ximpfw/presence/srcpresencedatamodel/presenceapidataobjfactory.inl
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     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:  Inline methods for codec to pack and unpack data objects.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 
       
    21 #include "presencetypehelpers.h"
       
    22 #include "presenceobjectfactory.h"
       
    23 #include "ximpapidataobjbase.h"
       
    24 //#include "ximpidentityimp.h"
       
    25 #include "presentitygroupmemberinfoimp.h"
       
    26 #include "presentitygroupinfoimp.h"
       
    27 //#include "ximpfeatureinfoimp.h"
       
    28 //#include "ximpcontextclientinfoimp.h"
       
    29 #include "presencegrantrequestinfoimp.h"
       
    30 #include "presencewatcherinfoimp.h"
       
    31 //#include "ximpprotocolinfoimp.h"
       
    32 //#include "ximpserviceinfoimp.h"
       
    33 //#include "ximpstatusimp.h"
       
    34 #include "presenceinfofieldimp.h"
       
    35 #include "presenceinfofieldvaluetextimp.h"
       
    36 #include "presenceinfofieldvaluebinaryimp.h"
       
    37 #include "presenceinfofieldvalueenumimp.h"
       
    38 #include "servicepresenceinfoimp.h"
       
    39 #include "devicepresenceinfoimp.h"
       
    40 
       
    41 //DATA TYPES
       
    42 
       
    43 
       
    44 // ============================ MEMBER FUNCTIONS =============================
       
    45 
       
    46 /**
       
    47  * Type definition for exact API data object constructor signature.
       
    48  */
       
    49 typedef CXIMPApiDataObjBase* (*TApiDataObjConstructor)( RReadStream& );
       
    50 
       
    51 
       
    52 
       
    53 /**
       
    54  * Structure for mapping data object interface IDs to
       
    55  * to corect API data object constructors.
       
    56  */
       
    57 struct SApiDataObjConstructorMap
       
    58     {
       
    59     //Interface id
       
    60     TInt32    iInterfaceId;
       
    61 
       
    62     //Function pointer to data object interface implementation
       
    63     TApiDataObjConstructor iConstructorPtr;
       
    64     } ;
       
    65 
       
    66 
       
    67 
       
    68 /**
       
    69  * Helper macro to initialise KApiDataObjConstructorTable members.
       
    70  *
       
    71  * Macro forces that each data object implementation class to have static
       
    72  * NewFromStreamLC() member function to instantiate the object.
       
    73  *
       
    74  * See TApiDataObjConstructor type definition for exact constructor
       
    75  * signature.
       
    76  */
       
    77 #define CONSTRUCTOR_ENTRY( TheImplementedIf, TheClass ) \
       
    78     { TheImplementedIf::KInterfaceId, TheClass::NewFromStreamLC } \
       
    79 
       
    80 /**
       
    81  * Constructor function mapping for data object interface implementations.
       
    82  *
       
    83  * When new data object types are implemented, add them here.
       
    84  */
       
    85 const SApiDataObjConstructorMap KApiDataObjConstructorTable[] =
       
    86     {
       
    87     CONSTRUCTOR_ENTRY( MPresentityGroupMemberInfo, CPresentityGroupMemberInfoImp ),
       
    88     CONSTRUCTOR_ENTRY( MPresentityGroupInfo, CPresentityGroupInfoImp ),
       
    89     CONSTRUCTOR_ENTRY( MPresenceGrantRequestInfo, CPresenceGrantRequestInfoImp ),
       
    90     CONSTRUCTOR_ENTRY( MPresenceWatcherInfo, CPresenceWatcherInfoImp ),
       
    91     CONSTRUCTOR_ENTRY( MPresenceInfoField, CPresenceInfoFieldImp ),
       
    92     CONSTRUCTOR_ENTRY( MPresenceInfoFieldValueText, CPresenceInfoFieldValueTextImp ),
       
    93     CONSTRUCTOR_ENTRY( MPresenceInfoFieldValueBinary, CPresenceInfoFieldValueBinaryImp ),
       
    94     CONSTRUCTOR_ENTRY( MPresenceInfoFieldValueEnum, CPresenceInfoFieldValueEnumImp ),
       
    95     CONSTRUCTOR_ENTRY( MDevicePresenceInfo, CDevicePresenceInfoImp ),
       
    96     CONSTRUCTOR_ENTRY( MServicePresenceInfo, CServicePresenceInfoImp )
       
    97     };
       
    98 
       
    99 
       
   100 /**
       
   101  * Count of constructor mappings.
       
   102  */
       
   103 const TInt KApiDataObjConstructorCount = sizeof( KApiDataObjConstructorTable )
       
   104                                         / sizeof( SApiDataObjConstructorMap );
       
   105 
       
   106 
       
   107 
       
   108 // ============================ HELPER FUNCTIONS =============================
       
   109 
       
   110 
       
   111 namespace {
       
   112 
       
   113     /**
       
   114      * Helper function to locate constructor function for
       
   115      * data object interface ID.
       
   116      *
       
   117      * @param aDataObjInterfaceId The data object interface ID.
       
   118      * @return Data object constructor function.
       
   119      */
       
   120     TApiDataObjConstructor ConstructorForInterface( TInt32 aDataObjInterfaceId )
       
   121     {
       
   122         //Locate correct constructor
       
   123         for( TInt ix = 0; ix < KApiDataObjConstructorCount; ix++ )
       
   124         {
       
   125             const SApiDataObjConstructorMap map = KApiDataObjConstructorTable[ ix ];
       
   126             if( map.iInterfaceId == aDataObjInterfaceId )
       
   127             {
       
   128                 return map.iConstructorPtr;
       
   129             }
       
   130         }
       
   131 
       
   132 
       
   133         //If assertion below fails, check that data object implementation
       
   134         //class implementing requested data object interface (aDataObjInterfaceId)
       
   135         //is registered to KApiDataObjConstructorTable
       
   136         __ASSERT_DEBUG( EFalse,
       
   137                 User::Panic( _L("PresenceObjectFactory"), KErrUnknown ) );
       
   138 
       
   139         return NULL;
       
   140     }
       
   141 
       
   142     /**
       
   143      * Helper function to instantiate new data object object
       
   144      * of requested type and construct it from the stream.
       
   145      *
       
   146      * @param aDataObjInterfaceId
       
   147      * @return Data object constructor function.
       
   148      */
       
   149     CXIMPApiDataObjBase* NewDataObjectFromStreamLC( TInt32 aDataObjInterfaceId,
       
   150             RReadStream& aStream )
       
   151     {
       
   152         TApiDataObjConstructor newFromStreamLC = NULL;
       
   153 
       
   154         //Locate correct constructor for interface ID
       
   155         newFromStreamLC = ConstructorForInterface( aDataObjInterfaceId );
       
   156 
       
   157         //Instantiate the object
       
   158         CXIMPApiDataObjBase* dataObject = newFromStreamLC( aStream );
       
   159 
       
   160         return dataObject;
       
   161     }
       
   162 
       
   163 } // namespace
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // PresenceApiDataObjFactory::InternalizeL
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 template< class INFOIMP >
       
   170 inline void CPresenceApiDataObjFactory::InternalizeL( 
       
   171         RReadStream& aStream,
       
   172         RPointerArray<INFOIMP>& aArray )
       
   173     {
       
   174     TInt32 arrLen = aStream.ReadInt32L();
       
   175 
       
   176     for ( TInt i = 0; i < arrLen; i++ )
       
   177         {
       
   178         TInt paramType = aStream.ReadInt32L();
       
   179         INFOIMP* infoObj = ( INFOIMP* ) NewDataObjectFromStreamLC( paramType, aStream );
       
   180         aArray.AppendL( infoObj );
       
   181         CleanupStack::Pop( infoObj );
       
   182         }
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // PresenceApiDataObjFactory::ExternalizeL
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 template <class INFOIMP>
       
   190 inline void CPresenceApiDataObjFactory::ExternalizeL( 
       
   191         RWriteStream& aWs,
       
   192         const RPointerArray<INFOIMP>& aArray )
       
   193     {
       
   194     aWs.WriteInt32L( aArray.Count() ); // array length
       
   195 
       
   196     for ( TInt i = 0; i < aArray.Count(); i++ )
       
   197         {
       
   198         INFOIMP* infoField = aArray[ i ];
       
   199 
       
   200         // write the type
       
   201         aWs.WriteInt32L( infoField->Base().GetInterfaceId() );
       
   202 
       
   203         // write the actual object
       
   204         infoField->ExternalizeL( aWs );
       
   205         }
       
   206 
       
   207     aWs.CommitL();
       
   208     }
       
   209