voipplugins/voipadapters/provisioningfile/src/WPProtocolProfileHandlerSIP.cpp
changeset 0 a4daefaec16c
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Handling SIP profiles.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "WPProtocolProfileHandlerSIP.h"
       
    21 #include    "wpprovisioningfileconst.h"
       
    22 #include    "wpprovisioningfiledebug.h"
       
    23 
       
    24 #include    <sip.h>
       
    25 #include    <sipprofileregistry.h>
       
    26 #include    <sipprofile.h>
       
    27 
       
    28 #include    <sipmanagedprofile.h>
       
    29 #include    <sipmanagedprofileregistry.h>
       
    30 
       
    31 // ============================= LOCAL FUNCTIONS ===============================
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CWPProtocolProfileHandlerSIP::CWPProtocolProfileHandlerSIP
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CWPProtocolProfileHandlerSIP::CWPProtocolProfileHandlerSIP()
       
    42     {
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CWPProtocolProfileHandlerSIP::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CWPProtocolProfileHandlerSIP::ConstructL()
       
    51     {
       
    52     FLOG( "[ProvisioningFile] CWPProtocolProfileHandlerSIP::ConstructL" );
       
    53     
       
    54     iSIP = CSIP::NewL( KProvisioningFileUid, *this );
       
    55     
       
    56     iSIPProfileRegistry = CSIPProfileRegistry::NewL( *iSIP, *this );
       
    57 
       
    58     // Get SIP profile pointers
       
    59     iSIPProfileRegistry->ProfilesL( iSIPProfiles );
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CWPProtocolProfileHandlerSIP::NewL
       
    64 // Two-phased constructor.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CWPProtocolProfileHandlerSIP* CWPProtocolProfileHandlerSIP::NewL()
       
    68     {
       
    69     CWPProtocolProfileHandlerSIP* self = 
       
    70         CWPProtocolProfileHandlerSIP::NewLC();
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CWPProtocolProfileHandlerSIP::NewLC
       
    78 // Two-phased constructor.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CWPProtocolProfileHandlerSIP* CWPProtocolProfileHandlerSIP::NewLC()
       
    82     {
       
    83     CWPProtocolProfileHandlerSIP* self = 
       
    84         new (ELeave) CWPProtocolProfileHandlerSIP();
       
    85     CleanupStack::PushL( self );
       
    86     self->ConstructL();
       
    87     return self;
       
    88     }
       
    89 
       
    90     
       
    91 // Destructor
       
    92 CWPProtocolProfileHandlerSIP::~CWPProtocolProfileHandlerSIP()
       
    93     {
       
    94     FLOG( "[ProvisioningFile] CWPProtocolProfileHandlerSIP::~CWPProtocolProfileHandlerSIP" );
       
    95     
       
    96     delete iSIPProfileRegistry;
       
    97     iSIPProfileRegistry = NULL;
       
    98 
       
    99     delete iSIP;
       
   100     iSIP = NULL;
       
   101     
       
   102     // Close SIP Profile id array
       
   103     iSIPProfileIds.Reset();
       
   104     iSIPProfileIds.Close();
       
   105 
       
   106     // Close SIP Profile array
       
   107     for ( TInt i = iSIPProfiles.Count()-1; i >= 0; i-- )
       
   108         {
       
   109         delete iSIPProfiles[i];
       
   110         }
       
   111     iSIPProfiles.Close();
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CWPProtocolProfileHandlerSIP::IncomingRequest
       
   116 // (other items were commented in a header).
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CWPProtocolProfileHandlerSIP::IncomingRequest(
       
   120     TUint32 /*aIapId*/,
       
   121     CSIPServerTransaction* /*aTransaction*/ )
       
   122     {
       
   123     FLOG( "[ProvisioningFile] CWPProtocolProfileHandlerSIP::IncomingRequest 1" );
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CWPProtocolProfileHandlerSIP::TimedOut
       
   128 // (other items were commented in a header).
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CWPProtocolProfileHandlerSIP::TimedOut(
       
   132     CSIPServerTransaction& /*aTransaction*/ )
       
   133     {
       
   134     FLOG( "[ProvisioningFile] CWPProtocolProfileHandlerSIP::TimedOut" );
       
   135     }
       
   136     
       
   137 // -----------------------------------------------------------------------------
       
   138 // CWPProtocolProfileHandlerSIP::ProfileRegistryEventOccurred
       
   139 // Handle profile events.
       
   140 // (other items were commented in a header).
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CWPProtocolProfileHandlerSIP::ProfileRegistryEventOccurred(
       
   144     TUint32 /*aProfileId*/,
       
   145     MSIPProfileRegistryObserver::TEvent /*aEvent*/ )
       
   146     {
       
   147     FLOG( "[ProvisioningFile] CWPProtocolProfileHandlerSIP::ProfileRegistryEventOccurred" );
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CWPProtocolProfileHandlerSIP::ProfileRegistryErrorOccurred
       
   152 // Handle SIP profile error events
       
   153 // (other items were commented in a header).
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CWPProtocolProfileHandlerSIP::ProfileRegistryErrorOccurred(
       
   157     TUint32 /*aProfileId*/,
       
   158     TInt /*aError*/ )
       
   159     {
       
   160     FLOG( "[ProvisioningFile] CWPProtocolProfileHandlerSIP::ProfileRegistryErrorOccurred" );
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CWPProtocolProfileHandlerSIP::SetProfilesIapL
       
   165 // Set Protocol Profile use this IAP.
       
   166 // (other items were commented in a header).
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CWPProtocolProfileHandlerSIP::SetProfilesIapL(
       
   170     TInt aProfileId, 
       
   171     TUint32 aProfileIapId )
       
   172     {
       
   173     FLOG( "[ProvisioningFile] CWPProtocolProfileHandlerSIP::SetProfilesIapL" );
       
   174     
       
   175     // Set new IAP Id and Update SIP profile table
       
   176     CSIPProfile* updatedProfile = NULL;
       
   177     TInt index( 0 );
       
   178     
       
   179     // SIP engine for saving
       
   180     CSIPManagedProfileRegistry* sipEngine = 
       
   181         CSIPManagedProfileRegistry::NewLC( *this );
       
   182         
       
   183     // Take right SIP profile
       
   184     updatedProfile = FindSIPProfileByIdL( iSIPProfileIds[aProfileId], index );
       
   185     
       
   186     // Take managed SIP Profile
       
   187     CSIPManagedProfile* profile = 
       
   188         static_cast<CSIPManagedProfile*> ( updatedProfile );
       
   189     
       
   190     // Add new Iap Id to SIP Profile
       
   191     User::LeaveIfError( profile->SetParameter( KSIPAccessPointId, 
       
   192                                                aProfileIapId ) );
       
   193     
       
   194     // Save changes
       
   195     sipEngine->SaveL( *profile );
       
   196     
       
   197     // Update the SIP table
       
   198     iSIPProfiles.Remove( index );
       
   199     iSIPProfiles.Insert( updatedProfile, index );
       
   200                 
       
   201     CleanupStack::PopAndDestroy( sipEngine );
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CWPProtocolProfileHandlerSIP::FindSIPProfileByIdL
       
   206 // Find SIP Profile Id from local SIP Profile pointer array
       
   207 // (other items were commented in a header).
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 CSIPProfile* CWPProtocolProfileHandlerSIP::FindSIPProfileByIdL(
       
   211     TUint32 aProfileId,
       
   212     TInt& aIndex )
       
   213     {
       
   214     FLOG( "[ProvisioningFile] CWPProtocolProfileHandlerSIP::FindSIPProfileByIdL" );
       
   215     
       
   216     CSIPProfile* result = NULL;
       
   217     TUint32 sipId = 0;
       
   218     const TInt profilesCount = iSIPProfiles.Count();
       
   219 
       
   220     for ( TInt i = 0; i < profilesCount; i++ )
       
   221         {
       
   222         sipId = 0;
       
   223         iSIPProfiles[i]->GetParameter( KSIPProfileId, sipId );
       
   224         if ( sipId == aProfileId )
       
   225             {
       
   226             result = iSIPProfiles[i];
       
   227             aIndex = i;
       
   228             break;
       
   229             }
       
   230         }
       
   231 
       
   232     if ( !result )
       
   233         {
       
   234         User::Leave( KErrNotFound );
       
   235         }
       
   236 
       
   237     return result;
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CWPProtocolProfileHandlerSIP::SetProvisioningIdL
       
   242 // Set provisioning Protocol Profiles Id in array.
       
   243 // (other items were commented in a header).
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CWPProtocolProfileHandlerSIP::SetProvisioningIdL()    
       
   247     {
       
   248     FLOG( "[ProvisioningFile] CWPProtocolProfileHandlerSIP::SetProvisioningIdL" );
       
   249     
       
   250     TUint32 sipId( 0 );
       
   251     TBool idExist( EFalse );
       
   252     
       
   253     RArray<TUint32> oldIdArray;
       
   254     CleanupClosePushL( oldIdArray );
       
   255         
       
   256     // delete old SIP Profile array
       
   257     for ( TInt i = 0; i < iSIPProfiles.Count(); i++ )
       
   258         {
       
   259         iSIPProfiles[i]->GetParameter( KSIPProfileId, sipId );
       
   260         User::LeaveIfError( oldIdArray.Append( sipId ) );
       
   261         delete iSIPProfiles[i];
       
   262         iSIPProfiles[i] = NULL;
       
   263         }
       
   264     iSIPProfiles.Close();
       
   265             
       
   266     // Get SIP profile pointers
       
   267     iSIPProfileRegistry->ProfilesL( iSIPProfiles );
       
   268     
       
   269     if ( oldIdArray.Count() < iSIPProfiles.Count() )
       
   270         {
       
   271         for ( TInt j = 0; j < iSIPProfiles.Count(); j++ )
       
   272             {
       
   273             idExist = EFalse;
       
   274             TUint32 newSipId( 0 );
       
   275             User::LeaveIfError( iSIPProfiles[j]->GetParameter( KSIPProfileId, newSipId ) );
       
   276             
       
   277             for ( TInt k = 0; k < oldIdArray.Count(); k++ )
       
   278                 {
       
   279                 if ( oldIdArray[k] == newSipId )
       
   280                     {
       
   281                     idExist = ETrue;
       
   282                     k = oldIdArray.Count();
       
   283                     }
       
   284                 }
       
   285                 
       
   286             if ( !idExist )
       
   287                 {
       
   288                 // Save Id to Profile Id array
       
   289                 User::LeaveIfError( iSIPProfileIds.Append( newSipId ) );
       
   290                 }
       
   291             }
       
   292         }
       
   293         
       
   294     CleanupStack::PopAndDestroy( &oldIdArray );        
       
   295     FLOG( "[ProvisioningFile] *** CWPProtocolProfileHandlerSIP::SetProvisioningIdL out" );
       
   296     }
       
   297     
       
   298 // -----------------------------------------------------------------------------
       
   299 // CWPProtocolProfileHandlerSIP::ProvisionedCount
       
   300 // Get provisioned Protocol Profiles count.
       
   301 // (other items were commented in a header).
       
   302 // -----------------------------------------------------------------------------
       
   303 TInt CWPProtocolProfileHandlerSIP::ProvisionedCount()    
       
   304     {
       
   305     FLOG( "[ProvisioningFile] CWPProtocolProfileHandlerSIP::GetProvisionedCount" );
       
   306     
       
   307     return iSIPProfileIds.Count();
       
   308     }    
       
   309     
       
   310 //  End of File