Source

h323ac / ep.cxx

/***************************************************************************
    ep.cxx

    Copyright (c) 2002-2003  Vladimir Toncar

    The contents of this file are subject to the Mozilla Public License
    Version 1.1 (the "License"); you may not use this file except in
    compliance with the License. You may obtain a copy of the License at
    http://www.mozilla.org/MPL/

    Software distributed under the License is distributed on an "AS IS"
    basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
    See the License for the specific language governing rights and
    limitations under the License.

    The Original Code is oh323tut.

    The Initial Developer of the Original Code is Vladimir Toncar.
    All Rights Reserved.

    Contributor: Peter Nixon <codemonkey@peternixon.net>

 ***************************************************************************/

#include <ptlib.h>
#include "ep.h"
#include "nullchan.h"
#include "wavchan.h"


// ***********************************************************************

MyEndPoint::MyEndPoint(const ProgConf & conf, PSyncPoint & _exitFlag) : 
	progConf(conf), exitFlag(_exitFlag)
{}


// ***********************************************************************

MyEndPoint::~MyEndPoint() 
{}


// ***********************************************************************

void MyEndPoint::OnConnectionEstablished(H323Connection & /*connection*/, 
						const PString & token)
{
	PTRACE(1, "Connection established, token is " << token);
	PString a= token;
} 


// ***********************************************************************

void MyEndPoint::OnConnectionCleared(H323Connection &/*connection*/, 
						const PString &token)
{
	PTRACE(1, "Connection cleared, token is " << token);
	PString a = token;
	exitFlag.Signal();
} 


// ***********************************************************************

H323Connection::AnswerCallResponse MyEndPoint::OnAnswerCall( 
						H323Connection & /*connection*/,
						const PString & caller, 
						const H323SignalPDU &, 
						H323SignalPDU &)
{
	PTRACE(1, "Accepting connection from " << caller);
	PString a = caller;
	return H323Connection::AnswerCallNow;

} 


// ***********************************************************************

bool MyEndPoint::Init() 
{
	// Set user name
	if (!progConf.userAliases.IsEmpty()) 
	{
		SetLocalUserName(progConf.userAliases[0]); 
		for (PINDEX i=1; i<progConf.userAliases.GetSize(); i++)
			AddAliasName(progConf.userAliases[i]); 
	} 
	
	DisableFastStart(!progConf.fastStart);	
	DisableH245Tunneling(!progConf.h245Tunnell);
	//DisableH245inSetup(true);	
		
	// Codecs
	AddAllCapabilities(0, 0, "*");
	AddAllUserInputCapabilities(0, 1); 
					
	PTRACE(1, "Capabilities:\n" << setprecision(2) << capabilities); 

	// Gatekeeper registration
	BOOL gkResult = false; 
	switch (progConf.gkMode)
	{
	case ProgConf::NoGatekeeper: 
		gkResult = true;
		break;
	case ProgConf::RegisterWithGatekeeper:
		gkResult = UseGatekeeper(progConf.gkAddr, progConf.gkId);
		break;
	default:
		break;
	}

	if (!gkResult)
	{
		PError << "Failed to register with gatekeeper" << endl; 
		return false;
	} 


	// Make the H323 call to the specified number/user
              PTRACE(1, "Attempting to make the call");
              MakeCall(progConf.callingNumber, currentCallToken);

		
	return true;
} 


// ***********************************************************************

BOOL MyEndPoint::OpenAudioChannel(H323Connection &connection, 
						BOOL isEncoding,
						unsigned /*bufferSize*/, 
						H323AudioCodec &codec)
{
	//codec.SetSilenceDetectionMode(H323AudioCodec::NoSilenceDetection); 
	if (isEncoding) 
	{	// send audio direction
		WavChannel *ch = new WavChannel(progConf.fileName, connection);
		return codec.AttachChannel(ch, true); 
	}
	else
	{	// receive audio direction
		NullChannel *ch = new NullChannel();
		return codec.AttachChannel(ch, true);
	}
	
	return false;
} 


// ***********************************************************************

BOOL MyEndPoint::OnStartLogicalChannel(H323Connection & /*connection*/, 
						H323Channel & channel)
{
	PString dir;
	switch (channel.GetDirection())
	{
	case H323Channel::IsTransmitter :
		dir = "sending";
		break;
	case H323Channel::IsReceiver :
		dir = "receiving";
		break;
	default :
		break;
	}

	PTRACE(1, "Started logical channel " << dir << " " 
		<< channel.GetCapability() );
	return true;
} 


// ***********************************************************************