⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cxx

📁 performance analysis in H.323 environments. Open H.323 Call Generator是一个OpenH323 (www.openh323.org)子
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* H.323 Call Generator.
 (c) Benny Prijono <seventhson@theseventhson.freeserve.co.uk>
     Thomas Kessler <thomas.kessler@gmx.net>
 
 Changelog:
 25 Jan 2000 Update to incorporate openh323 v.01 alpha2 and fix gatekeeper
             related codes [bennylp]
 16 Oct 2000 Update to incorporate openh323 v1.1 release 
              (Win32 not tested!) [thomask]
 */
#include "precompile.h"
#include "main.h"

PMutex COH323LineDevice::m_Mutex;
int COH323LineDevice::m_NConnected;

PCREATE_PROCESS(MyMain);

///////////////////////////////////////////////////////////////////////////////
COH323EndPoint::COH323EndPoint()
{
    m_FreeIncomingLines.DisallowDeleteObjects();
    m_BusyIncomingLines.DisallowDeleteObjects();
    m_FreeOutgoingLines.DisallowDeleteObjects();
    m_BusyOutgoingLines.DisallowDeleteObjects();
}

COH323EndPoint::~COH323EndPoint()
{
    m_LineMutex.Wait();
}

BOOL COH323EndPoint::Initialise(const PArgList& args)
{
    // set dummy capability
    //SetCapability(0, 0, new COHG711ULaw64kCapability);
    SetCapability(0, 0, new H323_G711Capability(H323_G711Capability::muLaw, H323_G711Capability::At64k));
    SetCapability(0, 1, new H323_UserInputCapability);

    // init listener
    H323ListenerTCP * listener;
    if (args.GetOptionString('i').IsEmpty())
	listener = new H323ListenerTCP(*this);
    else {
	PIPSocket::Address interface_addr(args.GetOptionString('i'));
	listener = new H323ListenerTCP(*this, interface_addr);
    }
    if (!StartListener(listener)) {
	cout << "Couldn't start listener on port "
	     << listener->GetListenerPort() << endl;
	delete listener;
	return FALSE;
    }

    // set local username, is necessary
    if (args.HasOption('u')) {
	PStringArray aliases = args.GetOptionString('u').Lines();
	SetLocalUserName(aliases[0]);
	for (PINDEX i = 1; i < aliases.GetSize(); ++i)
	    AddAliasName(aliases[i]);
    }
    cout << "Local username: " << GetLocalUserName() << endl;

    // process gatekeeper registration options
    if (args.HasOption('g')) {
	PString gkName = args.GetOptionString('g');
	H323TransportUDP * rasChannel;
	if (args.GetOptionString('i').IsEmpty())
	    rasChannel  = new H323TransportUDP(*this);
	else {
	    PIPSocket::Address interfaceAddress(args.GetOptionString('i'));
	    rasChannel  = new H323TransportUDP(*this, interfaceAddress);
	}
	if (SetGatekeeper("ip$"+gkName, rasChannel))
	    cout << "Gatekeeper set: " << *gatekeeper << endl;
	else {
	    cout << "Error registering with gatekeeper at \"" 
 	   	 << gkName << '"' << endl;
	    return FALSE;
	}
    }
    else if (!args.HasOption('N')) {
	cout << "Searching for gatekeeper..." << flush;
	if (DiscoverGatekeeper(new H323TransportUDP(*this)))
	    cout << "\nGatekeeper found: " << *gatekeeper << endl;
	else {
	    cout << "\nNo gatekeeper found." << endl;
	    if (args.HasOption("require-gatekeeper")) 
	    return FALSE;
	}
    }

    return TRUE;
}

H323Connection* COH323EndPoint::CreateConnection ( unsigned callReference ) 
{ 
    return new COH323Connection( *this, callReference); 
}

COH323LineDevice *COH323EndPoint::CreateLineDevice(const char *name, 
						   ECallDirection dir)
{
    COH323LineDevice *line_dev = new COH323LineDevice(name, *this, dir);

    m_LineMutex.Wait();
    m_AllLines.Append(line_dev);
    if (dir==eCD_INCOMING)
	m_FreeIncomingLines.Append(line_dev);
    else 
	m_FreeOutgoingLines.Append(line_dev);
    m_LineMutex.Signal();

    return line_dev;
}

PString COH323EndPoint::MakeOutgoingCall(COH323LineDevice &line_dev, 
					 const PString& dest)
{
    PString token;
    H323Connection *c=MakeCall( dest, token);
    if (!c)
	return "";

    m_LineMutex.Wait();
    m_FreeOutgoingLines.Remove(&line_dev);
    m_BusyOutgoingLines.Append(&line_dev);
    m_LineMutex.Signal();
    
    COH323Connection &connection=(COH323Connection &)*c;
    connection.SetLineDevice(line_dev);

    return token;
}

BOOL COH323EndPoint::ListenForIncomingCalls()
{
    /*
    if (GetListeners().GetSize()==0) {
	H323ListenerTCP * listener = new H323ListenerTCP(*this);
	if (!StartListener(listener)) {
	    cout <<  "Could not open H.323 listener port on "
		 << listener->GetListenerPort() << endl;
	    return FALSE;
	}
    }
    */
    return TRUE;
}

