PageRenderTime 33ms CodeModel.GetById 24ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/jain-mgcp/stack/src/test/java/org/mobicents/protocols/mgcp/stack/test/endpointconfiguration/CA.java

http://mobicents.googlecode.com/
Java | 112 lines | 64 code | 27 blank | 21 comment | 1 complexity | 3bded982321faf826ab26ba99fb868ea MD5 | raw file
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2011, Red Hat, Inc. and individual contributors
  4 * by the @authors tag. See the copyright.txt in the distribution for a
  5 * full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22
 23package org.mobicents.protocols.mgcp.stack.test.endpointconfiguration;
 24
 25import jain.protocol.ip.mgcp.JainMgcpCommandEvent;
 26import jain.protocol.ip.mgcp.JainMgcpEvent;
 27import jain.protocol.ip.mgcp.JainMgcpResponseEvent;
 28import jain.protocol.ip.mgcp.message.Constants;
 29import jain.protocol.ip.mgcp.message.EndpointConfiguration;
 30import jain.protocol.ip.mgcp.message.parms.BearerInformation;
 31import jain.protocol.ip.mgcp.message.parms.CallIdentifier;
 32import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
 33
 34import org.apache.log4j.Logger;
 35import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
 36import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
 37import org.mobicents.protocols.mgcp.stack.test.createconnection.CreateConnectionTest;
 38
 39public class CA implements JainMgcpExtendedListener {
 40
 41	private static Logger logger = Logger.getLogger(CA.class);
 42
 43	private JainMgcpStackProviderImpl caProvider;
 44	private int mgStack = 0;
 45	private boolean responseReceived = false;
 46
 47	public CA(JainMgcpStackProviderImpl caProvider, JainMgcpStackProviderImpl mgwProvider) {
 48		this.caProvider = caProvider;
 49		mgStack = mgwProvider.getJainMgcpStack().getPort();
 50	}
 51
 52	public void sendEndpointConfiguration() {
 53
 54		try {
 55			caProvider.addJainMgcpListener(this);
 56
 57			CallIdentifier callID = caProvider.getUniqueCallIdentifier();
 58
 59			EndpointIdentifier endpointID = new EndpointIdentifier("media/trunk/Announcement/", "127.0.0.1:" + mgStack);
 60			EndpointConfiguration endpointConfiguration = new EndpointConfiguration(this, endpointID, BearerInformation.EncMethod_A_Law );
 61
 62			endpointConfiguration.setTransactionHandle(caProvider.getUniqueTransactionHandler());
 63
 64			caProvider.sendMgcpEvents(new JainMgcpEvent[] { endpointConfiguration });
 65
 66			logger.debug(" EndpointConfiguration command sent for TxId " + endpointConfiguration.getTransactionHandle()
 67					+ " and CallId " + callID);
 68		} catch (Exception e) {			
 69			e.printStackTrace();
 70			EndpointConfigurationTest.fail("Unexpected Exception");
 71		}
 72	}
 73
 74	public void checkState() {
 75		CreateConnectionTest.assertTrue("Expect to receive EPCF Response", responseReceived);
 76
 77	}
 78
 79	public void transactionEnded(int handle) {
 80		logger.info("transactionEnded " + handle);
 81
 82	}
 83
 84	public void transactionRxTimedOut(JainMgcpCommandEvent command) {
 85		logger.info("transactionRxTimedOut " + command);
 86
 87	}
 88
 89	public void transactionTxTimedOut(JainMgcpCommandEvent command) {
 90		logger.info("transactionTxTimedOut " + command);
 91
 92	}
 93
 94	public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
 95		logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
 96	}
 97
 98	public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
 99		logger.debug("processMgcpResponseEvent = " + jainmgcpresponseevent);
100		switch (jainmgcpresponseevent.getObjectIdentifier()) {
101		case Constants.RESP_ENDPOINT_CONFIGURATION:
102			responseReceived = true;			
103			break;
104		default:
105			logger.warn("This RESPONSE is unexpected " + jainmgcpresponseevent);
106			break;
107
108		}
109
110	}
111
112}