mtpfws/mtpfw/src/cmtpserviceinfo.cpp
changeset 0 d0791faffa3f
child 47 63cf70d3ecd8
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17 @file
       
    18 @internalComponent
       
    19 */ 
       
    20 
       
    21 #include "mtpservicecommon.h"
       
    22 #include "cmtpserviceinfo.h"
       
    23 
       
    24 
       
    25 // Class constants.
       
    26 
       
    27 __FLOG_STMT(_LIT8(KComponent,"ServiceInfo");)
       
    28 
       
    29 
       
    30 TPKeyPair::TPKeyPair( const TMTPTypeGuid& aNamespace, const TUint aID ):
       
    31     iNamespace( aNamespace ),
       
    32     iPKeyId(aID)
       
    33     {
       
    34     }
       
    35 
       
    36 
       
    37 CServiceElementBase::CServiceElementBase(const TMTPTypeGuid& aGUID, HBufC* aName):
       
    38     iCode( KInvliadU16DataCode ),
       
    39     iGUID( aGUID ),
       
    40     iName( aName )
       
    41     {
       
    42     }
       
    43 
       
    44 CServiceElementBase::~CServiceElementBase()
       
    45     {
       
    46     delete iName;
       
    47     }
       
    48 
       
    49 EXPORT_C TBool CServiceElementBase::IsUsed()
       
    50     {
       
    51     return ( KInvliadU16DataCode != iCode );
       
    52     }
       
    53 
       
    54 EXPORT_C TUint CServiceElementBase::Code() const
       
    55     {
       
    56     return iCode;
       
    57     }
       
    58 EXPORT_C const TDesC& CServiceElementBase::Name() const
       
    59     {
       
    60     return *iName;
       
    61     }
       
    62 EXPORT_C const TMTPTypeGuid& CServiceElementBase::GUID() const
       
    63     {
       
    64     return iGUID;
       
    65     }
       
    66 
       
    67 EXPORT_C void CServiceElementBase::SetCode( const TUint aCode )
       
    68     {
       
    69     iCode = aCode;
       
    70     }
       
    71 
       
    72 TInt CServiceElementBase::Compare( const CServiceElementBase& aR ) const
       
    73     {
       
    74     return iGUID.Compare( aR.GUID() );
       
    75     }
       
    76 
       
    77 CServiceProperty::CServiceProperty( const TMTPTypeGuid& aGUID, const TUint aPkeyID, HBufC* aName, const TUint aDataType, const TUint aGetSet, const TUint aFormFlag):
       
    78     CServiceElementBase( aGUID, aName ),
       
    79     iPKeyId( aPkeyID ),
       
    80     iDataType( aDataType ),
       
    81     iGetSet( aGetSet ),
       
    82     iFormFlag( aFormFlag )
       
    83     {
       
    84     }
       
    85 
       
    86 CServiceProperty* CServiceProperty::NewLC(const TMTPTypeGuid& aGUID, const TUint aPkeyID, HBufC* aName, const TUint aDataType, const TUint aGetSet, const TUint aFormFlag)
       
    87     {
       
    88     CServiceProperty* self = new (ELeave) CServiceProperty(aGUID, aPkeyID, aName, aDataType, aGetSet, aFormFlag);
       
    89     CleanupStack::PushL(self);
       
    90     self->ConstructL(); 
       
    91     return self;
       
    92     }
       
    93 
       
    94 void CServiceProperty::ConstructL()
       
    95     {
       
    96     }
       
    97 
       
    98 EXPORT_C const TMTPTypeGuid& CServiceProperty::Namespace() const
       
    99     {
       
   100     return GUID();
       
   101     }
       
   102 EXPORT_C TUint CServiceProperty::PKeyID() const
       
   103     {
       
   104     return iPKeyId;
       
   105     }
       
   106 
       
   107 EXPORT_C TUint CServiceProperty::DataType() const
       
   108     {
       
   109     return iDataType;
       
   110     }
       
   111 EXPORT_C TUint CServiceProperty::GetSet() const
       
   112     {
       
   113     return iGetSet;
       
   114     }
       
   115 EXPORT_C TUint CServiceProperty::FormFlag() const
       
   116     {
       
   117     return iFormFlag;
       
   118     }
       
   119     
       
   120 
       
   121 
       
   122 CServiceFormat::CServiceFormat(const TMTPTypeGuid& aGUID, HBufC* aName, const TUint aBaseFormat, HBufC* aMime ):
       
   123     CServiceElementBase( aGUID, aName ),
       
   124     iFormatBase(aBaseFormat),
       
   125     iMIMEType1(aMime)
       
   126     {
       
   127     }
       
   128 
       
   129 CServiceFormat* CServiceFormat::NewLC(const TMTPTypeGuid& aGUID, HBufC* aName, const TUint aBaseFormat, HBufC* aMime )
       
   130     {
       
   131     CServiceFormat* self = new (ELeave) CServiceFormat( aGUID, aName, aBaseFormat, aMime );
       
   132     CleanupStack::PushL(self);
       
   133     self->ConstructL(); 
       
   134     return self;
       
   135     }
       
   136 
       
   137 void CServiceFormat::ConstructL()
       
   138     {
       
   139     }
       
   140 
       
   141 CServiceFormat::~CServiceFormat()
       
   142 	{
       
   143 	delete iMIMEType1;
       
   144 	}
       
   145 
       
   146 EXPORT_C TUint CServiceFormat::FormatBase() const
       
   147     {
       
   148     return iFormatBase;
       
   149     }
       
   150 EXPORT_C const TDesC& CServiceFormat::MIMEType1() const
       
   151     {
       
   152     return *iMIMEType1;
       
   153     }
       
   154 
       
   155 CServiceMethod::CServiceMethod(const TMTPTypeGuid& aGUID, HBufC* aName, const TUint aAssFormat):
       
   156     CServiceElementBase( aGUID, aName ),
       
   157     iObjAssociateFormatCode(aAssFormat)
       
   158     {
       
   159     }
       
   160 
       
   161 CServiceMethod* CServiceMethod::NewLC(const TMTPTypeGuid& aGUID, HBufC* aName, const TUint aAssFormat)
       
   162     {
       
   163     CServiceMethod* self = new (ELeave) CServiceMethod( aGUID,  aName, aAssFormat );
       
   164     CleanupStack::PushL(self);
       
   165     self->ConstructL(); 
       
   166     return self;
       
   167     }
       
   168 
       
   169 void CServiceMethod::ConstructL()
       
   170     {
       
   171     }
       
   172 
       
   173 EXPORT_C TUint CServiceMethod::ObjAssociateFormatCode() const
       
   174     {
       
   175     return iObjAssociateFormatCode;
       
   176     }
       
   177 
       
   178 
       
   179 CServiceEvent::CServiceEvent( const TUint aCode, const TMTPTypeGuid& aGUID, HBufC* aName):
       
   180     CServiceElementBase( aGUID, aName )
       
   181     {
       
   182     SetCode(aCode);
       
   183     }
       
   184 CServiceEvent* CServiceEvent:: NewLC(const TUint aCode, const TMTPTypeGuid& aGUID, HBufC* aName)
       
   185     {
       
   186     CServiceEvent* self = new (ELeave) CServiceEvent( aCode, aGUID, aName );
       
   187     CleanupStack::PushL(self);
       
   188     self->ConstructL(); 
       
   189     return self;
       
   190     }
       
   191 
       
   192 void CServiceEvent::ConstructL()
       
   193     {
       
   194     }
       
   195 
       
   196 
       
   197 CMTPServiceInfo* CMTPServiceInfo::NewLC()
       
   198     {
       
   199     CMTPServiceInfo* self = new (ELeave) CMTPServiceInfo();
       
   200     CleanupStack::PushL(self);
       
   201     self->ConstructL(); 
       
   202     return self;
       
   203     }
       
   204 
       
   205 CMTPServiceInfo::~CMTPServiceInfo()
       
   206     {
       
   207     __FLOG(_L8("CServiceInfo::~CserviceInfo() - Entry"));
       
   208     
       
   209     delete iServiceName;
       
   210     
       
   211     iUsedServiceGUIDs.Close();
       
   212     iServiceProperties.ResetAndDestroy();
       
   213     iServiceFormats.ResetAndDestroy();
       
   214     iServiceMethods.ResetAndDestroy();
       
   215     iServiceEvents.ResetAndDestroy();
       
   216     iDataBlock.Close();
       
   217     
       
   218     __FLOG(_L8("CServiceInfo::~CserviceInfo() - Exit"));
       
   219     __FLOG_CLOSE;
       
   220     }
       
   221     
       
   222 
       
   223 CMTPServiceInfo::CMTPServiceInfo()
       
   224     {
       
   225     }
       
   226 void CMTPServiceInfo::ConstructL()
       
   227     {
       
   228     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
   229     __FLOG(_L8("CServiceInfo::ConstructL() - Entry"));
       
   230    
       
   231     
       
   232     
       
   233     __FLOG(_L8("CServiceInfo::ConstructL() - Exit"));
       
   234     }
       
   235 
       
   236 
       
   237 TInt CMTPServiceInfo::ServicePropertyOrderFromAscending( const CServiceProperty& aL, const CServiceProperty& aR)
       
   238     {
       
   239     TInt ret = aL.Compare( aR );
       
   240     if( 0 == ret )
       
   241         {
       
   242         return aL.PKeyID() - aR.PKeyID();
       
   243         }
       
   244     else
       
   245         {
       
   246         return ret;
       
   247         }
       
   248     }
       
   249 
       
   250 TInt CMTPServiceInfo::ServicePropertyOrderFromKeyAscending( const TPKeyPair* aL, const CServiceProperty& aR)
       
   251     {
       
   252     TInt ret = aL->iNamespace.Compare( aR.Namespace() );
       
   253         if( 0 == ret )
       
   254             {
       
   255             return aL->iPKeyId - aR.PKeyID();
       
   256             }
       
   257         else
       
   258             {
       
   259             return ret;
       
   260             }
       
   261     }
       
   262 
       
   263 TInt CMTPServiceInfo::ServiceElementBaseOrderFromAscending( const CServiceElementBase& aL, const CServiceElementBase& aR)
       
   264     {
       
   265     return aL.Compare( aR );
       
   266     }
       
   267 
       
   268 TInt CMTPServiceInfo::ServiceElementBaseOrderFromKeyAscending( const TMTPTypeGuid* aL, const CServiceElementBase& aR )
       
   269     {
       
   270     return aL->Compare( aR.GUID() );
       
   271     }
       
   272 
       
   273 TInt CMTPServiceInfo::ServiceFormatOrderFromAscending( const CServiceFormat& aL, const CServiceFormat& aR)
       
   274     {
       
   275     return ServiceElementBaseOrderFromAscending(aL, aR);
       
   276     }
       
   277 
       
   278 TInt CMTPServiceInfo::ServiceFormatOrderFromKeyAscending( const TMTPTypeGuid* aL, const CServiceFormat& aR )
       
   279     {
       
   280     return ServiceElementBaseOrderFromKeyAscending(aL, aR);
       
   281     }
       
   282 
       
   283 TInt CMTPServiceInfo::ServiceMethodOrderFromAscending( const CServiceMethod& aL, const CServiceMethod& aR )
       
   284     {
       
   285     return ServiceElementBaseOrderFromAscending(aL, aR);
       
   286     }
       
   287 
       
   288 TInt CMTPServiceInfo::ServiceMethodOrderFromKeyAscending( const TMTPTypeGuid* aL, const CServiceMethod& aR )
       
   289     {
       
   290     return ServiceElementBaseOrderFromKeyAscending(aL, aR);
       
   291     }
       
   292 
       
   293 TInt CMTPServiceInfo::ServiceEventOrderFromAscending( const CServiceEvent& aL, const CServiceEvent& aR )
       
   294     {
       
   295     return ServiceElementBaseOrderFromAscending(aL, aR);
       
   296     }
       
   297 
       
   298 
       
   299 void CMTPServiceInfo::SetServiceID( TUint aServiceID)
       
   300     {
       
   301     iServiceId = aServiceID;
       
   302     }
       
   303 
       
   304 void CMTPServiceInfo::SetServiceStorageID( TUint aStorageID )
       
   305     {
       
   306     iServiceStorageId = aStorageID;
       
   307     }
       
   308 
       
   309 void CMTPServiceInfo::SetPersistentGUIDL( const TMTPTypeGuid& aGUID )
       
   310     {
       
   311     MMTPType::CopyL( aGUID, iPersistentGUID);
       
   312     }
       
   313 
       
   314 void CMTPServiceInfo::SetServiceVersion( TUint aVersion )
       
   315     {
       
   316     iServiceVersion = aVersion;
       
   317     }
       
   318 
       
   319 void CMTPServiceInfo::SetServiceGUIDL( const TMTPTypeGuid& aGUID )
       
   320     {
       
   321     MMTPType::CopyL( aGUID, iServiceGUID);
       
   322     }
       
   323 
       
   324 void CMTPServiceInfo::SetServiceName( HBufC* aName )
       
   325     {
       
   326     delete iServiceName;
       
   327     iServiceName = aName;
       
   328     }
       
   329 
       
   330 void CMTPServiceInfo::SetServiceType( TUint aServiceType )
       
   331     {
       
   332     iServiceType = aServiceType;
       
   333     }
       
   334 
       
   335 void CMTPServiceInfo::SetBaseServiceID( TUint aID )
       
   336     {
       
   337     iBaseServiceId = aID;
       
   338     }
       
   339 
       
   340 void CMTPServiceInfo::AppendUserServiceL( const TMTPTypeGuid& aServiceGUID )
       
   341     {
       
   342     __FLOG(_L8("CServiceInfo::AppendUserServiceL - Entry"));
       
   343     
       
   344     iUsedServiceGUIDs.AppendL( aServiceGUID );
       
   345     
       
   346     __FLOG(_L8("CServiceInfo::AppendUserServiceL - Exit"));
       
   347     }
       
   348 
       
   349 void CMTPServiceInfo::InsertPropertyL( const CServiceProperty* aProperty )
       
   350     {
       
   351     __FLOG(_L8("CServiceInfo::InsertPropertyL - Entry"));
       
   352     
       
   353     iServiceProperties.InsertInOrderL( aProperty, TLinearOrder<CServiceProperty>(ServicePropertyOrderFromAscending) );
       
   354     
       
   355     __FLOG(_L8("CServiceInfo::InsertPropertyL - Exit"));
       
   356     }
       
   357 
       
   358 void CMTPServiceInfo::InsertFormatL( const CServiceFormat* aFormat )
       
   359     {
       
   360     __FLOG(_L8("CServiceInfo::InsertFormatL - Entry"));
       
   361     
       
   362     iServiceFormats.InsertInOrderL( aFormat, TLinearOrder<CServiceFormat>(ServiceFormatOrderFromAscending) );
       
   363     
       
   364     __FLOG(_L8("CServiceInfo::InsertFormatL - Exit"));
       
   365     }
       
   366 
       
   367 void CMTPServiceInfo::InsertMethodL( const CServiceMethod* aMethod )
       
   368     {
       
   369     __FLOG(_L8("CServiceInfo::InsertMethodL - Entry"));
       
   370     
       
   371     iServiceMethods.InsertInOrderL( aMethod , TLinearOrder<CServiceMethod>(ServiceMethodOrderFromAscending) );
       
   372     
       
   373     __FLOG(_L8("CServiceInfo::InsertMethodL - Exit"));
       
   374     }
       
   375 
       
   376 void CMTPServiceInfo::InsertEventL( const CServiceEvent* aEvent )
       
   377     {
       
   378     __FLOG(_L8("CServiceInfo::InsertMethodL - Entry"));
       
   379     
       
   380     iServiceEvents.InsertInOrderL( aEvent , TLinearOrder<CServiceEvent>(ServiceEventOrderFromAscending) );
       
   381     
       
   382     __FLOG(_L8("CServiceInfo::InsertMethodL - Exit"));
       
   383     }
       
   384   
       
   385 void CMTPServiceInfo::AppendDataGUIDL( const TMTPTypeGuid& aGUID )
       
   386     {
       
   387     __FLOG(_L8("CServiceInfo::AppendDataGUIDL - Entry"));
       
   388     
       
   389     iDataBlock.AppendL( aGUID );
       
   390     
       
   391     __FLOG(_L8("CServiceInfo::AppendDataGUIDL - Exit"));
       
   392     }
       
   393     
       
   394 EXPORT_C TUint CMTPServiceInfo::ServiceID() const
       
   395     {
       
   396     return iServiceId;
       
   397     }
       
   398 
       
   399 EXPORT_C TUint CMTPServiceInfo::ServiceStorageID() const
       
   400     {
       
   401     return iServiceStorageId;
       
   402     }
       
   403 
       
   404 EXPORT_C const TMTPTypeGuid& CMTPServiceInfo::ServicePersistentGUID() const
       
   405     {
       
   406     return iPersistentGUID;
       
   407     }
       
   408 EXPORT_C TUint CMTPServiceInfo::ServiceVersion() const
       
   409     {
       
   410     return iServiceVersion;
       
   411     }
       
   412 
       
   413 EXPORT_C const TMTPTypeGuid& CMTPServiceInfo::ServiceGUID() const
       
   414     {
       
   415     return iServiceGUID;
       
   416     }
       
   417 
       
   418 EXPORT_C const TDesC& CMTPServiceInfo::ServiceName() const
       
   419     {
       
   420     return *iServiceName;
       
   421     }
       
   422 
       
   423 EXPORT_C TUint CMTPServiceInfo::ServiceType() const
       
   424     {
       
   425     return iServiceType;
       
   426     }
       
   427 
       
   428 EXPORT_C TUint CMTPServiceInfo::BaseServiceID() const
       
   429     {
       
   430     return iBaseServiceId;
       
   431     }
       
   432 
       
   433 CServiceProperty* CMTPServiceInfo::ServiceProperty( const TMTPTypeGuid& aPKNamespace, const TUint aPKID ) const
       
   434     {
       
   435     TInt index = iServiceProperties.FindInOrder( TPKeyPair(aPKNamespace, aPKID), ServicePropertyOrderFromKeyAscending );
       
   436     if( index != KErrNotFound )
       
   437         return iServiceProperties[index];
       
   438     
       
   439     return NULL;
       
   440     }
       
   441 
       
   442 CServiceFormat* CMTPServiceInfo::ServiceFormat( const TMTPTypeGuid& aGUID ) const
       
   443     {
       
   444     TInt index = iServiceFormats.FindInOrder( aGUID, ServiceFormatOrderFromKeyAscending );
       
   445     if( index != KErrNotFound )
       
   446         return iServiceFormats[index];
       
   447     
       
   448     return NULL;
       
   449     }
       
   450 
       
   451 CServiceMethod* CMTPServiceInfo::ServiceMethod( const TMTPTypeGuid& aGUID ) const
       
   452     {
       
   453     TInt index = iServiceMethods.FindInOrder( aGUID , ServiceMethodOrderFromKeyAscending );
       
   454     if( index != KErrNotFound )
       
   455         return iServiceMethods[index];
       
   456     
       
   457     return NULL;
       
   458     }
       
   459 
       
   460 EXPORT_C const RArray<TMTPTypeGuid>& CMTPServiceInfo::UsedServiceGUIDs() const
       
   461 	{
       
   462 	return iUsedServiceGUIDs;
       
   463 	}
       
   464 
       
   465 EXPORT_C const RPointerArray<CServiceProperty>& CMTPServiceInfo::ServiceProperties() const
       
   466 	{
       
   467 	return iServiceProperties;
       
   468 	}
       
   469 
       
   470 EXPORT_C const RPointerArray<CServiceFormat>& CMTPServiceInfo::ServiceFormats() const
       
   471 	{
       
   472 	return iServiceFormats;
       
   473 	}
       
   474 
       
   475 EXPORT_C const RPointerArray<CServiceMethod>& CMTPServiceInfo::ServiceMethods() const
       
   476 	{
       
   477 	return iServiceMethods;
       
   478 	}
       
   479 
       
   480 EXPORT_C const RPointerArray<CServiceEvent>& CMTPServiceInfo::ServiceEvents() const
       
   481 	{
       
   482 	return iServiceEvents;
       
   483 	}
       
   484 
       
   485 EXPORT_C const RArray<TMTPTypeGuid>& CMTPServiceInfo::DataBlockGUIDs() const
       
   486     {
       
   487     return iDataBlock;
       
   488     }
       
   489