exchange.cpp
资源名称:h323.zip [点击查看]
上传用户:hnnddl
上传日期:2007-01-06
资源大小:3580k
文件大小:23k
源码类别:
IP电话/视频会议
开发平台:
WINDOWS
- /*
- * $Revision: 1.19 $
- * $Date: 1999/03/15 22:49:36 $
- */
- ////////////////////////////////////////////////////////////////
- // Copyright (c) 1996-98 Lucent Technologies //
- // All Rights Reserved //
- // //
- // THIS IS UNPUBLISHED //
- // PROPRIETARY SOURCE //
- // CODE OF Lucent Technologies //
- // AND elemedia //
- // //
- ////////////////////////////////////////////////////////////////
- //
- ////////////////////////////////////////////////////////////////
- // Example programs are provided soley to demonstrate one //
- // possible use of the stack libraries and are included for //
- // instructional purposes only. You are free to use, modify //
- // and/or redistribute any portion of code in the example //
- // programs. However, such examples are not intended to //
- // represent production quality code. //
- // //
- // THE COPYRIGHT HOLDERS PROVIDE THESE EXAMPLE PROGRAMS //
- // "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED //
- // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED //
- // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A //
- // PARTICULAR PURPOSE. //
- ////////////////////////////////////////////////////////////////
- #if (!defined(WIN32))
- #if defined(VXWORKS)
- #else
- #if (defined(__hpux))
- #include <pthread.h>
- #else
- #include <thread.h>
- #endif
- #endif
- #endif
- #include "exchange.h"
- #include "call.h"
- #include "msg.h"
- #include "mq.h"
- #include <assert.h>
- #if defined(USE_RAS)
- extern char *ras_msg_id_str[];
- char *ras_msg_id2str[] =
- {
- "INVALID",
- "GRQ",
- "GCF",
- "GRJ",
- "RRQ",
- "RCF",
- "RRJ",
- "URQ",
- "UCF",
- "URJ",
- "ARQ",
- "ACF",
- "ARJ",
- "BRQ",
- "BCF",
- "BRJ",
- "DRQ",
- "DCF",
- "DRJ",
- "LRQ",
- "LCF",
- "LRJ",
- "IRQ",
- "IRR",
- "NSM",
- "XRS"
- };
- int
- find_msg_id(char* msg_str)
- {
- for(int i=MSG_INVALID;i<=MSG_XRS;++i)
- {
- if (!stricmp(msg_str,ras_msg_id2str[i]))
- {
- return i;
- }
- }
- return -1;
- }
- Exchange::Exchange(H225CSEndpointType& endpoint_type,
- H225CSVendorID& vendor_id, int ras_endpoint,
- ProtReturnCode& result) :
- ConnectionManager(result),
- H225RASProtocol(endpoint_type, vendor_id, ras_endpoint, result),
- MessageQueue("Exchange",512,0)
- #else
- Exchange::Exchange(ProtReturnCode &result) : ConnectionManager(result),
- MessageQueue("Exchange",512,0)
- #endif
- {
- for (int i = 0; i < NUM_LINES; i++)
- {
- calls[i] = NULL;
- #if defined(USE_RAS)
- ras_sess[i].last_seqno = 0;
- ras_sess[i].ARQsent = FALSE;
- ras_sess[i].ACFrecd = FALSE;
- #endif
- }
- num_active_calls = 0;
- terminal_type = TT_TERMINAL_NO_MC;
- // initialize the endpoint_type.
- H225CSVendorID vid;
- char *desc = "Test audio distribution application";
- vid.SetH221NonStd(0xde, 0, 0xad);
- vid.SetProductID((unsigned char *)desc, strlen(desc) + 1);
- vid.SetVersionID((unsigned char *)desc, strlen(desc) + 1);
- endpoint_type.SetVendor(vid);
- endpoint_type.SetTerminal(NULL);
- ProtReturnCode ret;
- confid_prefix = get_local_ip();
- // by default use version 1 procedures.
- use_faststart = 0;
- use_overlapsend = 0;
- use_tunneling = 0;
- use_alerting = 0;
- use_callproc = 0;
- #ifdef USE_RAS
- isGKRegistered = FALSE;
- gkdiscovered = FALSE;
- local_ip = get_local_ip();
- confid_prefix = local_ip;
- ((sockaddr_in*)&local_ras)->sin_family = AF_INET;
- ((sockaddr_in*)&local_ras)->sin_port = HTONS(config->localrasport);
- #ifdef VXWORKS
- ((sockaddr_in*)&local_ras)->sin_addr.s_addr = htonl(INADDR_ANY);
- #else
- ((sockaddr_in*)&local_ras)->sin_addr.s_addr = local_ip;
- #endif
- ret = SetLocalAddr((sockaddr *) &local_ras);
- if (!PROT_IS_SUCCESS(ret)) {
- LOG("SetLocalAddr error 0x%xn", ret);
- return;
- }
- // vxworks doesn't like to bind on a named socket, so we bind to
- // INADDR_ANY but we need to communicate the real IP in out RAS messages
- #ifdef VXWORKS
- ((sockaddr_in*)&local_ras)->sin_addr.s_addr = local_ip;
- #endif
- ((sockaddr_in*)&local_sig)->sin_family = AF_INET;
- ((sockaddr_in*)&local_sig)->sin_port = HTONS(config->q931port);
- ((sockaddr_in*)&local_sig)->sin_addr.s_addr = local_ip;
- SetLastSeqno(1);
- #endif
- sockaddr_in addr;
- addr.sin_family = AF_INET;
- addr.sin_port = HTONS(config->q931port);
- addr.sin_addr.s_addr = 0;
- LOG("Calling ConnectionManager::Listenn");
- ret = Listen(ID_H225,(sockaddr*)&addr,LT_MANY);
- if (!PROT_IS_SUCCESS(ret))
- {
- LOG("ConnectionManager::Listen failed, 0x%xn",ret);
- return;
- }
- LOG("Listen succeededn");
- }
- Exchange::~Exchange()
- {
- LOG("Exchange::~Exchangen");
- }
- #ifdef USE_RAS
- void
- Exchange::DiscoverGK()
- {
- ProtReturnCode ret = SendGRQ(seqno++,NULL);
- if (!PROT_IS_SUCCESS(ret))
- {
- LOG("H225RASProtocol::SendGRQ failed, 0x%xn",ret);
- return;
- }
- LOG("Discovery request sentn");
- }
- void
- Exchange::RegisterWithGK()
- {
- struct sockaddr_in gk_address;
- gk_address.sin_family = AF_INET;
- gk_address.sin_port = HTONS(1719);
- gk_address.sin_addr.s_addr= inet_addr(config->gkaddrstr);
- ChooseGK((sockaddr*) &(gk_address));
- ProtReturnCode ret = SendRRQ(seqno++,NULL);
- if (!PROT_IS_SUCCESS(ret))
- {
- LOG("H225RASProtocol::SendRRQ failed, 0x%xn",ret);
- return;
- }
- LOG("Registration request sentn");
- }
- void
- Exchange::UnRegisterWithGK()
- {
- if(!IsGKRegistered())
- return;
- ProtReturnCode ret = SendURQ(seqno++,NULL);
- if (!PROT_IS_SUCCESS(ret))
- {
- LOG("H225RASProtocol::SendURQ failed, 0x%xn",ret);
- return;
- }
- LOG("UnRegistration request sentn");
- }
- #endif
- void
- Exchange::SendToExchange(int message, unsigned int wparam,
- unsigned int lparam)
- {
- USER_MESSAGE msg;
- msg.message = message;
- msg.wParam = wparam;
- msg.lParam = lparam;
- QueueMessage(&msg);
- }
- int
- Exchange::create_call(int outgoing)
- {
- ProtReturnCode result = 0;
- int i;
- for(i=0;i<NUM_LINES;++i)
- {
- if (calls[i] == NULL)
- break;
- }
- if (i == NUM_LINES)
- {
- assert(num_active_calls == NUM_LINES);
- return(-1);
- }
- char display[20];
- sprintf(display, "%s%d", config->h323IDsrc, i);
- calls[i] = new H323Call(this,ID_H225 + i, ID_H245 + i,
- endpoint_type, terminal_type, display, outgoing, result);
- if (!PROT_IS_SUCCESS(result))
- {
- return(result);
- }
- if (calls[i] == NULL)
- {
- LOG("Memory allocation for call failedn");
- return(-1);
- }
- #if defined(USE_RAS)
- ras_sess[i].ARQsent = ras_sess[i].ACFrecd = FALSE;
- if (outgoing)
- ras_sess[i].direction = (boolean)DIR_OUTGOING;
- else
- ras_sess[i].direction = (boolean)DIR_INCOMING;
- #endif
- calls[i]->SetApplicationPrivate((unsigned long)i);
- calls[i]->Start();
- ++num_active_calls;
- return(i);
- }
- // Note: connections are closed by the destructor of ConnectionEntity
- void
- Exchange::destroy_call(int index)
- {
- assert(calls[index] != NULL);
- H245Protocol* h245 = calls[index];
- H225CSProtocol* h225 = calls[index];
- if (h225)
- {
- LOG("Closing H.225 connectionn");
- CloseConnection(h225);
- LOG("Done closing H.225 connectionn");
- }
- if (h245)
- {
- LOG("Closing H.245 connectionn");
- CloseConnection(h245);
- LOG("Done closing H.245 connectionn");
- }
- calls[index]->Stop();
- #ifdef USE_RAS
- if (IsGKRegistered() &&
- ras_sess[index].ACFrecd )
- {
- ras_sess[index].last_seqno = seqno++;
- SendDRQ(ras_sess[index].last_seqno, NULL, index);
- }
- #endif
- delete calls[index];
- calls[index] = NULL;
- --num_active_calls;
- }
- void
- Exchange::ShutDown()
- {
- StopListening(ID_H225);
- SendToExchange(PROT_UI_MSG,UI_CMD_EXIT,0);
- while(num_active_calls > 0)
- {
- #if defined(WIN32)
- Sleep(0);
- #elif defined(VXWORKS)
- taskDelay(1);
- #else
- #if (defined(__hpux))
- pthread_yield();
- #else
- thr_yield();
- #endif
- #endif
- }
- }
- void
- Exchange::NotifyMessage(USER_MESSAGE& msg)
- {
- void *data = (void*)msg.lParam;
- if (msg.message == PROT_EXCH_MSG)
- {
- if (msg.wParam == XC_CALL_DROPPED)
- {
- H323Call *call =(H323Call*)data;
- destroy_call((int)call->GetApplicationPrivate());
- data = NULL;
- }
- else if (msg.wParam == CB_NEW_CONNECTION)
- {
- XchgNewConnection *info = (XchgNewConnection *)data;
- if (info->identifier == ID_H225)
- {
- int index = create_call(0); // incoming call
- if (index == -1)
- {
- RejectConnection(info->conn_ref);
- }
- else
- {
- ProtReturnCode ret;
- ret = AcceptConnection(info->conn_ref,
- (H225CSProtocol*)calls[index]);
- if (!PROT_IS_SUCCESS(ret))
- {
- LOG("AcceptConnection failed on H.225 portn");
- destroy_call(index);
- }
- }
- }
- else
- {
- int index = info->identifier;
- assert(index >= ID_H245);
- index -= ID_H245;
- assert(index < NUM_LINES);
- assert(index >= 0);
- assert(((H245Protocol*)calls[index])->GetIdentifier()
- == info->identifier);
- msg.message = PROT_CALL_MSG;
- if (calls[index] == NULL)
- {
- abort();
- }
- calls[index]->QueueMessage(&msg);
- // We don't have to freeup data.
- data = NULL;
- }
- }
- else if (msg.wParam == CB_LISTEN_ERROR)
- {
- XchgListenError *info = (XchgListenError *)data;
- LOG("ERROR: error occurred while accepting on id %dn",
- info->identifier);
- }
- else
- {
- LOG("ERROR: Unknown PROT_EXCH_MSGn");
- }
- }
- else if (msg.message == PROT_UI_MSG) // this is a command
- {
- LOG("Message from UIn");
- switch(msg.wParam)
- {
- case UI_CMD_PLACE_CALL:
- {
- LOG("UI_CMD_PLACE_CALLn");
- int index;
- UICmdPlaceCall *info = (UICmdPlaceCall *)data;
- // check if any lines are free...
- if((index=create_call(1)) == -1) // outgoing call
- {
- LOG("All lines are busy, try latern");
- }
- else
- {
- ProtReturnCode ret;
- if (info->dest_addr_length > 0)
- {
- calls[index]->SetPhoneNumber(info->dest_addr);
- }
- if (info->transfer_flag == TRUE) // is this a call transfer?
- {
- calls[index]->SetInvokeID(info->invokeID);
- calls[index]->SetTransferFlag(TRUE);
- if (info->callID)
- calls[index]->SetTransferCallID(info->callID);
- calls[index]->SetParentIndex(info->parent_index);
- }
- #ifdef USE_RAS
- if (IsGKRegistered() != TRUE)
- {
- // Initiate a TCP connection to the remote ends
- // Q.931 engine...
- ret = Connect((struct sockaddr*)&info->remote_addr,
- (H225CSProtocol*)calls[index]);
- if (!PROT_IS_PENDING(ret))
- {
- // Kinda kludgy... but not too bad..
- NotifyConnectionStatus(
- (H225CSProtocol*)calls[index],ret);
- }
- }
- else // we are registered with a gatekeeper; send ARQ
- {
- SendARQdata *arq_data = new SendARQdata;
- // create a src e164 alias in the form YYYXXXX
- // where YYY is the prefix and YYYY is the index of the call
- // for a gateway app, the app should pass the caller-id
- // in the UICmdPlaceCall message
- char tmp_phone[256];
- sprintf(tmp_phone, "%s%0004d",
- config->e164src, index);
- calls[index]->SetSrcPhoneNumber(tmp_phone);
- strcpy(arq_data->e164src, tmp_phone);
- strcpy(arq_data->e164dst, info->dest_addr);
- arq_data->index = index;
- LOG("SendARQ for OUTGOING calln");
- // info->dest_addr is the outgoing number
- ras_sess[index].last_seqno = seqno++;
- SendARQ(ras_sess[index].last_seqno,NULL,
- arq_data );
- ras_sess[index].ARQsent = TRUE;
- delete arq_data;
- }
- #else
- ret = Connect((struct sockaddr*)&info->remote_addr,
- (H225CSProtocol*)calls[index]);
- if (!PROT_IS_PENDING(ret))
- {
- // Kinda kludgy... but not too bad..
- NotifyConnectionStatus(
- (H225CSProtocol*)calls[index],ret);
- }
- #endif
- }
- }
- break;
- case UI_CMD_HANGUP:
- {
- LOG("UI_CMD_HANGUPn");
- UICmdHangup *info = (UICmdHangup *)data;
- msg.lParam = 0;
- LOG("Hanging up line %dn", info->line_no);
- if (calls[info->line_no])
- {
- calls[info->line_no]->QueueMessage(&msg);
- }
- }
- break;
- case UI_CMD_FACILITY:
- {
- LOG("UI_CMD_FACILITYn");
- UICmdFacility *info = (UICmdFacility *)data;
- msg.lParam = (unsigned int)info;
- LOG("Sending Facility msg on line %dn", info->line_no);
- if (calls[info->line_no])
- {
- calls[info->line_no]->QueueMessage(&msg);
- }
- // We don't have to freeup data.
- data = NULL;
- }
- break;
- case UI_CMD_EXIT:
- {
- LOG("UI_CMD_EXITn");
- msg.lParam = 0;
- for (int i = 0; i < NUM_LINES; ++i)
- {
- if (calls[i] != NULL)
- {
- calls[i]->QueueMessage(&msg);
- }
- }
- }
- break;
- case UI_CMD_CTRL:
- {
- // Control type command from the user interface.
- LOG("UI_CMD_CTRLn");
- UICmdCtrl *info = (UICmdCtrl *)data;
- for (int i = 0; i < info->num_cmds; i++)
- {
- switch (info->command[i])
- {
- case UI_CTRL_CMD_ENABLE_FASTSTART:
- use_faststart = 1;
- break;
- case UI_CTRL_CMD_DISABLE_FASTSTART:
- use_faststart = 0;
- break;
- case UI_CTRL_CMD_ENABLE_TUNNELING:
- use_tunneling = 1;
- break;
- case UI_CTRL_CMD_DISABLE_TUNNELING:
- use_tunneling = 0;
- break;
- case UI_CTRL_CMD_ENABLE_OVERLAP_SEND:
- use_overlapsend = 1;
- break;
- case UI_CTRL_CMD_DISABLE_OVERLAP_SEND:
- use_overlapsend = 0;
- break;
- case UI_CTRL_CMD_ENABLE_ALERTING:
- use_alerting = 1;
- break;
- case UI_CTRL_CMD_DISABLE_ALERTING:
- use_alerting = 0;
- break;
- case UI_CTRL_CMD_ENABLE_CALLPROC:
- use_callproc = 1;
- break;
- case UI_CTRL_CMD_DISABLE_CALLPROC:
- use_callproc = 0;
- break;
- }
- }
- }
- break;
- }
- }
- // code for handling with messages from H323Call
- else if (msg.message == PROT_CALL_MSG)
- {
- LOG("Message from H323 CALLn");
- switch(msg.wParam)
- {
- #if defined(USE_RAS)
- // the following ARQ request message is for an incoming call
- case CB_SEND_ARQ:
- {
- SendARQdata *info = (SendARQdata *)data;
- assert(calls[info->index] != NULL);
- ras_sess[info->index].last_seqno = seqno++;
- SendARQ(ras_sess[info->index].last_seqno, NULL,
- (SendARQdata*)info );
- ras_sess[info->index].ARQsent = TRUE;
- }
- break;
- #endif
- default:
- break;
- }
- }
- #if defined(USE_RAS)
- else if (msg.message == PROT_RAS_MSG)
- {
- XchgRASMessage *info = (XchgRASMessage *)data;
- int msg_type = info->ras_message->GetType();
- H225RASMessage *ras_message = info->ras_message;
- struct sockaddr *origin = info->origin;
- LOG("Exchange::NotifyRASMessagen");
- LOG("Got message(%d,%s), seqno(%d)n",ras_message->GetType(),
- ((ras_message->GetType() >= MSG_INVALID &&
- ras_message->GetType() <= MSG_XRS) ?
- ras_msg_id2str[ras_message->GetType()] : "UNKNOWN" ),
- ras_message->GetSequenceNumber());
- int seqno_rcvd = ras_message->GetSequenceNumber();
- switch(ras_message->GetType())
- {
- case MSG_GRQ:
- {
- struct sockaddr_in host_addr;
- // just snoop and log GRQs received at the multicast address
- ((H225RASMsgGCF*)ras_message)->GetRASAddr((sockaddr*)&host_addr);
- char *host_addr_str = inet_ntoa(host_addr.sin_addr);
- LOG("host %s is looking for a gatekeepern", host_addr_str);
- }
- break;
- case MSG_GCF:
- {
- struct sockaddr_in gk_address;
- ((H225RASMsgGCF*)ras_message)->GetRASAddr((sockaddr*)&gk_address);
- char *gk_addr_str = inet_ntoa(gk_address.sin_addr);
- LOG("%s is offering to become our gatekeepern", gk_addr_str);
- // if we have already received a reply from a gatekeeper, ignore this one
- // we can selectively filter the replies to find a preferred gatekeeper
- if (!gkdiscovered) {
- gkdiscovered = TRUE;
- strcpy(config->gkaddrstr, gk_addr_str);
- RegisterWithGK();
- }
- }
- break;
- case MSG_GRJ:
- case MSG_RRQ:
- break;
- case MSG_RCF:
- {
- unsigned short *id;
- ((H225RASMsgRCF*)ras_message)->GetEndpointID(id, ep_id_len);
- memcpy(&ep_id[0], id, ep_id_len * 2);
- LOG("Registration succeeded!n");
- SetIsGKRegistered(TRUE);
- LOG("Endpoint ID: 0x");
- for(int i=0; i<ep_id_len; i++)
- LOG("%x", ep_id[i]);
- LOG("n");
- }
- break;
- case MSG_RRJ:
- isGKRegistered = FALSE;
- break;
- case MSG_URQ:
- break;
- case MSG_UCF:
- isGKRegistered = FALSE;
- break;
- case MSG_URJ:
- break;
- case MSG_ARQ:
- break;
- case MSG_ACF:
- {
- ProtReturnCode ret;
- struct sockaddr_in addr;
- ((H225RASMsgACF*)ras_message)->GetDstCallSigAddr((struct sockaddr*)&addr);
- char *rem_addr_str = inet_ntoa(addr.sin_addr);
- LOG("gatekeeper offers dest signaling addr <%s>:<%u>n",
- rem_addr_str, ntohs(addr.sin_port));
- int index = -1;
- int is_call_valid = 0;
- for (int i = 0;i < NUM_LINES; i++)
- {
- if (seqno_rcvd == ras_sess[i].last_seqno) {
- index = i;
- if ((void *)calls[index])
- {
- is_call_valid = 1;
- break;
- }
- }
- }
- if (is_call_valid) {
- ras_sess[index].ACFrecd = TRUE;
- if (ras_sess[index].direction == DIR_OUTGOING) {
- LOG("valid OUTgoing call index = %dn",index);
- // Initiate a TCP connection to the remote ends
- // Q.931 engine...
- ret = Connect((struct sockaddr*)&addr,
- (H225CSProtocol*)calls[index]);
- if (!PROT_IS_PENDING(ret))
- {
- // Kinda kludgy... but not too bad..
- NotifyConnectionStatus(
- (H225CSProtocol*)calls[index],ret);
- }
- }
- else if (ras_sess[index].direction == DIR_INCOMING)
- {
- LOG("valid INcoming call index = %dn",index);
- calls[index]->Q931SendAlerting();
- }
- else
- {
- assert(1);
- }
- }
- }
- break;
- case MSG_ARJ:
- {
- LOG("Received ARJn");
- int index = -1;
- int is_call_valid = 0;
- for (int i = 0;i < NUM_LINES; i++)
- {
- if (seqno_rcvd == ras_sess[i].last_seqno) {
- index = i;
- if ((void *)calls[index])
- {
- is_call_valid = 1;
- break;
- }
- }
- }
- if (is_call_valid) {
- ras_sess[index].ACFrecd = FALSE;
- // this should clean everything
- USER_MESSAGE msg;
- msg.message = PROT_UI_MSG;
- msg.wParam = UI_CMD_HANGUP;
- msg.lParam = NULL;
- calls[index]->QueueMessage(&msg);
- }
- }
- break;
- #if 1 // TODO: implement
- case MSG_BRQ:
- case MSG_BCF:
- case MSG_BRJ:
- // DRQ request might come from the GK if the call has to be teared down
- // the terminal should tear down the call
- case MSG_DRQ:
- case MSG_DCF:
- case MSG_DRJ:
- case MSG_LRQ:
- case MSG_LCF:
- case MSG_LRJ:
- case MSG_IRQ:
- case MSG_IRR:
- case MSG_NSM:
- case MSG_XRS:
- #endif
- break;
- default:
- break;
- }
- }
- #endif
- if (data)
- {
- delete (CBData*)data;
- }
- }
- void
- Exchange::NotifyListenError(int identifier,
- ProtReturnCode status)
- {
- XchgListenError *msg = new XchgListenError;
- msg->identifier = identifier;
- msg->status = status;
- SendToExchange((unsigned int)PROT_EXCH_MSG,
- (unsigned int)CB_LISTEN_ERROR,
- (unsigned int)msg);
- }
- void
- Exchange::NotifyNewConnection(int identifier,
- int conn_ref, sockaddr *new_addr)
- {
- XchgNewConnection *msg = new XchgNewConnection;
- msg->identifier = identifier;
- msg->conn_ref = conn_ref;
- msg->new_addr = *(struct sockaddr_in *)new_addr;
- SendToExchange((unsigned int)PROT_EXCH_MSG,
- (unsigned int)CB_NEW_CONNECTION,
- (unsigned int)msg);
- }
- void
- Exchange::NotifyConnectionStatus(ConnectionEntity *conn,
- ProtReturnCode connection_status)
- {
- USER_MESSAGE m;
- LOG("NotifyConnectionStatus status = 0x%xn",
- connection_status);
- int index = conn->GetIdentifier();
- if (index < ID_H245)
- {
- index -= ID_H225;
- assert(index >= 0 && index <= NUM_LINES);
- }
- else
- {
- index -= ID_H245;
- assert(index >= 0 && index <= NUM_LINES);
- }
- if (calls[index] == NULL)
- {
- abort();
- }
- XchgConnectionStatus *msg = new XchgConnectionStatus;
- msg->conn = conn;
- msg->status = connection_status;
- m.message = PROT_CALL_MSG;
- m.wParam = CB_CONNECTION_STATUS;
- m.lParam = (unsigned int)msg;
- calls[index]->QueueMessage(&m);
- }
- void
- Exchange::NotifyConnectionClosed(ConnectionEntity *conn,
- ProtReturnCode reason)
- {
- USER_MESSAGE m;
- int index = conn->GetIdentifier();
- if (index < ID_H245)
- {
- index -= ID_H225;
- }
- else
- {
- index -= ID_H245;
- }
- if (calls[index] == NULL)
- {
- abort();
- }
- XchgConnectionClosed *msg = new XchgConnectionClosed;
- msg->conn = conn;
- msg->reason = reason;
- m.message = PROT_CALL_MSG;
- m.wParam = CB_CONNECTION_CLOSED;
- m.lParam = (unsigned int)msg;
- calls[index]->QueueMessage(&m);
- }
- #if defined(__SVR4) && defined(__sun)
- extern "C"
- {
- int gethostname(char *,int);
- };
- #endif
- unsigned int
- Exchange::get_local_ip()
- {
- char hostname[256];
- unsigned int local_addr;
- gethostname(hostname,sizeof(hostname));
- local_addr = inet_addr(hostname);
- #if defined(VXWORKS)
- // if gethostname() works for your target, you don't need the
- // following line. We use if for our simulator
- sprintf(hostname,"vxworks%d",sysProcNumGet());
- local_addr = hostGetByName(hostname);
- LOG("local_addr=0x%xn", local_addr);
- return local_addr;
- #else
- struct hostent *hent_p;
- hent_p = gethostbyname((const char *)hostname);
- if(hent_p == NULL)
- {
- #if defined(WIN32)
- int ret = WSAGetLastError();
- LOG("gethostbyname failed on %s error %dn", hostname,ret);
- #else
- LOG("gethostbyname failed on %sn", hostname);
- #endif
- return 0;
- }
- int i = 0;
- while(hent_p->h_addr_list[i])
- {
- LOG("Interface %d, ip = 0x%xn",
- i,*(unsigned long *)(hent_p->h_addr_list[i]));
- ++i;
- }
- return *(unsigned int *)(hent_p->h_addr_list[0]);
- #endif
- }
- #if defined(USE_RAS)
- void
- Exchange::NotifyRASTimeout(H225RASMessage& ras_message,
- struct sockaddr *destination,
- H225RASTransmitterInfo& info)
- {
- LOG("Exchange::NotifyRASMessagen");
- LOG("message(%d,%s), seqno(%d) timed-outn",ras_message.GetType(),
- ((ras_message.GetType() >= MSG_INVALID &&
- ras_message.GetType() <= MSG_XRS) ?
- ras_msg_id2str[ras_message.GetType()] : "UNKNOWN" ),
- ras_message.GetSequenceNumber());
- }
- void
- Exchange::NotifyRASMessage(H225RASMessage& ras_message,
- struct sockaddr *origin, struct sockaddr *destination,
- struct H225RASTransmitterInfo& info)
- {
- XchgRASMessage *msg = new XchgRASMessage;
- int msg_type = ras_message.GetType();
- ProtReturnCode ret = H225RASMessage::Factory(msg->ras_message, msg_type, (H225RASProtocol *)this);
- if (!PROT_IS_SUCCESS(ret) || !msg->ras_message)
- {
- LOG("Failed to new ras messagen");
- return;
- }
- *(msg->ras_message) = ras_message;
- msg->origin = origin;
- SendToExchange((unsigned int)PROT_RAS_MSG,
- (unsigned int)CB_RAS_EVENT,
- (unsigned int)msg);
- }
- sockaddr*
- Exchange::GetLocalRASAddr()
- {
- return (sockaddr*)&local_ras;
- }
- void
- Exchange::SetIsGKRegistered(boolean flag)
- {
- isGKRegistered = flag;
- }
- boolean
- Exchange::IsGKRegistered()
- {
- return isGKRegistered;
- }
- sockaddr*
- Exchange::GetLocalSigAddr()
- {
- return (sockaddr*)&local_sig;
- }
- int
- Exchange::GetLastSeqno()
- {
- return seqno;
- }
- void Exchange::SetLastSeqno(unsigned int seq_no)
- {
- seqno = seq_no;
- }
- #endif