mtpfws/mtpfw/src/cmtpserviceconfig.cpp
changeset 0 d0791faffa3f
child 15 f85613f12947
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 "cmtpserviceconfig.h"
       
    23 
       
    24 
       
    25 // Class constants.
       
    26 __FLOG_STMT(_LIT8(KComponent,"ServiceConfigMgr");)
       
    27 _LIT(KMTPServiceCofigfile, "z:\\resource\\mtp\\services.rsc");
       
    28 
       
    29 
       
    30 
       
    31 CMTPServiceConfig::TSupportedService::TSupportedService( const TMTPTypeGuid& aGUID, const TUint aServiceType, const TUint aResID ):
       
    32     iGUID(aGUID),
       
    33     iServiceType(aServiceType),
       
    34     iResourceID(aResID)
       
    35     {
       
    36     
       
    37     }
       
    38 
       
    39 /**
       
    40 
       
    41 */
       
    42 CMTPServiceConfig* CMTPServiceConfig::NewL( RFs& aRFs)  
       
    43     {
       
    44     CMTPServiceConfig* self = new (ELeave) CMTPServiceConfig( aRFs );
       
    45     CleanupStack::PushL(self);
       
    46     self->ConstructL( KMTPServiceCofigfile ); 
       
    47     CleanupStack::Pop(self);
       
    48     return self;
       
    49     }
       
    50 
       
    51 
       
    52 /**
       
    53 Destructor
       
    54 */    
       
    55 CMTPServiceConfig::~CMTPServiceConfig()
       
    56     {
       
    57     __FLOG(_L8("CMTPServiceConfig::~CMTPServiceConfig() - Entry"));
       
    58         
       
    59     iSupportedServices.Close();
       
    60     iServiceInfos.ResetAndDestroy();
       
    61     __FLOG(_L8("CMTPServiceConfig::~CMTPServiceConfig() - Exit"));
       
    62     __FLOG_CLOSE;
       
    63     }
       
    64 
       
    65 TInt CMTPServiceConfig::SupportedServiceOrderFromAscending( const TSupportedService& aL, const TSupportedService& aR)
       
    66     {
       
    67     return aL.iGUID.Compare( aR.iGUID );
       
    68     }
       
    69 
       
    70 TInt CMTPServiceConfig::SupportedServiceOrderFromKeyAscending( const TMTPTypeGuid* aL, const TSupportedService& aR)
       
    71     {
       
    72     return aL->Compare( aR.iGUID );
       
    73     }
       
    74 
       
    75 CMTPServiceConfig::CMTPServiceConfig( RFs& aRFs ):
       
    76     iRFs(aRFs)
       
    77     {
       
    78     
       
    79     }
       
    80 
       
    81 void CMTPServiceConfig::ConstructL( const TDesC& aResourceFilename )
       
    82     {
       
    83     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    84     __FLOG(_L8("CMTPServiceConfig::ConstructL - Entry"));
       
    85     
       
    86 
       
    87     
       
    88     RResourceFile file;
       
    89     file.OpenL( iRFs, aResourceFilename );
       
    90     CleanupClosePushL(file);
       
    91        
       
    92     
       
    93     // Create the resource reader.
       
    94     const TInt KDefaultResourceId(1);
       
    95     HBufC8* buffer(file.AllocReadLC(KDefaultResourceId));
       
    96     TResourceReader reader;
       
    97     reader.SetBuffer(buffer);
       
    98     
       
    99     InitializeL( reader );
       
   100     
       
   101     CleanupStack::PopAndDestroy(buffer);
       
   102     CleanupStack::PopAndDestroy(&file);
       
   103     
       
   104     __FLOG(_L8("CMTPServiceConfig::ConstructL - Exit"));
       
   105     }
       
   106 
       
   107 
       
   108 void CMTPServiceConfig::InitializeL( TResourceReader& aReader )
       
   109     {
       
   110     __FLOG(_L8("CMTPServiceConfig::InitializeL - Entry"));
       
   111     
       
   112     //read the supported services
       
   113     TUint serviceCount = aReader.ReadInt16();
       
   114 
       
   115     TUint resID(0);
       
   116     TUint type(EMTPServiceTypeAbstract);
       
   117     while( serviceCount-- )
       
   118         {
       
   119         TMTPTypeGuid svcGUID = ReadGUID( aReader );
       
   120         type = aReader.ReadUint32();
       
   121         resID = aReader.ReadUint32();
       
   122         iSupportedServices.InsertInOrderL( TSupportedService( svcGUID, type, resID ), TLinearOrder<TSupportedService>(SupportedServiceOrderFromAscending) );      
       
   123         }
       
   124     
       
   125     
       
   126     __FLOG(_L8("CMTPServiceConfig::InitializeL - Exit"));
       
   127     }
       
   128 
       
   129 TBool CMTPServiceConfig::IsSupportedService( const TMTPTypeGuid& aServiceGUID ) const
       
   130     {   
       
   131     return !( KErrNotFound == iSupportedServices.FindInOrder( aServiceGUID, SupportedServiceOrderFromKeyAscending  ) );
       
   132     }
       
   133 
       
   134 void CMTPServiceConfig::LoadServiceDataL( const TMTPTypeGuid& aServiceGUID )
       
   135     {
       
   136     __FLOG(_L8("CMTPServiceConfig::LoadServiceDataL - Entry"));
       
   137     
       
   138     RResourceFile file;
       
   139     file.OpenL( iRFs, KMTPServiceCofigfile );
       
   140     CleanupClosePushL(file);
       
   141    
       
   142 
       
   143     // Create the resource reader.
       
   144     HBufC8* buffer(file.AllocReadLC( ServiceResourceIDL( aServiceGUID ) ));
       
   145     TResourceReader reader;
       
   146     reader.SetBuffer(buffer);
       
   147     
       
   148     CMTPServiceInfo* serviceInfo = CMTPServiceInfo::NewLC();
       
   149     const TUint KStorageID = 0;
       
   150     serviceInfo->SetServiceStorageID( KStorageID );
       
   151     
       
   152     //read pguid
       
   153     TMTPTypeGuid KPGUID( ReadGUID( reader ) );
       
   154     serviceInfo->SetPersistentGUIDL( KPGUID );
       
   155     
       
   156     //read version
       
   157     serviceInfo->SetServiceVersion( reader.ReadUint32() );
       
   158     
       
   159     //read service guid
       
   160     TMTPTypeGuid KSvcGUID( ReadGUID( reader ) );
       
   161     serviceInfo->SetServiceGUIDL( KSvcGUID );
       
   162     
       
   163     HBufC* name = reader.ReadHBufCL();
       
   164     //read service name
       
   165     serviceInfo->SetServiceName( name );
       
   166 
       
   167     //read service type
       
   168     serviceInfo->SetServiceType( reader.ReadUint32() );
       
   169     
       
   170     //read service base service id
       
   171     serviceInfo->SetBaseServiceID( reader.ReadUint32() );
       
   172     
       
   173     //read use service guids
       
   174     TUint resID = reader.ReadUint32();
       
   175     StartReadUseServicesL( file, resID, *serviceInfo );
       
   176     
       
   177     //read service properties
       
   178     TUint resNamespace = reader.ReadUint32();
       
   179     resID = reader.ReadUint32();
       
   180     StartReadServicePropertiesL( file,resNamespace, resID, *serviceInfo );
       
   181     
       
   182     //read service formats
       
   183     resID = reader.ReadUint32();
       
   184     StartReadServiceFormatsL( file, resID, *serviceInfo );
       
   185     
       
   186     //read service methods
       
   187     resID = reader.ReadUint32();
       
   188     StartReadServiceMethodsL( file, resID, *serviceInfo );
       
   189 
       
   190     //read service events
       
   191     resID = reader.ReadUint32();
       
   192     StartReadServiceEventsL( file, resID, *serviceInfo );
       
   193     
       
   194     //read service data block.
       
   195     resID = reader.ReadUint32();
       
   196     StartReadServiceDataBlockL( file, resID, *serviceInfo );
       
   197     
       
   198     iServiceInfos.AppendL(serviceInfo);
       
   199     CleanupStack::Pop(serviceInfo);
       
   200     CleanupStack::PopAndDestroy(buffer);
       
   201     CleanupStack::PopAndDestroy(&file);
       
   202     
       
   203     __FLOG(_L8("CMTPServiceConfig::LoadServiceDataL - Exit"));
       
   204     }
       
   205 
       
   206 void CMTPServiceConfig::StartReadUseServicesL(  RResourceFile& aResFile, const TUint aResID, CMTPServiceInfo& aServiceInfo )
       
   207     {
       
   208     __FLOG(_L8("CMTPServiceConfig::StartReadUseServices - Entry"));
       
   209     
       
   210     // Create the resource reader.
       
   211     HBufC8* buffer(aResFile.AllocReadLC( aResID ));
       
   212     TResourceReader reader;
       
   213     reader.SetBuffer(buffer);
       
   214     
       
   215     TUint num  = reader.ReadInt16();
       
   216     while( num-- )
       
   217         {
       
   218         TMTPTypeGuid KGUID(ReadGUID(reader));
       
   219         aServiceInfo.AppendUserServiceL( KGUID );
       
   220         }
       
   221     
       
   222     CleanupStack::PopAndDestroy(buffer);
       
   223     
       
   224     __FLOG(_L8("CMTPServiceConfig::StartReadUseServices - Exit"));
       
   225     }
       
   226 
       
   227 void CMTPServiceConfig::StartReadServicePropertyNamespacesL(  RResourceFile& aResFile, const TUint aResID, RArray<TMTPTypeGuid>& aNamespaces )
       
   228     {
       
   229     __FLOG(_L8("CMTPServiceConfig::StartReadServicePropertyNamespacesL - Entry"));
       
   230         
       
   231     // Create the resource reader.
       
   232     HBufC8* buffer(aResFile.AllocReadLC( aResID ));
       
   233     TResourceReader reader;
       
   234     reader.SetBuffer(buffer);
       
   235     
       
   236     //read namespaces
       
   237     TUint num = reader.ReadInt16();
       
   238     while( num-- )
       
   239         {
       
   240         aNamespaces.Append( ReadGUID(reader) );
       
   241         }
       
   242     
       
   243     CleanupStack::PopAndDestroy(buffer);
       
   244     __FLOG(_L8("CMTPServiceConfig::StartReadServicePropertyNamespacesL - Exit"));
       
   245     }
       
   246 
       
   247 void CMTPServiceConfig::StartReadServicePropertiesL(  RResourceFile& aResFile, const TUint aNamespaceResID, const TUint aPropertiesResID, CMTPServiceInfo& aServiceInfo )
       
   248     {
       
   249     __FLOG(_L8("CMTPServiceConfig::StartReadServicePropertyL - Entry"));
       
   250     
       
   251     //read namespaces
       
   252     RArray<TMTPTypeGuid> namespaces;
       
   253     CleanupClosePushL(namespaces);
       
   254     StartReadServicePropertyNamespacesL(aResFile, aNamespaceResID, namespaces);
       
   255     
       
   256     // Create the resource reader.
       
   257     HBufC8* buffer(aResFile.AllocReadLC( aPropertiesResID ));
       
   258     TResourceReader reader;
       
   259     reader.SetBuffer(buffer);
       
   260     
       
   261     //read properties  
       
   262     TUint num = reader.ReadInt16();
       
   263     TUint namespaceid = 0 ;
       
   264     TUint pkeyid = 0;
       
   265     HBufC* name( NULL );
       
   266     TUint16 datatype = 0;
       
   267     TUint8  getset = 0;
       
   268     TUint8  formflag = 0;
       
   269     CServiceProperty* newElement = NULL;
       
   270     while( num-- )
       
   271         {
       
   272         namespaceid = reader.ReadUint32();
       
   273         pkeyid = reader.ReadUint32();
       
   274         name = reader.ReadHBufCL();
       
   275         datatype = reader.ReadUint32();
       
   276         getset = reader.ReadUint8();
       
   277         formflag = reader.ReadUint8();
       
   278         
       
   279         newElement = CServiceProperty::NewLC(namespaces[namespaceid], pkeyid, name, datatype, getset, formflag);
       
   280         aServiceInfo.InsertPropertyL( newElement );
       
   281         CleanupStack::Pop(newElement);
       
   282         }
       
   283     
       
   284     CleanupStack::PopAndDestroy(buffer);
       
   285     CleanupStack::PopAndDestroy(&namespaces);
       
   286     
       
   287     __FLOG(_L8("CMTPServiceConfig::StartReadServicePropertyL - Exit"));
       
   288     }
       
   289 
       
   290 void CMTPServiceConfig::StartReadServiceFormatsL(  RResourceFile& aResFile, const TUint aResID, CMTPServiceInfo& aServiceInfo )
       
   291     {
       
   292     __FLOG(_L8("CMTPServiceConfig::StartReadServiceFormatL - Entry"));
       
   293     
       
   294     // Create the resource reader.
       
   295     HBufC8* buffer(aResFile.AllocReadLC( aResID ));
       
   296     TResourceReader reader;
       
   297     reader.SetBuffer(buffer);
       
   298     
       
   299     TUint num = reader.ReadInt16();
       
   300     HBufC* name( NULL );
       
   301     HBufC* mimetype1( NULL );
       
   302     CServiceFormat* newElement = NULL;
       
   303     while( num-- )
       
   304         {
       
   305         TMTPTypeGuid guid = ReadGUID( reader );
       
   306         name = reader.ReadHBufCL();   
       
   307 		CleanupStack::PushL(name);
       
   308 
       
   309         mimetype1 = reader.ReadHBufCL();
       
   310         if( NULL == mimetype1 )
       
   311             {
       
   312 			//If mimetype is not configed in the config file, then alloc a zero length buffer for it. The mimetype is treated as an empty string for this situation.
       
   313             mimetype1 = HBufC16::NewLC(0);
       
   314             }
       
   315         else
       
   316             {
       
   317             CleanupStack::PushL(mimetype1);
       
   318             }
       
   319         CleanupStack::Pop(2);
       
   320         newElement = CServiceFormat::NewLC( guid, name, reader.ReadUint16() ,mimetype1 );
       
   321 		
       
   322         aServiceInfo.InsertFormatL( newElement );
       
   323         CleanupStack::Pop(newElement);
       
   324         }
       
   325     
       
   326     CleanupStack::PopAndDestroy(buffer);
       
   327     
       
   328     __FLOG(_L8("CMTPServiceConfig::StartReadServiceFormatL - Exit"));
       
   329     }
       
   330 
       
   331 
       
   332 void CMTPServiceConfig::StartReadServiceMethodsL(  RResourceFile& aResFile, const TUint aResID,  CMTPServiceInfo& aServiceInfo )
       
   333     {
       
   334     __FLOG(_L8("CMTPServiceConfig::StartReadServiceMethodL - Entry"));
       
   335     
       
   336     // Create the resource reader.
       
   337     HBufC8* buffer(aResFile.AllocReadLC( aResID ));
       
   338     TResourceReader reader;
       
   339     reader.SetBuffer(buffer);
       
   340     
       
   341     TUint num = reader.ReadInt16();
       
   342     HBufC* name( NULL );
       
   343     CServiceMethod* newElement = NULL;
       
   344     while( num-- )
       
   345         {
       
   346         TMTPTypeGuid guid = ReadGUID( reader );
       
   347         name = reader.ReadHBufCL();       
       
   348         
       
   349         newElement = CServiceMethod::NewLC(guid, name, reader.ReadUint16());
       
   350         aServiceInfo.InsertMethodL( newElement );
       
   351         CleanupStack::Pop(newElement);
       
   352         }
       
   353     
       
   354     CleanupStack::PopAndDestroy(buffer);
       
   355     
       
   356     __FLOG(_L8("CMTPServiceConfig::StartReadServiceMethodL - Exit"));
       
   357     }
       
   358 
       
   359 void CMTPServiceConfig::StartReadServiceEventsL(  RResourceFile& aResFile, const TUint aResID, CMTPServiceInfo& aServiceInfo )
       
   360     {
       
   361     __FLOG(_L8("CMTPServiceConfig::StartReadServiceEventsL - Entry"));
       
   362       
       
   363     // Create the resource reader.
       
   364     HBufC8* buffer(aResFile.AllocReadLC( aResID ));
       
   365     TResourceReader reader;
       
   366     reader.SetBuffer(buffer);
       
   367     
       
   368     TUint num = reader.ReadInt16();
       
   369     TUint16 datacode(0); 
       
   370     CServiceEvent* newElement = NULL;
       
   371     while( num-- )
       
   372         {
       
   373         datacode = reader.ReadUint16();
       
   374         TMTPTypeGuid guid = ReadGUID( reader );     
       
   375         
       
   376         newElement = CServiceEvent::NewLC(datacode, guid, reader.ReadHBufCL() );
       
   377         aServiceInfo.InsertEventL( newElement );
       
   378         CleanupStack::Pop(newElement);
       
   379         }
       
   380       
       
   381     CleanupStack::PopAndDestroy(buffer);
       
   382     
       
   383       __FLOG(_L8("CMTPServiceConfig::StartReadServiceEventsL - Exit"));
       
   384     }
       
   385 
       
   386 void CMTPServiceConfig::StartReadServiceDataBlockL(  RResourceFile& aResFile, const TUint aResID, CMTPServiceInfo& aServiceInfo )
       
   387     {
       
   388     __FLOG(_L8("CMTPServiceConfig::StartReadServiceDataBlockL - Entry"));
       
   389     
       
   390     // Create the resource reader.
       
   391     HBufC8* buffer(aResFile.AllocReadLC( aResID ));
       
   392     TResourceReader reader;
       
   393     reader.SetBuffer(buffer);
       
   394     
       
   395     TUint num = reader.ReadInt16();
       
   396     while( num-- )
       
   397         {
       
   398         TMTPTypeGuid guid = ReadGUID( reader );
       
   399               
       
   400         aServiceInfo.AppendDataGUIDL( guid );
       
   401         }
       
   402     
       
   403     CleanupStack::PopAndDestroy(buffer);
       
   404     __FLOG(_L8("CMTPServiceConfig::StartReadServiceDataBlockL - Exit"));
       
   405     }
       
   406 
       
   407 CMTPServiceInfo* CMTPServiceConfig::ServiceInfo(const TMTPTypeGuid& aServiceGUID ) const
       
   408     {
       
   409     TInt count = iServiceInfos.Count();
       
   410     for(TInt i(0); i < count; i++ )
       
   411         {
       
   412         if(iServiceInfos[i]->ServicePersistentGUID().Equal(aServiceGUID))
       
   413             return iServiceInfos[i] ;
       
   414         }
       
   415     
       
   416     return NULL;
       
   417     }
       
   418 
       
   419 CMTPServiceInfo* CMTPServiceConfig::ServiceInfo(const TUint aServiceID) const
       
   420 	{
       
   421 	__FLOG(_L8("CMTPServiceConfig::ServiceInfo - Entry"));
       
   422 	
       
   423 	TInt count = iServiceInfos.Count();
       
   424     for(TInt i(0); i < count; i++ )
       
   425         {
       
   426         if(iServiceInfos[i]->ServiceID() == aServiceID)
       
   427             return iServiceInfos[i] ;
       
   428         }
       
   429     
       
   430     __FLOG(_L8("CMTPServiceConfig::ServiceInfo - Exit"));
       
   431     return NULL;
       
   432 	
       
   433 	}
       
   434 
       
   435 TInt CMTPServiceConfig::ServiceTypeOfSupportedService( const TMTPTypeGuid& aServiceGUID ) const
       
   436     {
       
   437     TInt index = iSupportedServices.FindInOrder( aServiceGUID, SupportedServiceOrderFromKeyAscending ) ;
       
   438        if( KErrNotFound == index)
       
   439            return KErrNotFound;
       
   440        
       
   441        return iSupportedServices[index].iServiceType;
       
   442     }
       
   443 
       
   444 TUint CMTPServiceConfig::ServiceResourceIDL( const TMTPTypeGuid& aServiceGUID ) const
       
   445     {
       
   446     TInt index = iSupportedServices.FindInOrder( aServiceGUID, SupportedServiceOrderFromKeyAscending ) ;
       
   447     if( KErrNotFound == index)
       
   448         User::Leave( KErrNotFound );
       
   449     
       
   450     return iSupportedServices[index].iResourceID;
       
   451     }
       
   452 
       
   453 TMTPTypeGuid CMTPServiceConfig::ReadGUID( TResourceReader& aReader )
       
   454     {
       
   455     TUint upper2 = aReader.ReadUint32();
       
   456     TUint upper1 = aReader.ReadUint32();
       
   457     TUint lower2 = aReader.ReadUint32();
       
   458     TUint lower1 = aReader.ReadUint32();
       
   459     
       
   460     return TMTPTypeGuid( MAKE_TUINT64( upper2, upper1 ), MAKE_TUINT64( lower2, lower1 ) );
       
   461     }
       
   462 
       
   463