PECengine/CoreUtilsLib2/Src/CPEngSessionSlotEvent.cpp
branchRCL_3
changeset 17 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
16:6ca72c0fe49a 17:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Session Slot Event container.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include    "CPEngSessionSlotEvent.h"
       
    20 #include    "PEngCoreUtilsTools.h"
       
    21 #include    "CPEngSessionSlotId.h"
       
    22 
       
    23 
       
    24 
       
    25 // CONSTANTS
       
    26 
       
    27 //LOCAL PANIC
       
    28 namespace
       
    29     {
       
    30     //SessionSlotEvent panic
       
    31     _LIT( KPEngSessionSlotEventPanic, "SessSlotEvent" );
       
    32 
       
    33     //SessionSlotEvent panic reasons
       
    34     enum TPEngSessionSlotEventPanicReasons
       
    35         {
       
    36         EPEngNoSessionSlotId = 1
       
    37         };
       
    38 
       
    39     void PanicSessionSlotEvent( TPEngSessionSlotEventPanicReasons aPanicReason )
       
    40         {
       
    41         User::Panic( KPEngSessionSlotEventPanic, aPanicReason );
       
    42         }
       
    43     }
       
    44 
       
    45 
       
    46 
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CPEngSessionSlotEvent::CPEngSessionSlotEvent
       
    52 // C++ default constructor can NOT contain any code, that
       
    53 // might leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CPEngSessionSlotEvent::CPEngSessionSlotEvent()
       
    57         : iIdentificationOwned( EFalse )
       
    58     {
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CPEngSessionSlotEvent::NewL()
       
    64 // Two-phased constructor.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CPEngSessionSlotEvent* CPEngSessionSlotEvent::NewL()
       
    68     {
       
    69     CPEngSessionSlotEvent* self = new ( ELeave ) CPEngSessionSlotEvent();
       
    70     return self;
       
    71     }
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CPEngSessionSlotEvent::NewLC()
       
    76 // Two-phased constructor.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C CPEngSessionSlotEvent* CPEngSessionSlotEvent::NewLC()
       
    80     {
       
    81     CPEngSessionSlotEvent* self = new ( ELeave ) CPEngSessionSlotEvent();
       
    82     CleanupStack::PushL( self );
       
    83     return self;
       
    84     }
       
    85 
       
    86 
       
    87 // Destructor
       
    88 CPEngSessionSlotEvent::~CPEngSessionSlotEvent()
       
    89     {
       
    90     if ( iIdentificationOwned )
       
    91         {
       
    92         delete iSessionId;
       
    93         }
       
    94     delete iEventDesc;
       
    95     delete iApplicationId;
       
    96 
       
    97 
       
    98 #if _BullseyeCoverage
       
    99     cov_write();
       
   100 #endif
       
   101     }
       
   102 
       
   103 
       
   104 
       
   105 // =============================================================================
       
   106 // ======================= Session Slot Event ==================================
       
   107 // =============================================================================
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CPEngSessionSlotEvent::SessionSlotIndentification()
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 EXPORT_C const CPEngSessionSlotId& CPEngSessionSlotEvent::SessionSlotIndentification( ) const
       
   114     {
       
   115     __ASSERT_ALWAYS( iSessionId, PanicSessionSlotEvent( EPEngNoSessionSlotId ) );
       
   116     return *iSessionId;
       
   117     }
       
   118 
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CPEngSessionSlotEvent::ApplicationId()
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C const TDesC& CPEngSessionSlotEvent::ApplicationId( void ) const
       
   125     {
       
   126     return DoGetDescriptor( iApplicationId );
       
   127     }
       
   128 
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CPEngSessionSlotEvent::Event()
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 EXPORT_C TPEngNWSessionSlotEvent CPEngSessionSlotEvent::Event( void ) const
       
   135     {
       
   136     return iEvent;
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CPEngSessionSlotEvent::AppSessSlotState()
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 EXPORT_C TPEngNWSessionSlotState CPEngSessionSlotEvent::AppSessSltState( void ) const
       
   145     {
       
   146     return iAppSessState;
       
   147     }
       
   148 
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CPEngSessionSlotEvent::GlobSessSltState()
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C TPEngNWSessionSlotState CPEngSessionSlotEvent::GlobSessSltState( void ) const
       
   155     {
       
   156     return iGlobSessState;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CPEngSessionSlotEvent::EventInt()
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 EXPORT_C TInt CPEngSessionSlotEvent::EventInt( void ) const
       
   164     {
       
   165     return iEventInt;
       
   166     }
       
   167 
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CPEngSessionSlotEvent::EventDesc()
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 EXPORT_C const TDesC& CPEngSessionSlotEvent::EventDesc( void ) const
       
   174     {
       
   175     return DoGetDescriptor( iEventDesc );
       
   176     }
       
   177 
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CPEngSessionSlotEvent::SetSessionStlotId()
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 EXPORT_C void CPEngSessionSlotEvent::SetSessionSlotId(
       
   184     CPEngSessionSlotId* aSlotId,
       
   185     TBool aOwnershipTransfered /* EFalse */ )
       
   186     {
       
   187     if ( iSessionId && iIdentificationOwned )
       
   188         {
       
   189         delete iSessionId;
       
   190         }
       
   191 
       
   192     iSessionId = aSlotId;
       
   193     iIdentificationOwned = aOwnershipTransfered;
       
   194     }
       
   195 
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CPEngSessionSlotEvent::SetAppIdL()
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 EXPORT_C void CPEngSessionSlotEvent::SetAppIdL( const TDesC& aAppId )
       
   202     {
       
   203     DoSetDescriptorL( iApplicationId, aAppId );
       
   204     }
       
   205 
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CPEngSessionSlotEvent::SetSessSltEvent()
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C void CPEngSessionSlotEvent::SetSessSltEvent(
       
   212     TPEngNWSessionSlotEvent aEvent )
       
   213     {
       
   214     iEvent = aEvent;
       
   215     }
       
   216 
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CPEngSessionSlotEvent::SetAppSessSltState()
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 EXPORT_C void CPEngSessionSlotEvent::SetAppSessSltState(
       
   223     TPEngNWSessionSlotState aState )
       
   224     {
       
   225     iAppSessState = aState;
       
   226     }
       
   227 
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CPEngSessionSlotEvent::SetGlobSessSltState()
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 EXPORT_C void CPEngSessionSlotEvent::SetGlobSessSltState(
       
   234     TPEngNWSessionSlotState aState )
       
   235     {
       
   236     iGlobSessState = aState;
       
   237     }
       
   238 
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CPEngSessionSlotEvent::SetEventInt()
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 EXPORT_C void CPEngSessionSlotEvent::SetEventInt(
       
   245     TInt aEventInt )
       
   246     {
       
   247     iEventInt = aEventInt;
       
   248     }
       
   249 
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CPEngSessionSlotEvent::SetEventDesL()
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 EXPORT_C void CPEngSessionSlotEvent::SetEventDesL(
       
   256     const TDesC& aEventDes )
       
   257     {
       
   258     DoSetDescriptorL( iEventDesc, aEventDes );
       
   259     }
       
   260 
       
   261 
       
   262 
       
   263 
       
   264 // =============================================================================
       
   265 // =========== Externalize Internalize functions ===============================
       
   266 // =============================================================================
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CPEngSessionSlotEvent::InternalizeL()
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 EXPORT_C void CPEngSessionSlotEvent::InternalizeL( RReadStream& aStream,
       
   273                                                    TBool aAllData )
       
   274     {
       
   275     if ( aAllData )
       
   276         {
       
   277         CPEngSessionSlotId* newId = CPEngSessionSlotId::NewLC();
       
   278         newId->InternalizeL( aStream );
       
   279         SetSessionSlotId( newId, ETrue );
       
   280         CleanupStack::Pop( newId );
       
   281         }
       
   282 
       
   283     delete iApplicationId;
       
   284     iApplicationId = NULL;
       
   285     iApplicationId = InternalizeBufferL( aStream );
       
   286 
       
   287 
       
   288     iEvent = static_cast<TPEngNWSessionSlotEvent>( aStream.ReadInt32L() );
       
   289     iAppSessState = static_cast<TPEngNWSessionSlotState>( aStream.ReadInt32L() );
       
   290     iGlobSessState = static_cast<TPEngNWSessionSlotState>( aStream.ReadInt32L() );
       
   291 
       
   292 
       
   293     iEventInt = aStream.ReadInt32L();
       
   294 
       
   295     delete iEventDesc;
       
   296     iEventDesc = NULL;
       
   297     iEventDesc = InternalizeBufferL( aStream );
       
   298     }
       
   299 
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CPEngSessionSlotEvent::UnpackEventL()
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 EXPORT_C void CPEngSessionSlotEvent::UnpackEventL( const TDesC8& aDes )
       
   306     {
       
   307     RDesReadStream rs;
       
   308     rs.Open( aDes );               // CSI: 65 #
       
   309     CleanupClosePushL( rs );
       
   310     InternalizeL( rs, ETrue );
       
   311     CleanupStack::PopAndDestroy(); // rs
       
   312     }
       
   313 
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CPEngSessionSlotEvent::UnpackEventPartL()
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 EXPORT_C void CPEngSessionSlotEvent::UnpackEventPartL( const TDesC8& aDes )
       
   320     {
       
   321     RDesReadStream rs;
       
   322     rs.Open( aDes );               // CSI: 65 #
       
   323     CleanupClosePushL( rs );
       
   324 
       
   325     InternalizeL( rs, EFalse );
       
   326 
       
   327     CleanupStack::PopAndDestroy(); // rs
       
   328     }
       
   329 
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CPEngSessionSlotEvent::ExternalizeL()
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 EXPORT_C void CPEngSessionSlotEvent::ExternalizeL( RWriteStream& aStream,
       
   336                                                    TBool aAllData ) const
       
   337     {
       
   338     if ( aAllData )
       
   339         {
       
   340         __ASSERT_ALWAYS( iSessionId, PanicSessionSlotEvent( EPEngNoSessionSlotId ) );
       
   341         iSessionId->ExternalizeL( aStream );
       
   342         }
       
   343 
       
   344     ExternalizeBufferL( iApplicationId, aStream );
       
   345 
       
   346     aStream.WriteInt32L( iEvent );
       
   347     aStream.WriteInt32L( iAppSessState );
       
   348     aStream.WriteInt32L( iGlobSessState );
       
   349 
       
   350     aStream.WriteInt32L( iEventInt );
       
   351     ExternalizeBufferL( iEventDesc, aStream );
       
   352     }
       
   353 
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CPEngSessionSlotEvent::Size()
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 EXPORT_C TInt CPEngSessionSlotEvent::Size( TBool aAllData ) const
       
   360     {
       
   361     TInt size = 16; // iEvent: 4 bytes
       
   362     // iAppSessState: 4 bytes
       
   363     // iGlobSessState: 4 bytes
       
   364     // iEventInt: 4 bytes
       
   365 
       
   366     if ( aAllData )
       
   367         {
       
   368         __ASSERT_ALWAYS( iSessionId, PanicSessionSlotEvent( EPEngNoSessionSlotId ) );
       
   369         size += iSessionId->Size();
       
   370         }
       
   371 
       
   372     size += BufferExternalizeSizeInBytes( iApplicationId );
       
   373     size += BufferExternalizeSizeInBytes( iEventDesc );
       
   374 
       
   375     return size;
       
   376     }
       
   377 
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // CPEngSessionSlotEvent::PackEventLC()
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 EXPORT_C HBufC8* CPEngSessionSlotEvent::PackEventLC()
       
   384     {
       
   385     HBufC8* packBuffer = HBufC8::NewLC( Size( ETrue ) );
       
   386     TPtr8 pack( packBuffer->Des() );
       
   387 
       
   388     RDesWriteStream ws;
       
   389     ws.Open( pack );               // CSI: 65 #
       
   390     CleanupClosePushL( ws );
       
   391 
       
   392     ExternalizeL( ws, ETrue );
       
   393 
       
   394     ws.CommitL();
       
   395     CleanupStack::PopAndDestroy(); //ws
       
   396 
       
   397     packBuffer = packBuffer->ReAllocL( packBuffer->Length() );
       
   398     CleanupStack::Pop();
       
   399     CleanupStack::PushL( packBuffer ); //Due realloc
       
   400     return packBuffer;
       
   401     }
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // CPEngSessionSlotEvent::PackEventL()
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 EXPORT_C void CPEngSessionSlotEvent::PackEventL( RBuf8& aBuf )
       
   408     {
       
   409     TInt size( Size( ETrue ) );
       
   410     if ( aBuf.MaxSize() < size )
       
   411         {
       
   412         aBuf.ReAllocL( size );
       
   413         }
       
   414     aBuf.Zero();
       
   415 
       
   416     RDesWriteStream ws;
       
   417     ws.Open( aBuf );              // CSI: 65 #
       
   418     CleanupClosePushL( ws );
       
   419 
       
   420     ExternalizeL( ws, ETrue );
       
   421 
       
   422     ws.CommitL();
       
   423     CleanupStack::PopAndDestroy(); //ws
       
   424     }
       
   425 
       
   426 // -----------------------------------------------------------------------------
       
   427 // CPEngSessionSlotEvent::PackEventPartL()
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 EXPORT_C HBufC8* CPEngSessionSlotEvent::PackEventPartLC()
       
   431     {
       
   432     HBufC8* packBuffer = HBufC8::NewLC( Size( EFalse ) );
       
   433     TPtr8 pack( packBuffer->Des() );
       
   434 
       
   435     RDesWriteStream ws;
       
   436     ws.Open( pack );              // CSI: 65 #
       
   437     CleanupClosePushL( ws );
       
   438 
       
   439     ExternalizeL( ws, EFalse );
       
   440 
       
   441     ws.CommitL();
       
   442     CleanupStack::PopAndDestroy(); //ws
       
   443 
       
   444     packBuffer = packBuffer->ReAllocL( packBuffer->Length() );
       
   445     CleanupStack::Pop();
       
   446     CleanupStack::PushL( packBuffer ); //Due realloc
       
   447     return packBuffer;
       
   448     }
       
   449 
       
   450 
       
   451 // End of File
       
   452 
       
   453