BOOL COH323EndPoint::OnIncomingCall(COH323Connection &con, const PString &token)
{
    if (m_FreeIncomingLines.GetSize()==0) {
	cout << "No ready lines for incoming call" << endl;
	return FALSE;
    }

    m_LineMutex.Wait();
    COH323LineDevice &line_dev=m_FreeIncomingLines[0];
    m_FreeIncomingLines.RemoveAt(0);
    m_BusyIncomingLines.Append(&line_dev);
    m_LineMutex.Signal();

    con.SetLineDevice(line_dev);
    line_dev.OnIncomingConnection(token);

    return TRUE;
}


void COH323EndPoint::OnConnectionEstablished (H323Connection &c, 
					      const PString &token)
{
    COH323Connection &connection = (COH323Connection&)c;
    COH323LineDevice *line=connection.GetLineDevice();
    PAssert(line!=NULL, PLogicError);
    line->OnConnectionEstablished(token);
}

void COH323EndPoint::OnConnectionCleared (H323Connection &c, 
					  const PString & token )
{
    COH323Connection &connection = (COH323Connection&)c;
    COH323LineDevice *line_dev=connection.GetLineDevice();

    if (!line_dev) {
	cout << "Connection has no line device" << endl;
	return;
    }

    connection.OnConnectionCleared(token);

    m_LineMutex.Wait();
    if (line_dev->GetDirection()==eCD_INCOMING) {
	m_BusyIncomingLines.Remove(line_dev);
	m_FreeIncomingLines.Append(line_dev);
    } else {
	m_BusyOutgoingLines.Remove(line_dev);
	m_FreeOutgoingLines.Append(line_dev);
    }
    m_LineMutex.Signal();
}


BOOL COH323EndPoint::RegisterGk(const PString& gk_host)
{
    /*
    if (!gk_host.IsEmpty()) {
	if (SetGatekeeper("ip:"+gk_host, new H323TransportUDP(*this))) {
	    cout << "Gatekeeper set: " << *gatekeeper << endl;
	    return TRUE;
	} else {
	    cout << "Error registering with gatekeeper at \"" 
		 << gk_host << '"' << endl;
	    return FALSE;
	}
    }
    else {
	cout << "Searching for gatekeeper..." << flush;
	if (DiscoverGatekeeper(new H323TransportUDP(*this))) {
	    cout << "\nGatekeeper found: " << *gatekeeper << endl;
	    return TRUE;
	} else {
	    cout << "\nNo gatekeeper found." << endl;
	    return FALSE;
	}
    }
    PAssertAlways(PLogicError);
    return FALSE;
    */
    return TRUE;
}

///////////////////////////////////////////////////////////////////////////////
COH323Connection::COH323Connection(H323EndPoint &endpoint, unsigned callReference)
: H323Connection(endpoint,callReference ), m_LineDevice(NULL)
{
}

COH323Connection::~COH323Connection()
{
}

BOOL COH323Connection::OnIncomingCall (const H323SignalPDU &, H323SignalPDU &)
{
    COH323EndPoint &endpt=(COH323EndPoint&)GetEndPoint();
    return endpt.OnIncomingCall(*this, callToken);
}

void COH323Connection::OnConnectionCleared(const PString &token)
{
    PAssert(m_LineDevice!=NULL,PLogicError);
    m_LineDevice->OnConnectionCleared(token);
    m_LineDevice=NULL;
}

H323Connection::AnswerCallResponse 
COH323Connection::OnAnswerCall(const PString &, 
	                       const H323SignalPDU &, 
             		       H323SignalPDU &)
{
    PAssert(m_LineDevice!=NULL, PLogicError);
    m_LineDevice->OnAnswerCall();

    // simply answer the call
    return AnswerCallNow;
}

/*
void COH323Connection::OnUserInputString( const PString & value )
{
    PAssert(m_LineDevice!=NULL, PLogicError);
    m_LineDevice->OnUserInputString(value);
}
*/

void COH323Connection::Hangup()
{
    // this not the correct function to hangup
    PAssert( FALSE, PLogicError );
    if (!GetEndPoint().ClearCall(callToken))
	cout << "Can't hangup connecton" << endl;
}


///////////////////////////////////////////////////////////////////////////////
COH323Codec::COH323Codec(Direction dir, PINDEX)
: H323Codec(dir)
{
}

COH323Codec::~COH323Codec()
{
}

BOOL COH323Codec::Read(BYTE *, unsigned &size, RTP_DataFrame &)
{
    size = 0;
    //m_WaitFlag.Wait();
    return TRUE;
}

BOOL COH323Codec::Write(const BYTE*, unsigned, const RTP_DataFrame&, unsigned&)
{
    //m_WaitFlag.Wait();
    return TRUE;
}

BOOL COH323Codec::Open(H323Connection &)
{
    return TRUE;
}

void COH323Codec::Close()
{
    //m_WaitFlag.Signal();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -