cmmanager/cmmgr/cmmserver/src/cmmconnmethodstruct.cpp
branchRCL_3
changeset 58 83ca720e2b9a
parent 57 05bc53fe583b
child 62 bb1f80fb7db2
equal deleted inserted replaced
57:05bc53fe583b 58:83ca720e2b9a
     1 /*
       
     2 * Copyright (c) 2009-2010 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:
       
    15 * Cache side object representing a connection method.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <cmpluginbaseeng.h>
       
    22 
       
    23 #include "cmmconnmethodstruct.h"
       
    24 #include "cmmconnmethodinstance.h"
       
    25 
       
    26 #include "OstTraceDefinitions.h"
       
    27 #ifdef OST_TRACE_COMPILER_IN_USE
       
    28 #include "cmmconnmethodstructTraces.h"
       
    29 #endif
       
    30 
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // Two phased construction.
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CCmmConnMethodStruct* CCmmConnMethodStruct::NewL(
       
    37         const TUint32 aConnMethodId )
       
    38     {
       
    39     OstTraceFunctionEntry0( CCMMCONNMETHODSTRUCT_NEWL_ENTRY );
       
    40 
       
    41     CCmmConnMethodStruct* self = CCmmConnMethodStruct::NewLC( aConnMethodId );
       
    42     CleanupStack::Pop( self );
       
    43 
       
    44     OstTraceFunctionExit0( CCMMCONNMETHODSTRUCT_NEWL_EXIT );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // Two phased construction.
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CCmmConnMethodStruct* CCmmConnMethodStruct::NewLC(
       
    53         const TUint32 aConnMethodId )
       
    54     {
       
    55     OstTraceFunctionEntry0( CCMMCONNMETHODSTRUCT_NEWLC_ENTRY );
       
    56 
       
    57     CCmmConnMethodStruct* self = new( ELeave ) CCmmConnMethodStruct( aConnMethodId );
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();
       
    60 
       
    61     OstTraceFunctionExit0( CCMMCONNMETHODSTRUCT_NEWLC_EXIT );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Destructor.
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CCmmConnMethodStruct::~CCmmConnMethodStruct()
       
    70     {
       
    71     OstTraceFunctionEntry0( CCMMCONNMETHODSTRUCT_CCMMCONNMETHODSTRUCT_ENTRY );
       
    72 
       
    73     if ( iConnMethodPlugin )
       
    74         {
       
    75         delete iConnMethodPlugin;
       
    76         iConnMethodPlugin = NULL;
       
    77         }
       
    78 
       
    79     OstTraceFunctionExit0( CCMMCONNMETHODSTRUCT_CCMMCONNMETHODSTRUCT_EXIT );
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Constructor.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CCmmConnMethodStruct::CCmmConnMethodStruct( TUint32 aConnMethodId )
       
    87         :
       
    88         iConnMethodId( aConnMethodId )
       
    89     {
       
    90     OstTraceFunctionEntry0( DUP1_CCMMCONNMETHODSTRUCT_CCMMCONNMETHODSTRUCT_ENTRY );
       
    91 
       
    92     iConnMethodPlugin = NULL;
       
    93     iReferenceCounter = 0;
       
    94     iBearerType = 0;
       
    95     iStatus = ECmmConnMethodStatusNotSaved;
       
    96     iRecordStatus = ECmmRecordStatusBlank;
       
    97 
       
    98     OstTraceFunctionExit0( DUP1_CCMMCONNMETHODSTRUCT_CCMMCONNMETHODSTRUCT_EXIT );
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // Second phase constructor.
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CCmmConnMethodStruct::ConstructL()
       
   106     {
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Return the reference count.
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 TInt CCmmConnMethodStruct::GetReferenceCounter()
       
   114     {
       
   115     return iReferenceCounter;
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Increase the reference counter by one.
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CCmmConnMethodStruct::IncrementReferenceCounter()
       
   123     {
       
   124     OstTraceFunctionEntry0( CCMMCONNMETHODSTRUCT_INCREMENTREFERENCECOUNTER_ENTRY );
       
   125     iReferenceCounter++;
       
   126     OstTraceFunctionExit0( CCMMCONNMETHODSTRUCT_INCREMENTREFERENCECOUNTER_EXIT );
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // Return the connection method ID.
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 TUint32 CCmmConnMethodStruct::GetId() const
       
   134     {
       
   135     return iConnMethodId;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // Set the connection method ID.
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CCmmConnMethodStruct::SetId( const TUint32 aConnMethodId )
       
   143     {
       
   144     iConnMethodId = aConnMethodId;
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // Return bearer type.
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 TUint32 CCmmConnMethodStruct::GetBearerType() const
       
   152     {
       
   153     return iBearerType;
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // Gets the current status of this connection method struct.
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 TCmmConnMethodStatus CCmmConnMethodStruct::GetStatus() const
       
   161     {
       
   162     return iStatus;
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // Sets a new status value.
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CCmmConnMethodStruct::SetStatus( const TCmmConnMethodStatus& aStatus )
       
   171     {
       
   172     iStatus = aStatus;
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // Reload the connection method data in this cache side object to be in synch
       
   177 // with the database(only if needed).
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void CCmmConnMethodStruct::ReloadPluginDataIfNeededL()
       
   181     {
       
   182     OstTraceFunctionEntry0( CCMMCONNMETHODSTRUCT_REFRESHCONNMETHODINSTANCEL_ENTRY );
       
   183 
       
   184     if ( !iConnMethodPlugin )
       
   185         {
       
   186         User::Leave( KErrCorrupt );
       
   187         }
       
   188 
       
   189     switch ( iStatus )
       
   190         {
       
   191         case ECmmConnMethodStatusValid:
       
   192         case ECmmConnMethodStatusToBeDeleted:
       
   193             {
       
   194             if ( iRecordStatus == ECmmRecordStatusExpired )
       
   195                 {
       
   196                 iConnMethodPlugin->ReLoadL();
       
   197                 SetRecordStatus( ECmmRecordStatusLoaded );
       
   198                 }
       
   199             }
       
   200             break;
       
   201         case ECmmConnMethodStatusNotSaved: // This is checked before.
       
   202         case ECmmConnMethodStatusChanged:
       
   203         default:
       
   204             User::Leave( KErrCorrupt );  // Error, invalid status.
       
   205             break;
       
   206         }
       
   207 
       
   208     OstTraceFunctionExit0( CCMMCONNMETHODSTRUCT_REFRESHCONNMETHODINSTANCEL_EXIT );
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // Decrease the reference counter by one. Return the remaining number of
       
   213 // references.
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 TInt CCmmConnMethodStruct::ConnMethodInstanceClosed()
       
   217     {
       
   218     OstTraceFunctionEntry0( CCMMCONNMETHODSTRUCT_SESSIONINSTANCECLOSED_ENTRY );
       
   219 
       
   220     iReferenceCounter--;
       
   221     if ( iReferenceCounter < 0 )
       
   222         {
       
   223         ASSERT( 0 );
       
   224         iReferenceCounter = 0;
       
   225         }
       
   226 
       
   227     OstTraceFunctionExit0( CCMMCONNMETHODSTRUCT_SESSIONINSTANCECLOSED_EXIT );
       
   228     return iReferenceCounter;
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // Set the connection method plugin pointer, bearer type and status.
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void CCmmConnMethodStruct::SetPlugin(
       
   236         CCmPluginBaseEng* aPlugin,
       
   237         TUint32 aBearerType,
       
   238         TCmmConnMethodStatus aStatus )
       
   239     {
       
   240     OstTraceFunctionEntry0( CCMMCONNMETHODSTRUCT_SETPLUGIN_ENTRY );
       
   241 
       
   242     // Only check reference counter, it is incremented by session side instance
       
   243     // when data is copied into it.
       
   244     if ( iReferenceCounter != 0 )
       
   245         {
       
   246         ASSERT( 0 ); // Error, wrong internal status.
       
   247         }
       
   248 
       
   249     iConnMethodPlugin = aPlugin;
       
   250     iBearerType = aBearerType;
       
   251 
       
   252     switch ( aStatus )
       
   253         {
       
   254         case ECmmConnMethodStatusNotSaved:
       
   255             {
       
   256             iStatus = aStatus;
       
   257             iRecordStatus = ECmmRecordStatusUnsaved;
       
   258             }
       
   259             break;
       
   260         case ECmmConnMethodStatusValid:
       
   261             {
       
   262             iStatus = aStatus;
       
   263             iRecordStatus = ECmmRecordStatusLoaded;
       
   264             }
       
   265             break;
       
   266         case ECmmConnMethodStatusChanged:
       
   267         case ECmmConnMethodStatusToBeDeleted:
       
   268         // Fallthrough intended.
       
   269         default:
       
   270             {
       
   271             iStatus = ECmmConnMethodStatusChanged;
       
   272             ASSERT( 0 ); // Error, invalid status as argument.
       
   273             }
       
   274             break;
       
   275         }
       
   276 
       
   277     OstTraceFunctionExit0( CCMMCONNMETHODSTRUCT_SETPLUGIN_EXIT );
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // Returns the connection method plugin.
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 CCmPluginBaseEng* CCmmConnMethodStruct::GetPlugin()
       
   285     {
       
   286     return iConnMethodPlugin;
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // Called after this connection method has been deleted and database
       
   291 // transaction has completed successfully. Sets the internal state of this
       
   292 // connection method structure to reflect the new deleted state.
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 void CCmmConnMethodStruct::DeleteSuccessful( const TUint32 aNewSecondaryId )
       
   296     {
       
   297     OstTraceFunctionEntry0( CCMMCONNMETHODSTRUCT_DELETESUCCESSFUL_ENTRY );
       
   298 
       
   299     iConnMethodId = aNewSecondaryId;
       
   300     iStatus = ( ECmmConnMethodStatusNotSaved );
       
   301 
       
   302     OstTraceFunctionExit0( CCMMCONNMETHODSTRUCT_DELETESUCCESSFUL_EXIT );
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // Called after this connection method has been updated and database
       
   307 // transaction has completed successfully. Sets the internal state of this
       
   308 // connection method structure to reflect the new valid state.
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 void CCmmConnMethodStruct::UpdateSuccessful()
       
   312     {
       
   313     OstTraceFunctionEntry0( CCMMCONNMETHODSTRUCT_UPDATESUCCESSFUL_ENTRY );
       
   314     iStatus = ECmmConnMethodStatusValid;
       
   315     SetRecordStatus( ECmmRecordStatusLoaded );
       
   316 
       
   317     OstTraceFunctionExit0( CCMMCONNMETHODSTRUCT_UPDATESUCCESSFUL_EXIT );
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // Set the record status.
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 void CCmmConnMethodStruct::SetRecordStatus( const TCmmRecordStatus aStatus )
       
   325     {
       
   326     iRecordStatus = aStatus;
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // Notify about a possible change in database on specified record table.
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 void CCmmConnMethodStruct::NotifyRecordChange( const TUint32 /*aRecordType*/ )
       
   334     {
       
   335     // Only change status if it is currently ECmmRecordStatusLoaded.
       
   336     if ( iRecordStatus == ECmmRecordStatusLoaded )
       
   337         {
       
   338         iRecordStatus = ECmmRecordStatusExpired;
       
   339         }
       
   340     }
       
   341 
       
   342 // ---------------------------------------------------------------------------
       
   343 // Return the status of the records.
       
   344 // ---------------------------------------------------------------------------
       
   345 //
       
   346 TCmmRecordStatus CCmmConnMethodStruct::GetRecordStatus() const
       
   347     {
       
   348     return iRecordStatus;
       
   349     }
       
   350 
       
   351 // End of file