commsfwsupport/commselements/NetMeta/inc/MetaData.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 /**
       
     2 * Copyright (c) 2004-2009 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @publishedPartner
       
    23  @released
       
    24 */
       
    25 
       
    26 #if (!defined METADATA_H)
       
    27 #define METADATA_H
       
    28 
       
    29 #include <e32base.h>
       
    30 #include <e32std.h>
       
    31 #include <elements/cftransportmacro.h>
       
    32 #include <elements/h_tdeallocator.h>
       
    33 
       
    34 /**
       
    35 Macro used to declare virtual functions from MMetaData interface and the virtual data table
       
    36 */
       
    37 #define TYPEID_TABLE \
       
    38  /** @internalComponent */ \
       
    39  static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
       
    40  /** @internalComponent */ \
       
    41  static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
       
    42  /** @internalComponent */ \
       
    43  static const Meta::SVDataTableEntry iVDataTable[];
       
    44 
       
    45 #define EXPORT_TYPEID_TABLE \
       
    46  /** @internalComponent */ \
       
    47  static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
       
    48  /** @internalComponent */ \
       
    49  IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
       
    50  /** @internalComponent */ \
       
    51  static const Meta::SVDataTableEntry iVDataTable[];
       
    52 
       
    53 #define DATA_VTABLE \
       
    54  /** @internalComponent */ \
       
    55  static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
       
    56  /** @internalComponent */ \
       
    57  virtual Meta::SVDataTableEntry const* GetVDataTable() const;	\
       
    58  /** @internalComponent */ \
       
    59  virtual TUint8* GetAttribPtr(const TInt aOffset) const;	\
       
    60  /** @internalComponent */ \
       
    61  static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
       
    62  /** @internalComponent */ \
       
    63  static const Meta::SVDataTableEntry iVDataTable[];
       
    64 
       
    65 #define EXPORT_DATA_VTABLE \
       
    66  /** @internalComponent */ \
       
    67  static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
       
    68  /** @internalComponent */ \
       
    69  virtual Meta::SVDataTableEntry const* GetVDataTable() const;	\
       
    70  /** @internalComponent */ \
       
    71  virtual TUint8* GetAttribPtr(const TInt aOffset) const;	\
       
    72  /** @internalComponent */ \
       
    73  IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
       
    74  /** @internalComponent */ \
       
    75  static const Meta::SVDataTableEntry iVDataTable[];
       
    76 
       
    77 #define EXPORT_DATA_VTABLE_AND_FN \
       
    78  /** @internalComponent */ \
       
    79  static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
       
    80  /** @internalComponent */ \
       
    81  IMPORT_C virtual Meta::SVDataTableEntry const* GetVDataTable() const;	\
       
    82  /** @internalComponent */ \
       
    83  IMPORT_C virtual TUint8* GetAttribPtr(const TInt aOffset) const;	\
       
    84  /** @internalComponent */ \
       
    85  IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
       
    86  /** @internalComponent */ \
       
    87  static const Meta::SVDataTableEntry iVDataTable[];
       
    88 
       
    89 /**
       
    90 Macros used to implement virtual functions from MMetaData interface and construct the v data table
       
    91 */
       
    92 #define START_ATTRIBUTE_TABLE( thisMetaClass, uid, typeId ) \
       
    93  /** @internalComponent */ \
       
    94  Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; };	\
       
    95  /** @internalComponent */ \
       
    96  TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; };	\
       
    97  /** @internalComponent */ \
       
    98  const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
       
    99  /** @internalComponent */ \
       
   100  const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
       
   101  { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
       
   102 
       
   103 #define EXPORT_START_ATTRIBUTE_TABLE( thisMetaClass, uid, typeId ) \
       
   104  /** @internalComponent */ \
       
   105  Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; };	\
       
   106  /** @internalComponent */ \
       
   107  TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; };	\
       
   108  /** @internalComponent */ \
       
   109  EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
       
   110  /** @internalComponent */ \
       
   111  const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
       
   112  { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
       
   113 
       
   114 #define EXPORT_START_ATTRIBUTE_TABLE_AND_FN( thisMetaClass, uid, typeId ) \
       
   115  /** @internalComponent */ \
       
   116  EXPORT_C Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; };	\
       
   117  /** @internalComponent */ \
       
   118  EXPORT_C TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; };	\
       
   119  /** @internalComponent */ \
       
   120  EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
       
   121  /** @internalComponent */ \
       
   122  const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
       
   123  { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
       
   124 
       
   125 #define REGISTER_ATTRIBUTE( thisMetaClass, var, metaType ) \
       
   126  { _FOFF( thisMetaClass, var ), Meta::metaType::NewL },
       
   127 
       
   128 #define END_ATTRIBUTE_TABLE() \
       
   129  { 0, NULL }};
       
   130 
       
   131 #define END_ATTRIBUTE_TABLE_BASE( baseMetaClass, baseId ) \
       
   132  { (TInt)((TAny*)(baseMetaClass::GetVDataTableStatic)), NULL }};
       
   133 
       
   134 #define REGISTER_TYPEID( thisMetaClass, uid, typeId ) \
       
   135  /** @internalComponent */ \
       
   136  const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
       
   137  /** @internalComponent */ \
       
   138  const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
       
   139  { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) }, \
       
   140  { 0, NULL }};
       
   141 
       
   142 #define EXPORT_REGISTER_TYPEID( thisMetaClass, uid, typeId ) \
       
   143  /** @internalComponent */ \
       
   144  EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
       
   145  /** @internalComponent */ \
       
   146  const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
       
   147  { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) }, \
       
   148  { 0, NULL }};
       
   149 
       
   150 #define EXPORT_START_ATTRIBUTE_TABLE_NO_FN( thisMetaClass, uid, typeId ) \
       
   151  /** @internalComponent */ \
       
   152  EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
       
   153  /** @internalComponent */ \
       
   154  const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
       
   155  { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
       
   156 
       
   157 
       
   158 namespace Meta
       
   159 {
       
   160 //Panics
       
   161 _LIT (MetaPanic,"MetaDataPanic");
       
   162 const TInt EBadCast = 1;
       
   163 
       
   164 struct SMetaData;
       
   165 typedef Elements::TDeAllocator<const SMetaData> TMetaDataDeAllocator;
       
   166 
       
   167 class MMetaType;
       
   168 typedef MMetaType* (*TMetaTypeNewL)(const TAny*, const TAny*);
       
   169 
       
   170 struct SVDataTableEntry
       
   171 /**
       
   172 
       
   173 Single entry of a virtual data table
       
   174 
       
   175 @publishedPartner
       
   176 @released since v9.0 */
       
   177     {
       
   178     TInt iOffset;
       
   179     TMetaTypeNewL iMetaNewL;
       
   180     };
       
   181 
       
   182 const TInt32 KNetMetaTypeAny = 0;
       
   183 
       
   184 struct STypeId
       
   185 /**
       
   186 
       
   187 Used to uniquely identify the type of a (meta).object.
       
   188 
       
   189 */
       
   190 	{
       
   191 	TUid iUid;
       
   192 	TInt32 iType;
       
   193 	inline TBool operator==(const STypeId& obj) const { return iUid==obj.iUid && iType==obj.iType; };
       
   194 	inline TBool operator!=(const STypeId& obj) const { return iUid!=obj.iUid || iType!=obj.iType; };
       
   195 	static inline STypeId CreateSTypeId();
       
   196 	static inline STypeId CreateSTypeId(TUint32 aUid, TUint32 aTypeId);
       
   197 	IMPORT_C static STypeId CreateSTypeId(TPtrC8& aStore);
       
   198 	IMPORT_C TInt Check( TPtrC8& aDes ) const;
       
   199 	};
       
   200 
       
   201 class MMetaData
       
   202 /**
       
   203 
       
   204 MetaData interface
       
   205 
       
   206 @publishedPartner
       
   207 @released since v9.0 */
       
   208 	{
       
   209 public:
       
   210 	virtual SVDataTableEntry const* GetVDataTable() const = 0;
       
   211 	virtual TUint8* GetAttribPtr(const TInt aOffset) const = 0;
       
   212 	};
       
   213 
       
   214 struct SMetaData : public MMetaData
       
   215 /**
       
   216 
       
   217 Meta object's base type
       
   218 
       
   219 Partially implements the MMetaData interface's pure virtual functions
       
   220 
       
   221 */
       
   222    {
       
   223 public:
       
   224 	IMPORT_C virtual ~SMetaData();
       
   225 
       
   226 	//Checks the exact type for match and advances the pointer if matched
       
   227 	IMPORT_C TInt Check( TPtrC8& aDes ) const;
       
   228 	//Checks the exact type and base types for match and advances the pointer if matched
       
   229 	IMPORT_C TInt CheckTypeOf( TPtrC8& aDes ) const;
       
   230 	IMPORT_C STypeId GetTypeId() const;
       
   231 	IMPORT_C TInt IsTypeOf( const STypeId& aTypeId ) const;
       
   232 
       
   233 	IMPORT_C void Copy(const SMetaData& aSource);
       
   234 	IMPORT_C TInt Store(TDes8& aDes) const;
       
   235 	IMPORT_C TInt Load(TPtrC8& aDes);
       
   236 
       
   237 	IMPORT_C TInt Length() const;
       
   238 
       
   239 protected:
       
   240 	IMPORT_C explicit SMetaData();
       
   241    };
       
   242 
       
   243 struct SMetaDataECom : public SMetaData
       
   244 /**
       
   245 Meta object based on ECom factory base type
       
   246 Implements static LoadL(TPtrC8& aDes) required by templated
       
   247 */
       
   248 	{
       
   249 public:
       
   250 	IMPORT_C static SMetaDataECom* LoadL(TPtrC8& aDes);
       
   251     IMPORT_C static SMetaDataECom* NewInstanceL(const STypeId& aTypeId);
       
   252 	IMPORT_C virtual ~SMetaDataECom();
       
   253 
       
   254 protected:
       
   255     IMPORT_C explicit SMetaDataECom();
       
   256 
       
   257 private:
       
   258 	TUid iDestroyUid;
       
   259 	};
       
   260 
       
   261 } //namespace Meta
       
   262 
       
   263 
       
   264 template <class SMETADATATYPE>
       
   265 SMETADATATYPE& smetadata_cast(Meta::SMetaData& aObject)
       
   266     {
       
   267     __ASSERT_DEBUG(aObject.IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)),User::Panic(Meta::MetaPanic, Meta::EBadCast));
       
   268     return static_cast<SMETADATATYPE&>(aObject);
       
   269     }
       
   270 
       
   271 template <class SMETADATATYPE>
       
   272 const SMETADATATYPE& smetadata_cast(const Meta::SMetaData& aObject)
       
   273     {
       
   274     __ASSERT_DEBUG(aObject.IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)),User::Panic(Meta::MetaPanic, Meta::EBadCast));
       
   275     return static_cast<const SMETADATATYPE&>(aObject);
       
   276     }
       
   277 
       
   278 template <class SMETADATATYPE>
       
   279 SMETADATATYPE* smetadata_cast(Meta::SMetaData* aObject)
       
   280     {
       
   281     __ASSERT_DEBUG(aObject,User::Panic(Meta::MetaPanic, Meta::EBadCast));
       
   282     return aObject->IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)) ? static_cast<SMETADATATYPE*>(aObject) : NULL;
       
   283     }
       
   284 
       
   285 template <class SMETADATATYPE>
       
   286 const SMETADATATYPE* smetadata_cast(const Meta::SMetaData* aObject)
       
   287     {
       
   288     __ASSERT_DEBUG(aObject,User::Panic(Meta::MetaPanic, Meta::EBadCast));
       
   289     return aObject->IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)) ? static_cast<const SMETADATATYPE*>(aObject) : NULL;
       
   290     }
       
   291 
       
   292 #include <elements/metadata.inl>
       
   293 
       
   294 #endif //METADATA_H
       
   295 
       
   296