📄 agent.cxx
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const agent_cxx_Version = "$Id: agent.cxx,v 1.15 2001/01/17 01:52:24 liuhong Exp $";#include <sys/types.h>#include <unistd.h>#include <stdio.h>#include "MgcGateway.hxx"#include "endpoint.h"#define ENDPOINT_MAX 2#define CALL_DATA_MAX 2Endpoint eps [ENDPOINT_MAX];CallData call [CALL_DATA_MAX];intnewRequestIdentifier (void){ static unsigned long currentNumber = 0; return ++currentNumber;} /* newRequestIdentifier */intnewCallIdentifier (void){ static unsigned long currentNumber = 0; return ++currentNumber;} /* newCallIdentifier */voidcallDataInit (CallData* cd){ cd->callIdentifier[0] = 0; for (int j = 0; j < ENDPOINTS_PER_CALL; j++) { cd->endpoint[j].id = -1; cd->endpoint[j].connectionId[0] = 0; } cd->dtmfDigits[0] = 0; cd->playDtmfDigit = 0;} /* callDataInit */CallData*newCallData (Endpoint* ep){ for (int i = 0; i < CALL_DATA_MAX; i++) { if (call[i].callIdentifier[0] == 0) { call[i].endpoint[0].id = ep->id; return &call[i]; } } return NULL;} /* newCallData */voidnotifyEndpoint (Endpoint* ep, int event){ char buf [32]; // cerr << "notifying endpoint\n"; sprintf (buf, "%d", event); if (ep->sfd < 0) { cerr << "sfd socket not open!\n"; } sendto (ep->sfd, buf, sizeof (buf), 0, (struct sockaddr*)&(ep->socketAddress), sizeof (ep->socketAddress));} /* notifyEndpoint */voidendpointInit (Endpoint* ep, const int id, MgcGateway* gw){ // int errNum = 0; ep->id = id; ep->state = Init; ep->gw = gw; ep->call = NULL; ep->requestIdentifier[0] = 0; ep->tid.spawn(epStart, (void*)ep);} /* endpointInit */void*process(void* gateway){ MgcGateway* gw; // cout << "entering process loop\n"; gw = static_cast < MgcGateway* > (gateway); gw->threadProcess(); // cout << "exiting process loop\n"; return NULL;}intmain (int argc, char* argv[]){ char* hostname0 = "localhost"; char* hostname1 = "localhost"; if (argc >= 3) { hostname0 = argv[1]; hostname1 = argv[2]; } else { cerr << "Usage: agent gatewayHostName1 gatewayHostName2" << endl; cerr << "Defaulting both gateways to localhost" << endl; cerr << "host 0: " << hostname0 << endl; cerr << "host 1: " << hostname1 << endl; } MgcGateway gw0 (hostname0, 5050, 5010); MgcGateway gw1 (hostname1, 5051, 5011); // spawn thread to do the waiting VThread tid0; VThread tid1; // int errNum; tid0.spawn(process, &gw0); tid1.spawn(process, &gw1); endpointInit (&eps[0], 0, &gw0); endpointInit (&eps[1], 1, &gw1); callDataInit (&call[0]); callDataInit (&call[1]); // cerr << "ho ho ho\n"; time_t oldtime = time(NULL); while ((time(NULL) - oldtime ) < 2) { sleep (2); } // cerr << "hey hey hey\n"; notifyEndpoint (&eps[0], Restart); sleep (1); notifyEndpoint (&eps[1], Restart); eps[0].tid.join(); eps[1].tid.join(); exit (1);} /* main */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -