Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


Example showing use of the SIP Profile API

The following code fragments show a simple use of the API.

1

Create an instance of the CSIPProfileRegistry class:

// An instance of the SIP client is needed.
// To do this, the client must implement MSIPObserver 
// (see the SIP Client API).
iSip = CSIP::NewL(iDoc.AppUid(), *this);

// To create a CSIPProfileRegistry object, the client must
// provide an implementation of MSIPProfileRegistryObserver.
iProfileRegistry = CSIPProfileRegistry::NewL(*iSip, *this);

2

This is code that shows you how to retrieve profiles by matching an AOR:

// To retrieve more than one profile, the client must create
// an RPointerArray object to hold pointers to instances of CSIPProfile.
RPointerArray<CSIPProfile> profiles;

// Profiles matching a given AOR are returned in the array.
iProfileRegistry->ProfilesL(_L8( "sip:[email protected]" ), profiles );
...

// When a client retrieves a profile, its ownership is transferred to that
// client, so it becomes responsible for deleting the instances when they are
// no longer needed.
profiles.ResetAndDestroy();

3

This is code that shows you how to retrieve profiles by type:

// To retrieve more than one profile, the client must create
// an RPointerArray object to holding pointers to instances of CSIPProfile.
RPointerArray<CSIPProfile> profiles;

// The wanted type is defined using a variable of type
// TSIPProfileTypeInfo.
TSIPProfileTypeInfo type;
type.iSIPProfileClass = TSIPProfileTypeInfo::EInternet;
type.iSIPProfileName = _L8("IETF");

// Profiles matching a given type are returned in the array.
iProfileRegistry->ProfilesL(type, profiles);
...
// When a client retrieves a profile, its ownership is transferred to that
// client, so it becomes responsible for deleting the instances when they are
// no longer needed.
profiles.ResetAndDestroy();

4

This is code that shows you how to retrieve the default profile:

// Retrieving a default profile.
CSIPProfile* profile = iProfileRegistry->DefaultProfileL();

// When a client retrieves a profile, its ownership is transferred to that
// client, so it becomes responsible for deleting the instances when they are
// no longer needed.
delete profile;

5

This is code that shows you how to enable a profile:

// Retrieving a default profile. The instance must be stored and must not
// be deleted before the profile is disabled.
iProfile = iProfileRegistry->DefaultProfileL();

// Safety check that DefaultProfile() didn't return NULL pointer.
if ( !iProfile )
  {
  iObserver->ProfileError( KErrNotFound );
  User::Leave( KErrNotFound );
  }

// The client asks the API to enable the retrieved profile for its use.
// For that, the client must implement MSIPConnectionObserver.
iProfileRegistry->EnableL( *iProfile, *this );
TBool val(EFalse);
TInt err = iProfile->GetParameter(KSIPProfileRegistered,val);
if(err!=KErrNone)User::Leave(err);

// The parameter val indicates whether the profile can be immediately used for
// creating a session, or whether the client must wait for the profile to be
// registered.
if (val)
  {
  // get the SIP connection used by the profile
  iConnection = iProfileRegistry->ConnectionL(*iProfile);
  // create a SIP dialog for sending an INVITE;
  // toHeader contains the SIP address of the invited party
  iDialog = CSIPInviteDialogAssoc::NewL( *iConnection, *toHeader, *iProfile );
  //Continue session establishement using the SIP Client API
  
  }
  else
  {
  // wait for the profile to be registered before using it further
  }

6

This is code that shows you how to get registration events:

// A callback function, which must be implemented by the client, is
// called when the registration status of a profile owned by the client
// is changed.
void CMySIPClient:: ProfileRegistryEventOccurred(TUint32 aProfileId,
MSIPProfileRegistryObserver::TEvent aEvent)
  {
  iProfileId = aProfileId;
  switch(aEvent)
    {
    case EProfileCreated:
      {
      iEventId = EAdded;
      break;
      }
    case EProfileUpdated:
      {
      iEventId = EUpdated;
      break;
      }
    case EProfileRegistered:
      {
      iEventId = CMySIPClient::ERegistered;
      break;
      }
    case EProfileDeregistered:
      {
      iEventId = CMySIPClient::EDeregistered;
      break;
      }
    case EProfileDestroyed:
      {
      iEventId = ERemoved;
      break;
      }
    default:
      break;
    }
  }

7

This is code that shows you how to disabling a profile:

// A client should disable an enabled profile when it no longer needs to
// use it.
TInt status = iProfileRegistry->Disable(*iProfile);

// Finally, the client should delete the profile.
delete iProfile;