CAF: Leg Creation Samples

From TBwiki
(Difference between revisions)
Jump to: navigation, search
(Bridging an Incoming Call (using CTBCAFBridge ))
(Bridging an Incoming Call (using CTBCAFBridge ))
Line 86: Line 86:
 
   CAFCODE( CTBCAFMediaGateway::OnCallLegPresent )
 
   CAFCODE( CTBCAFMediaGateway::OnCallLegPresent )
 
   {
 
   {
                 pCallLegAttribute          = in_CallLegAttribute.GetCallLegAttribute();
+
                 PTRCTBCMC_CALL_LEG_ATTRIBUTE ptrIncomingCallLegAttribute;
 +
                PTRCTBCMC_CALL_LEG_ATTRIBUTE ptrOutgoingCallLegAttribute;
 +
                PITBCAFCallFlow       pCallFlow;
 +
 
 +
                ptrOutgoingCallLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE();
 
                 ptrIncomingCallLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE(*pCallLegAttribute);
 
                 ptrIncomingCallLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE(*pCallLegAttribute);
                 ptrOutgoingCallLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE();
+
 
 +
                 ptrOutgoingLegAttribute->GetCalledNumber()        = ptrIncomingCallLegAttribute->GetCallingNumber();
 +
                ptrOutgoingLegAttribute->GetCallingNumber()        = ptrIncomingCallLegAttribute->GetCalledNumber();
 +
                ptrOutgoingLegAttribute->GetNetworkAccessPoint()  = ptrIncomingCallLegAttribute->GetNetworkAccessPoint();
 +
 
 +
                pCallFlow = tbnew CTBCAFBridge( mun32AccountId, this );
 +
                TBCAF_EXIT_ON_NULL( pCallFlow, TBX_RESULT_FAIL, "Failed to allocate call." );
 +
 
 +
                Result = pCallFlow->AddIncoming( mun32LegId, ptrIncomingCallLegAttribute );
 +
                TBCAF_EXIT_ON_ERROR(Result, "AddIncoming Failed." );
 +
 
 +
  Result = pCallFlow->AddOutgoing( ptrOutgoingCallLegAttribute );
 +
  TBCAF_EXIT_ON_ERROR(Result, "AddOutgoing Failed." );
 
      
 
      
                PCTBCMCLeg pIncomingCallLeg = tbnew CTBCMCLeg( ++mun32LegId, ptrIncomingCallLegAttribute, this, 0, &mLegMutex );
+
  // Start the call
                pIncomingCallLeg->CreateCall();
+
   Result = pCallFlow->InitCall( &pCallFlow );
   
+
                ptrOutgoingCallLegAttribute->GetCalledNumber()        = ptrIncomingCallLegAttribute->GetCallingNumber();
+
                ptrOutgoingCallLegAttribute->GetCallingNumber()        = ptrIncomingCallLegAttribute->GetCalledNumber();
+
                ptrOutgoingCallLegAttribute->GetNetworkAccessPoint()   = ptrIncomingCallLegAttribute->GetNetworkAccessPoint();
+
   
+
                PCTBCMCLeg pOutgoingCallLeg = tbnew CTBCMCLeg( ++mun32LegId, ptrOutgoingCallLegAttribute, this, 0, &mLegMutex );
+
                pOutgoingCallLeg->CreateCall();
+
 
      
 
      
 
         TBX_EXIT_SUCCESS( TBX_RESULT_OK );
 
         TBX_EXIT_SUCCESS( TBX_RESULT_OK );
Line 125: Line 134:
 
   TBCAF_MUTEX_GET_SCOPE_END( &mMutex )
 
   TBCAF_MUTEX_GET_SCOPE_END( &mMutex )
 
   }
 
   }
  PTRCTBCMC_CALL_LEG_ATTRIBUTE ptrIncomingCallLegAttribute;
 
  PTRCTBCMC_CALL_LEG_ATTRIBUTE ptrOutgoingCallLegAttribute;
 
  PITBCAFCallFlow       pCallFlow;
 
 
 
  ptrOutgoingCallLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE();
 
  ptrIncomingCallLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE(*pCallLegAttribute);
 
 
 
  ptrOutgoingLegAttribute->GetCalledNumber()        = ptrIncomingCallLegAttribute->GetCallingNumber();
 
  ptrOutgoingLegAttribute->GetCallingNumber()        = ptrIncomingCallLegAttribute->GetCalledNumber();
 
  ptrOutgoingLegAttribute->GetNetworkAccessPoint()  = ptrIncomingCallLegAttribute->GetNetworkAccessPoint();
 
 
 
  pCallFlow = tbnew CTBCAFBridge( mun32AccountId, this );
 
  TBCAF_EXIT_ON_NULL( pCallFlow, TBX_RESULT_FAIL, "Failed to allocate call." );
 
 
 
  Result = pCallFlow->AddIncoming( mun32LegId, ptrIncomingCallLegAttribute );
 
  TBCAF_EXIT_ON_ERROR(Result, "AddIncoming Failed." );
 
 
 
  Result = pCallFlow->AddOutgoing( ptrOutgoingCallLegAttribute );
 
  TBCAF_EXIT_ON_ERROR(Result, "AddOutgoing Failed." );
 
   
 
  // Start the call
 
  Result = pCallFlow->InitCall( &pCallFlow );
 
  
 
== Creating a Media-only Leg ==
 
== Creating a Media-only Leg ==

Revision as of 14:25, 22 October 2009

Contents

Creating a Standalone Outgoing Call

   PTRCTBCMC_CALL_LEG_ATTRIBUTE ptrOutgoingLegAttribute;
   ptrOutgoingLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE();
 
   ptrOutgoingLegAttribute->GetCalledNumber()         = "123-4567";
   ptrOutgoingLegAttribute->GetCallingNumber()        = "987-6543";
   ptrOutgoingLegAttribute->GetNetworkAccessPoint()   = "NAP_SS7_MONTREAL";
 
   PCTBCMCLeg pCallLeg = tbnew CTBCMCLeg( ++mun32LegId, ptrOutgoingLegAttribute, this, 0, &mLegMutex );
   pCallLeg->CreateCall();

Bridging an Incoming Call (manual method)

 TBX_VOID CTBCAFMediaGateway::OnCallLegPresent
 (
   IN	TBCMC_LEG_ID				in_LegId,
   IN	CTBCMC_CALL_LEG_ATTRIBUTE_COMMON &	in_CallLegAttribute,
   IN	CTBCMC_PROTOCOL_ATTRIBUTE &		in_ProtocolAttribute
 )
 {
 TBCAF_MUTEX_GET_SCOPE_BEGIN( &mMutex )
        PCTBCMC_CALL_LEG_ATTRIBUTE	pCallLegAttribute;
        PTRCTBCMC_CALL_LEG_ATTRIBUTE	ptrIncomingCallLegAttribute;
        PTRCTBCMC_CALL_LEG_ATTRIBUTE    ptrOutgoingCallLegAttribute;
 	/*---------------------------------------------------------------------------------------------------------------------------
 	 |  Code section
 	 *--------------------------------------------------------------------------------------------------------------------------*/
 	CAFCODE( CTBCAFMediaGateway::OnCallLegPresent )
 	{
               pCallLegAttribute           = in_CallLegAttribute.GetCallLegAttribute();
               ptrIncomingCallLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE(*pCallLegAttribute);
               ptrOutgoingCallLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE();
   
               PCTBCMCLeg pIncomingCallLeg = tbnew CTBCMCLeg( ++mun32LegId, ptrIncomingCallLegAttribute, this, 0, &mLegMutex );
               pIncomingCallLeg->CreateCall();
   
               ptrOutgoingCallLegAttribute->GetCalledNumber()         = ptrIncomingCallLegAttribute->GetCallingNumber();
               ptrOutgoingCallLegAttribute->GetCallingNumber()        = ptrIncomingCallLegAttribute->GetCalledNumber();
               ptrOutgoingCallLegAttribute->GetNetworkAccessPoint()   = ptrIncomingCallLegAttribute->GetNetworkAccessPoint();
   
               PCTBCMCLeg pOutgoingCallLeg = tbnew CTBCMCLeg( ++mun32LegId, ptrOutgoingCallLegAttribute, this, 0, &mLegMutex );
               pOutgoingCallLeg->CreateCall();
   
 	       TBX_EXIT_SUCCESS( TBX_RESULT_OK );
 	}
 
 	/*---------------------------------------------------------------------------------------------------------------------------
 	 |  Exception handling section
 	 *--------------------------------------------------------------------------------------------------------------------------*/
 	CAF_EXCEPTION_HANDLING
 
 	/*---------------------------------------------------------------------------------------------------------------------------
 	 |  Error handling section
 	 *--------------------------------------------------------------------------------------------------------------------------*/
 	CAF_ERROR_HANDLING( CAF_VERBOSE )
 	{
 	}
 
 	/*---------------------------------------------------------------------------------------------------------------------------
 	 |  Cleanup section
 	 *--------------------------------------------------------------------------------------------------------------------------*/
 	CAF_CLEANUP
 	{
 	}
 
 	RETURN_VOID;
 TBCAF_MUTEX_GET_SCOPE_END( &mMutex )
 }

Note that the incoming and outgoing call leg will be joined when we receive the notification OnCallLegAnswered() indicating that the outgoing call has been answered by the remote peer.

Bridging an Incoming Call (using CTBCAFBridge )

 TBX_VOID CTBCAFMediaGateway::OnCallLegPresent
 (
   IN	TBCMC_LEG_ID				in_LegId,
   IN	CTBCMC_CALL_LEG_ATTRIBUTE_COMMON &	in_CallLegAttribute,
   IN	CTBCMC_PROTOCOL_ATTRIBUTE &		in_ProtocolAttribute
 )
 {
 TBCAF_MUTEX_GET_SCOPE_BEGIN( &mMutex )
        PCTBCMC_CALL_LEG_ATTRIBUTE	pCallLegAttribute;
        PTRCTBCMC_CALL_LEG_ATTRIBUTE	ptrIncomingCallLegAttribute;
        PTRCTBCMC_CALL_LEG_ATTRIBUTE    ptrOutgoingCallLegAttribute;
 	/*---------------------------------------------------------------------------------------------------------------------------
 	 |  Code section
 	 *--------------------------------------------------------------------------------------------------------------------------*/
 	CAFCODE( CTBCAFMediaGateway::OnCallLegPresent )
 	{
               PTRCTBCMC_CALL_LEG_ATTRIBUTE ptrIncomingCallLegAttribute;
               PTRCTBCMC_CALL_LEG_ATTRIBUTE ptrOutgoingCallLegAttribute;
               PITBCAFCallFlow	      pCallFlow;
 
               ptrOutgoingCallLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE();
               ptrIncomingCallLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE(*pCallLegAttribute);
 
               ptrOutgoingLegAttribute->GetCalledNumber()         = ptrIncomingCallLegAttribute->GetCallingNumber();
               ptrOutgoingLegAttribute->GetCallingNumber()        = ptrIncomingCallLegAttribute->GetCalledNumber();
               ptrOutgoingLegAttribute->GetNetworkAccessPoint()   = ptrIncomingCallLegAttribute->GetNetworkAccessPoint();
 
               pCallFlow = tbnew CTBCAFBridge( mun32AccountId, this );
               TBCAF_EXIT_ON_NULL( pCallFlow, TBX_RESULT_FAIL, "Failed to allocate call." );
 			
               Result = pCallFlow->AddIncoming( mun32LegId, ptrIncomingCallLegAttribute );
               TBCAF_EXIT_ON_ERROR(Result, "AddIncoming Failed." );
 
 Result = pCallFlow->AddOutgoing( ptrOutgoingCallLegAttribute );
 TBCAF_EXIT_ON_ERROR(Result, "AddOutgoing Failed." );
   
 // Start the call
 Result = pCallFlow->InitCall( &pCallFlow );
   
 	       TBX_EXIT_SUCCESS( TBX_RESULT_OK );
 	}
 
 	/*---------------------------------------------------------------------------------------------------------------------------
 	 |  Exception handling section
 	 *--------------------------------------------------------------------------------------------------------------------------*/
 	CAF_EXCEPTION_HANDLING
 
 	/*---------------------------------------------------------------------------------------------------------------------------
 	 |  Error handling section
 	 *--------------------------------------------------------------------------------------------------------------------------*/
 	CAF_ERROR_HANDLING( CAF_VERBOSE )
 	{
 	}
 
 	/*---------------------------------------------------------------------------------------------------------------------------
 	 |  Cleanup section
 	 *--------------------------------------------------------------------------------------------------------------------------*/
 	CAF_CLEANUP
 	{
 	}
 
 	RETURN_VOID;
 TBCAF_MUTEX_GET_SCOPE_END( &mMutex )
 }

Creating a Media-only Leg

If you are using a nap of type NAP_MEDIA_TDM:

   PTRCTBCMC_MEDIA_ONLY_LEG_ATTRIBUTE ptrLegAttribute;
   PTBCMC_MEDIA_DESCRIPTION           pMediaDesc;
 
   ptrLegAttribute = tbnew CTBCMC_MEDIA_ONLY_LEG_ATTRIBUTE();
   pMediaDesc	    = &ptrLegAttribute->GetProfile()->MediaDescription; 

   ptrLegAttribute->GetNetworkAccessPoint()      = "NAP_SS7_MONTREAL";
   pMediaDesc->Type                              = TBCMC_MEDIA_TYPE_AUDIO;
   pMediaDesc->Transport                         = TBCMC_MEDIA_TRANSPORT_TDM;
   pMediaDesc->Settings.TdmAudio.Type            = TBCMC_MEDIA_SETTINGS_TYPE_TDM_AUDIO;
   pMediaDesc->Settings.TdmAudio.un8Timeslot     = 5;
   Strncpy
   (
       pMediaDesc->Settings.TdmAudio.szTrunkName, 
       "TRUNK_TORONTO_1", 
       sizeof(pMediaDesc->Settings.TdmAudio.szTrunkName)
   );
 
   PCTBCMCLeg pCallLeg = tbnew CTBCMCLeg( ++mun32LegId, ptrLegAttribute, this, 0, &mLegMutex );
   pCallLeg->CreateCall();

If you are using a nap of type NAP_MEDIA_VOIP:

   TBX_RESULT                         Result;
   TBX_SDP_INFO                       SdpInfo;
   PTRCTBCMC_MEDIA_ONLY_LEG_ATTRIBUTE ptrLegAttribute;
   PTBCMC_MEDIA_DESCRIPTION           pMediaDesc;
 
   ptrLegAttribute = tbnew CTBCMC_MEDIA_ONLY_LEG_ATTRIBUTE();
   pMediaDesc	    = &ptrLegAttribute->GetProfile()->MediaDescription;
 
   ptrLegAttribute->GetNetworkAccessPoint()      = "NAP_SS7_MONTREAL";
   pMediaDesc->Type                              = TBCMC_MEDIA_TYPE_AUDIO;
   pMediaDesc->Transport                         = TBCMC_MEDIA_TRANSPORT_IP;
   pMediaDesc->Settings.PacketAudio.Type         = TBCMC_MEDIA_SETTINGS_TYPE_PACKET_AUDIO;
  
   // Set Local SDP
   Result = BuildSdpInfo("", 0, SdpInfo);                 // No IP specified, Toolpack will choose one
   TBCAF_EXIT_ON_ERROR( Result, "BuildSdpInfo failed." );
   ptrLegAttribute->SetLocalSDP(&SdpInfo);
   
   // Set Peer SDP
   Result = BuildSdpInfo("10.0.0.15", 5000, SdpInfo);     // Using peer IP address and port
   TBCAF_EXIT_ON_ERROR( Result, "BuildSdpInfo failed." );
   ptrLegAttribute->SetPeerSDP(&SdpInfo);
 
   PCTBCMCLeg pCallLeg = tbnew CTBCMCLeg( ++mun32LegId, ptrLegAttribute, this, 0, &mLegMutex );
   pCallLeg->CreateCall();


To see how to fill a TBX_SDP_INFO structure (implementation of BuildSdpInfo()), refer to Filling an SDP Structure.

Personal tools