PECengine/PresenceManager2/SrcNWSessionSlot/CPEngNWSessionSlotID2Imp.cpp
branchRCL_3
changeset 13 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
12:6ca72c0fe49a 13:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2004 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:  NWSessionSlotID implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include    "CPEngNWSessionSlotID2Imp.h"
       
    20 #include    "CPEngSessionSlotId.h"
       
    21 #include    <s32strm.h>
       
    22 #include    <s32mem.h>
       
    23 
       
    24 
       
    25 // ============================ LOCAL FUNCTIONS ===============================
       
    26 namespace
       
    27     {
       
    28     // -----------------------------------------------------------------------------
       
    29     // ValueForMatchMode()
       
    30     // -----------------------------------------------------------------------------
       
    31     //
       
    32     const TDesC& ValueForMatchMode( const TDesC& aReqValue,
       
    33                                     TPEngNWSSIDMatchMode aMatchMode )
       
    34         {
       
    35         if ( aMatchMode == EPEngMMWildAny )
       
    36             {
       
    37             return KPEngMatchSymbolWildAny;
       
    38             }
       
    39 
       
    40         return aReqValue;
       
    41         }
       
    42 
       
    43     // -----------------------------------------------------------------------------
       
    44     // ExternalizeBufferL()
       
    45     // -----------------------------------------------------------------------------
       
    46     //
       
    47     void ExternalizeBufferL( const HBufC* aBuffer, RWriteStream& aStream )
       
    48         {
       
    49         if ( aBuffer && aBuffer->Length() != 0 )
       
    50             {
       
    51             aStream.WriteInt32L( aBuffer->Length() );
       
    52             aStream.WriteL( *aBuffer );
       
    53             }
       
    54         else
       
    55             {
       
    56             aStream.WriteInt32L( 0 );
       
    57             }
       
    58         }
       
    59 
       
    60 
       
    61     // -----------------------------------------------------------------------------
       
    62     // InternalizeBufferL()
       
    63     // -----------------------------------------------------------------------------
       
    64     //
       
    65     HBufC* InternalizeBufferL( RReadStream& aStream )
       
    66         {
       
    67         HBufC* buffer = NULL;
       
    68 
       
    69         TInt length = aStream.ReadInt32L();
       
    70         if ( length != 0 )
       
    71             {
       
    72             buffer = HBufC::NewLC( length );
       
    73             TPtr ptr( buffer->Des() );
       
    74             aStream.ReadL( ptr, length );
       
    75             CleanupStack::Pop(); //buffer
       
    76             }
       
    77 
       
    78         return buffer;
       
    79         }
       
    80 
       
    81 
       
    82     // -----------------------------------------------------------------------------
       
    83     // BufferExternalizeSizeInBytes()
       
    84     // -----------------------------------------------------------------------------
       
    85     //
       
    86     TInt BufferExternalizeSizeInBytes( const HBufC* aBuffer )
       
    87         {
       
    88         TInt size( 4 ); //Buffer length indicator: 4 bytes
       
    89 
       
    90         if ( aBuffer && aBuffer->Length() != 0 )
       
    91             {
       
    92             size += aBuffer->Size();
       
    93             }
       
    94 
       
    95         return size;
       
    96         }
       
    97     }
       
    98 
       
    99 
       
   100 // ============================ MEMBER FUNCTIONS ===============================
       
   101 
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CPEngNWSessionSlotID2Imp::NewL()
       
   105 // Two-phased constructor.
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CPEngNWSessionSlotID2Imp* CPEngNWSessionSlotID2Imp::NewL()
       
   109     {
       
   110     CPEngNWSessionSlotID2Imp* self = new ( ELeave ) CPEngNWSessionSlotID2Imp();
       
   111     CleanupStack::PushL( self );
       
   112     self->ConstructL();
       
   113     CleanupStack::Pop( self );
       
   114     return self;
       
   115     }
       
   116 
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CPEngNWSessionSlotID2Imp::CloneL()
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 CPEngNWSessionSlotID2Imp* CPEngNWSessionSlotID2Imp::CloneL() const
       
   123     {
       
   124     CPEngNWSessionSlotID2Imp* clone = CPEngNWSessionSlotID2Imp::NewL();
       
   125     CleanupStack::PushL( clone );
       
   126 
       
   127     clone->iBasePart->CopyL( *iBasePart );
       
   128 
       
   129     if ( iAppId )
       
   130         {
       
   131         clone->iAppId = iAppId->AllocL();
       
   132         }
       
   133 
       
   134     clone->iServiceAddressMatchMode = iServiceAddressMatchMode;
       
   135     clone->iUserIdMatchMode = iUserIdMatchMode;
       
   136     clone->iAppIdMatchMode = iAppIdMatchMode;
       
   137 
       
   138     CleanupStack::Pop( clone );
       
   139     return clone;
       
   140     }
       
   141 
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CPEngNWSessionSlotID2Imp::Reset()
       
   145 // Reset operation.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CPEngNWSessionSlotID2Imp::Reset()
       
   149     {
       
   150     iBasePart->Reset();
       
   151 
       
   152     delete iAppId;
       
   153     iAppId = NULL;
       
   154 
       
   155     iServiceAddressMatchMode = EPEngMMExact;
       
   156     iUserIdMatchMode = EPEngMMExact;
       
   157     iAppIdMatchMode = EPEngMMExact;
       
   158     }
       
   159 
       
   160 
       
   161 // Destructor
       
   162 CPEngNWSessionSlotID2Imp::~CPEngNWSessionSlotID2Imp()
       
   163     {
       
   164     delete iBasePart;
       
   165     delete iAppId;
       
   166     }
       
   167 
       
   168 
       
   169 
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // Symbian OS constructor.
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CPEngNWSessionSlotID2Imp::ConstructL()
       
   176     {
       
   177     iBasePart = CPEngSessionSlotId::NewL();
       
   178     }
       
   179 
       
   180 
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CPEngNWSessionSlotID2Imp::CPEngNWSessionSlotID2Imp
       
   184 // C++ default constructor can NOT contain any code, that
       
   185 // might leave.
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 CPEngNWSessionSlotID2Imp::CPEngNWSessionSlotID2Imp()
       
   189         : iServiceAddressMatchMode( EPEngMMExact ),
       
   190         iUserIdMatchMode( EPEngMMExact ),
       
   191         iAppIdMatchMode( EPEngMMExact )
       
   192     {
       
   193     }
       
   194 
       
   195 
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CPEngNWSessionSlotID2Imp::SetServiceAddressL()
       
   199 // Mutator
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CPEngNWSessionSlotID2Imp::SetServiceAddressL( const TDesC& aAddress,
       
   203                                                    TPEngNWSSIDMatchMode aMatchMode )
       
   204     {
       
   205     iBasePart->SetServiceAddressL( ValueForMatchMode( aAddress, aMatchMode ) );
       
   206     iServiceAddressMatchMode = aMatchMode;
       
   207     }
       
   208 
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CPEngNWSessionSlotID2Imp::SetUserIdL()
       
   212 // Mutator
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CPEngNWSessionSlotID2Imp::SetUserIdL( const TDesC& aUserId,
       
   216                                            TPEngNWSSIDMatchMode aMatchMode )
       
   217     {
       
   218     iBasePart->SetUserIdL( ValueForMatchMode( aUserId, aMatchMode ) );
       
   219     iUserIdMatchMode = aMatchMode;
       
   220     }
       
   221 
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CPEngNWSessionSlotID2Imp::SetAppIdL()
       
   225 // Mutator
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 void CPEngNWSessionSlotID2Imp::SetAppIdL( const TDesC& aAppId,
       
   229                                           TPEngNWSSIDMatchMode aMatchMode )
       
   230     {
       
   231     HBufC* tmpBuf = ValueForMatchMode( aAppId, aMatchMode ).AllocL();
       
   232     delete iAppId;
       
   233     iAppId = tmpBuf;
       
   234     iAppIdMatchMode = aMatchMode;
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CPEngNWSessionSlotID2Imp::SetAllL()
       
   239 // Mutator
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 void CPEngNWSessionSlotID2Imp::SetAllL( const CPEngSessionSlotId& aBasePart,
       
   243                                         const TDesC& aAppId )
       
   244     {
       
   245     SetServiceAddressL( aBasePart.ServiceAddress(), EPEngMMExact );
       
   246     SetUserIdL( aBasePart.UserId(), EPEngMMExact );
       
   247     SetAppIdL( aAppId, EPEngMMExact );
       
   248     }
       
   249 
       
   250 
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CPEngNWSessionSlotID2Imp::ServiceAddress()
       
   254 // Accessor
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 TPtrC CPEngNWSessionSlotID2Imp::ServiceAddress() const
       
   258     {
       
   259     return iBasePart->ServiceAddress();
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CPEngNWSessionSlotID2Imp::UserId()
       
   264 // Accessor
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 TPtrC CPEngNWSessionSlotID2Imp::UserId() const
       
   268     {
       
   269     return iBasePart->UserId();
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CPEngNWSessionSlotID2Imp::AppId()
       
   274 // Accessor
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 TPtrC CPEngNWSessionSlotID2Imp::AppId() const
       
   278     {
       
   279     if ( iAppId )
       
   280         {
       
   281         return *iAppId;
       
   282         }
       
   283 
       
   284     return KNullDesC();
       
   285     }
       
   286 
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CPEngNWSessionSlotID2Imp::BasePart()
       
   290 // Accessor
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 const CPEngSessionSlotId& CPEngNWSessionSlotID2Imp::BasePart() const
       
   294     {
       
   295     return *iBasePart;
       
   296     }
       
   297 
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CPEngNWSessionSlotID2Imp::IsServiceAddressWild()
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 TBool CPEngNWSessionSlotID2Imp::IsServiceAddressWild() const
       
   304     {
       
   305     return ( iServiceAddressMatchMode != EPEngMMExact );
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CPEngNWSessionSlotID2Imp::IsUserIdWild()
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 TBool CPEngNWSessionSlotID2Imp::IsUserIdWild() const
       
   313     {
       
   314     return ( iUserIdMatchMode != EPEngMMExact );
       
   315     }
       
   316 
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // CPEngNWSessionSlotID2Imp::IsAppIdWild()
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 TBool CPEngNWSessionSlotID2Imp::IsAppIdWild() const
       
   323     {
       
   324     return ( iAppIdMatchMode != EPEngMMExact );
       
   325     }
       
   326 
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CPEngNWSessionSlotID2Imp::IsWild()
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 TBool CPEngNWSessionSlotID2Imp::IsWild() const
       
   333     {
       
   334     return ( IsServiceAddressWild() || IsUserIdWild() || IsAppIdWild() );
       
   335     }
       
   336 
       
   337 
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 // CPEngNWSessionSlotID2Imp::IsFullyDefined()
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 TBool CPEngNWSessionSlotID2Imp::IsFullyDefined() const
       
   344     {
       
   345     if ( IsWild() )
       
   346         {
       
   347         return EFalse;
       
   348         }
       
   349 
       
   350 
       
   351     if ( ServiceAddress().Length() == 0 )
       
   352         {
       
   353         return EFalse;
       
   354         }
       
   355 
       
   356 
       
   357     if ( UserId().Length() == 0 )
       
   358         {
       
   359         return EFalse;
       
   360         }
       
   361 
       
   362 
       
   363     if ( AppId().Length() == 0 )
       
   364         {
       
   365         return EFalse;
       
   366         }
       
   367 
       
   368 
       
   369     return ETrue;
       
   370     }
       
   371 
       
   372 
       
   373 
       
   374 
       
   375 
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CPEngNWSessionSlotID2Imp::MatchFullId()
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 TInt CPEngNWSessionSlotID2Imp::MatchFullId( const CPEngNWSessionSlotID2Imp& aIdToMatch ) const
       
   382     {
       
   383     if ( MatchBasePart( aIdToMatch ) != KErrNone )
       
   384         {
       
   385         return KErrNotFound;
       
   386         }
       
   387 
       
   388     if ( MatchAppIdPart( aIdToMatch ) != KErrNone )
       
   389         {
       
   390         return KErrNotFound;
       
   391         }
       
   392 
       
   393     return KErrNone;
       
   394     }
       
   395 
       
   396 
       
   397 
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CPEngNWSessionSlotID2Imp::MatchBasePart()
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 TInt CPEngNWSessionSlotID2Imp::MatchBasePart(
       
   404     const CPEngNWSessionSlotID2Imp& aIdToMatch ) const
       
   405     {
       
   406     //In case of full ID container, the wild definitions can be
       
   407     //in either self object or in parameter one
       
   408     //==> must be matched both ways
       
   409 
       
   410     if ( MatchBasePart( aIdToMatch.BasePart() ) == KErrNone )
       
   411         {
       
   412         return KErrNone;
       
   413         }
       
   414 
       
   415     if ( aIdToMatch.MatchBasePart( BasePart() ) == KErrNone )
       
   416         {
       
   417         return KErrNone;
       
   418         }
       
   419 
       
   420     return KErrNotFound;
       
   421     }
       
   422 
       
   423 
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // CPEngNWSessionSlotID2Imp::MatchBasePart()
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 TInt CPEngNWSessionSlotID2Imp::MatchBasePart(
       
   430     const CPEngSessionSlotId& aBasePartToMatch ) const
       
   431     {
       
   432     //Both base part fragments must match
       
   433 
       
   434     //Check first serviceAddress
       
   435     TBool serviceAddressMatch = EFalse;
       
   436     if ( IsServiceAddressWild() )
       
   437         {
       
   438         serviceAddressMatch = ETrue;
       
   439         }
       
   440 
       
   441     else if ( ServiceAddress().Compare( aBasePartToMatch.ServiceAddress() )
       
   442               == KErrNone )
       
   443         {
       
   444         serviceAddressMatch = ETrue;
       
   445         }
       
   446 
       
   447 
       
   448     //And then user ID
       
   449     TBool userIdMatch = EFalse;
       
   450     if ( IsUserIdWild() )
       
   451         {
       
   452         userIdMatch = ETrue;
       
   453         }
       
   454 
       
   455     else if ( UserId().Compare( aBasePartToMatch.UserId() ) == KErrNone )
       
   456         {
       
   457         userIdMatch = ETrue;
       
   458         }
       
   459 
       
   460 
       
   461     if ( serviceAddressMatch && userIdMatch )
       
   462         {
       
   463         return KErrNone;
       
   464         }
       
   465     return KErrNotFound;
       
   466     }
       
   467 
       
   468 
       
   469 // -----------------------------------------------------------------------------
       
   470 // CPEngNWSessionSlotID2Imp::MatchAppIdPart()
       
   471 // -----------------------------------------------------------------------------
       
   472 //
       
   473 TInt CPEngNWSessionSlotID2Imp::MatchAppIdPart(
       
   474     const CPEngNWSessionSlotID2Imp& aIdToMatch ) const
       
   475     {
       
   476     //In case of full ID container, the wild definitions can be
       
   477     //in either self object or in parameter one
       
   478     //==> must be matched both ways
       
   479     if ( MatchAppIdPart( aIdToMatch.AppId() ) == KErrNone )
       
   480         {
       
   481         return KErrNone;
       
   482         }
       
   483 
       
   484     if ( aIdToMatch.MatchAppIdPart( AppId() ) == KErrNone )
       
   485         {
       
   486         return KErrNone;
       
   487         }
       
   488 
       
   489     return KErrNotFound;
       
   490     }
       
   491 
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CPEngNWSessionSlotID2Imp::MatchAppIdPart()
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 TInt CPEngNWSessionSlotID2Imp::MatchAppIdPart( const TDesC& aAppId ) const
       
   498     {
       
   499     if ( IsAppIdWild() )
       
   500         {
       
   501         return KErrNone;
       
   502         }
       
   503 
       
   504     if ( AppId().Compare( aAppId ) == KErrNone )
       
   505         {
       
   506         return KErrNone;
       
   507         }
       
   508 
       
   509     return KErrNotFound;
       
   510     }
       
   511 
       
   512 
       
   513 
       
   514 
       
   515 // -----------------------------------------------------------------------------
       
   516 // CPEngNWSessionSlotID2Imp::PackFullLC()
       
   517 // -----------------------------------------------------------------------------
       
   518 //
       
   519 HBufC8* CPEngNWSessionSlotID2Imp::PackFullLC() const
       
   520     {
       
   521     TInt size = 6 * 4; //6 static TInts
       
   522     //   - Version
       
   523     //   - 1 x buffer length
       
   524     //   - 3 x matchMode
       
   525     //   - Extension length
       
   526 
       
   527     size += iBasePart->Size();
       
   528     size += BufferExternalizeSizeInBytes( iAppId );
       
   529 
       
   530     HBufC8* packBuffer = HBufC8::NewLC( size );
       
   531     TPtr8 pack( packBuffer->Des() );
       
   532 
       
   533     RDesWriteStream ws;
       
   534     ws.Open( pack );                // CSI: 65 #
       
   535     CleanupClosePushL( ws );
       
   536 
       
   537     ExternalizeL( ws );
       
   538 
       
   539     ws.CommitL();
       
   540     CleanupStack::PopAndDestroy(); //ws
       
   541 
       
   542 
       
   543     packBuffer = packBuffer->ReAllocL( packBuffer->Length() );
       
   544     CleanupStack::Pop();
       
   545     CleanupStack::PushL( packBuffer ); //Due realloc
       
   546 
       
   547     return packBuffer;
       
   548     }
       
   549 
       
   550 
       
   551 
       
   552 // -----------------------------------------------------------------------------
       
   553 // CPEngNWSessionSlotID2Imp::UnPackFullL()
       
   554 // -----------------------------------------------------------------------------
       
   555 //
       
   556 void CPEngNWSessionSlotID2Imp::UnPackFullL( const TDesC8& aPack )
       
   557     {
       
   558     RDesReadStream rs;
       
   559     rs.Open( aPack );               // CSI: 65 #
       
   560     CleanupClosePushL( rs );
       
   561 
       
   562     InternalizeL( rs );
       
   563 
       
   564     CleanupStack::PopAndDestroy(); //rs
       
   565     }
       
   566 
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CPEngNWSessionSlotID2Imp::ExternalizeL()
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 void CPEngNWSessionSlotID2Imp::ExternalizeL( RWriteStream& aStream ) const
       
   573     {
       
   574     aStream.WriteInt32L( 0 );   //Version, currently first
       
   575 
       
   576     iBasePart->ExternalizeL( aStream );
       
   577     aStream.WriteInt32L( iServiceAddressMatchMode );
       
   578     aStream.WriteInt32L( iUserIdMatchMode );
       
   579 
       
   580     ExternalizeBufferL( iAppId, aStream );
       
   581     aStream.WriteInt32L( iAppIdMatchMode );
       
   582 
       
   583     aStream.WriteInt32L( 0 ); //Extension length for future, currently 0
       
   584     }
       
   585 
       
   586 
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CPEngNWSessionSlotID2Imp::InternalizeL()
       
   590 // -----------------------------------------------------------------------------
       
   591 //
       
   592 void CPEngNWSessionSlotID2Imp::InternalizeL( RReadStream& aStream )
       
   593     {
       
   594     aStream.ReadInt32L(); //Stream version
       
   595 
       
   596     iBasePart->InternalizeL( aStream );
       
   597     iServiceAddressMatchMode = aStream.ReadInt32L();
       
   598     iUserIdMatchMode = aStream.ReadInt32L();
       
   599 
       
   600 
       
   601     HBufC* tmpBuf = InternalizeBufferL( aStream );
       
   602     delete iAppId;
       
   603     iAppId = tmpBuf;
       
   604     iAppIdMatchMode = aStream.ReadInt32L();
       
   605 
       
   606     TInt extensionLength = aStream.ReadInt32L();
       
   607     if ( extensionLength > 0 )
       
   608         {
       
   609         //skip the extension data
       
   610         aStream.ReadL( extensionLength );
       
   611         }
       
   612     }
       
   613 
       
   614 
       
   615 // End of File
       
   616 
       
   617