mtpfws/mtpfw/dataproviders/devdp/src/cmtpgetserviceinfo.cpp
changeset 0 d0791faffa3f
child 2 4843bb5893b6
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 #include <mtp/cmtpdataproviderplugin.h>
       
    21 #include <mtp/cmtptypearray.h>
       
    22 #include <mtp/cmtptypestring.h>
       
    23 #include <mtp/mtpdataproviderapitypes.h>
       
    24 #include <mtp/tmtptyperequest.h>
       
    25 #include <mtp/cmtptypeserviceinfo.h>
       
    26 #include <mtp/cmtptypeserviceprop.h>
       
    27 #include <mtp/cmtptypeserviceformat.h>
       
    28 #include <mtp/cmtptypeservicemethod.h>
       
    29 #include <mtp/cmtptypeserviceevent.h>
       
    30 #include <mtp/tmtptypeguid.h>
       
    31 
       
    32 #include "cmtpgetserviceinfo.h"
       
    33 #include "rmtpframework.h"
       
    34 #include "mtpdevdppanic.h"
       
    35 #include "cmtpservicemgr.h"
       
    36 
       
    37 
       
    38 
       
    39 // Class constants.
       
    40 __FLOG_STMT(_LIT8(KComponent,"GetServiceInfo");)
       
    41 
       
    42 /**
       
    43 Two-phase construction method
       
    44 @param aPlugin    The data provider plugin
       
    45 @param aFramework    The data provider framework
       
    46 @param aConnection    The connection from which the request comes
       
    47 @return a pointer to the created request processor object
       
    48 */    
       
    49 MMTPRequestProcessor* CMTPGetServiceInfo::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection)
       
    50     {
       
    51     CMTPGetServiceInfo* self = new (ELeave) CMTPGetServiceInfo(aFramework, aConnection);
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop(self);
       
    55     return self;
       
    56     }
       
    57 
       
    58 /**
       
    59 Destructor.
       
    60 */    
       
    61 CMTPGetServiceInfo::~CMTPGetServiceInfo()
       
    62     {    
       
    63     __FLOG(_L8("~CMTPGetServiceInfo - Entry"));
       
    64     delete iServiceInfo;
       
    65 
       
    66     iSingletons.Close();
       
    67     __FLOG(_L8("~CMTPGetServiceInfo - Exit"));
       
    68     __FLOG_CLOSE;
       
    69     }
       
    70 
       
    71 /**
       
    72 Constructor.
       
    73 */    
       
    74 CMTPGetServiceInfo::CMTPGetServiceInfo(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
       
    75     CMTPRequestProcessor(aFramework, aConnection, 0, NULL)
       
    76     {
       
    77     
       
    78     }
       
    79     
       
    80 /**
       
    81 GetServiceInfo request handler. Build and send device info data set.
       
    82 */    
       
    83 void CMTPGetServiceInfo::ServiceL()
       
    84     {
       
    85     __FLOG(_L8("ServiceL - Entry"));
       
    86        
       
    87     TUint32 serviceId = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
    88     if ( KErrNotFound == iSingletons.ServiceMgr().GetServiceIDs().Find(serviceId) )
       
    89     	{
       
    90     	SendResponseL(EMTPRespCodeInvalidServiceID);
       
    91     	}
       
    92     else if(iSingletons.ServiceMgr().IsSupportedService(serviceId))
       
    93     	{
       
    94     	BuildServiceInfoL();
       
    95     	SendDataL(*iServiceInfo);
       
    96     	}
       
    97     else
       
    98         {
       
    99         //The ServiceID has been allocated by MTP Datacode Generator
       
   100         //but Parser&Router fail to get the target DP.
       
   101         //it may be caused by: 
       
   102         //    1. DP plugin does not register the ServiceID by the Supported() function. Mostly.
       
   103         //    2. Framework have some errors while setup the router mapping table.
       
   104         Panic(EMTPDevDpUnknownServiceID);
       
   105         }
       
   106     
       
   107     __FLOG(_L8("ServiceL - Exit"));
       
   108     }
       
   109 
       
   110 /**
       
   111 Second-phase constructor.
       
   112 */        
       
   113 void CMTPGetServiceInfo::ConstructL()
       
   114     {
       
   115     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
   116     __FLOG(_L8("ConstructL - Entry")); 
       
   117     iSingletons.OpenL();
       
   118     __FLOG(_L8("ConstructL - Exit")); 
       
   119     }
       
   120 
       
   121 /**
       
   122 Populates service info data set
       
   123 */
       
   124 void CMTPGetServiceInfo::BuildServiceInfoL()
       
   125     {
       
   126     __FLOG(_L8("BuildServiceInfoL - Entry")); 
       
   127     
       
   128     delete iServiceInfo;
       
   129     iServiceInfo = CMTPTypeServiceInfo::NewL();
       
   130     
       
   131     TUint32 serviceId = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
   132     CMTPServiceInfo* svcinfo = iSingletons.ServiceMgr().ServiceInfo( serviceId );
       
   133     if( NULL == svcinfo )
       
   134         {
       
   135         __FLOG_1(_L8("BuildServiceInfoL - CMTPServiceInfo is NULL!!! ServiceID is %d."),serviceId ); 
       
   136         __FLOG(_L8("BuildServiceInfoL - Exit")); 
       
   137         return;
       
   138         }
       
   139     BuildServiceInfoHeadL(*svcinfo);
       
   140     BuildUsedServiceGUIDL(*svcinfo);
       
   141 	BuildServicePropertyL(*svcinfo);
       
   142 	BuildServiceFormatL(*svcinfo);
       
   143 	BuildServiceMethodL(*svcinfo);
       
   144 	BuildDataBlockL(*svcinfo);    
       
   145     
       
   146     __FLOG(_L8("BuildServiceInfoL - Exit")); 
       
   147     }
       
   148 
       
   149 
       
   150 void CMTPGetServiceInfo::BuildServiceInfoHeadL(CMTPServiceInfo& aServiceInfo)
       
   151 	{
       
   152 	__FLOG(_L8("BuildServiceInfoHeadL - Entry"));
       
   153 	
       
   154 	iServiceInfo->SetUint32L(CMTPTypeServiceInfo::EServiceID,aServiceInfo.ServiceID());
       
   155 	iServiceInfo->SetUint32L(CMTPTypeServiceInfo::EServiceStorageID,aServiceInfo.ServiceStorageID());
       
   156 	iServiceInfo->SetL(CMTPTypeServiceInfo::EServicePGUID,aServiceInfo.ServicePersistentGUID());
       
   157 	iServiceInfo->SetUint32L(CMTPTypeServiceInfo::EServiceVersion,aServiceInfo.ServiceVersion());
       
   158 	iServiceInfo->SetL(CMTPTypeServiceInfo::EServiceGUID,aServiceInfo.ServiceGUID());
       
   159 	iServiceInfo->SetStringL(CMTPTypeServiceInfo::EServiceName,aServiceInfo.ServiceName());
       
   160 	iServiceInfo->SetUint32L(CMTPTypeServiceInfo::EServiceType,aServiceInfo.ServiceType());
       
   161 	iServiceInfo->SetUint32L(CMTPTypeServiceInfo::EBaseServiceID,aServiceInfo.BaseServiceID());
       
   162 	
       
   163 	__FLOG(_L8("BuildServiceInfoHeadL - Exit")); 
       
   164 	}
       
   165 
       
   166 void CMTPGetServiceInfo::BuildUsedServiceGUIDL(CMTPServiceInfo& aServiceInfo)
       
   167 	{
       
   168 	__FLOG(_L8("BuildUsedServiceGUIDL - Entry"));
       
   169 	TInt count = aServiceInfo.UsedServiceGUIDs().Count();
       
   170 	const RArray<TMTPTypeGuid> UsedServiceGUIDs = aServiceInfo.UsedServiceGUIDs();
       
   171 	for (TInt i=0;i<count;i++)
       
   172 		{
       
   173           iServiceInfo->AppendUsedServiceL( UsedServiceGUIDs[i] );
       
   174 		}
       
   175 	
       
   176 	__FLOG(_L8("BuildUsedServiceGUIDL - Exit"));
       
   177 	}
       
   178 
       
   179 void CMTPGetServiceInfo::BuildServicePropertyL(CMTPServiceInfo& aServiceInfo)
       
   180 	{
       
   181 	__FLOG(_L8("BuildServicePropertyL - Entry"));
       
   182 
       
   183 	TInt count = aServiceInfo.ServiceProperties().Count();
       
   184 	CMTPTypeServicePropertyElement* PropElement = NULL;
       
   185 	CServiceProperty* prop = NULL;
       
   186 	const RPointerArray<CServiceProperty> ServiceProperties = aServiceInfo.ServiceProperties();
       
   187 	for (TInt i=0;i<count;i++)
       
   188 		{
       
   189 		prop = ServiceProperties[i];
       
   190 		if(!prop->IsUsed())
       
   191 		    continue;
       
   192 		
       
   193 		PropElement = CMTPTypeServicePropertyElement::NewLC(prop->Code(),prop->Namespace(),prop->PKeyID(), prop->Name());
       
   194 		iServiceInfo->ServicePropList().AppendL(PropElement);
       
   195 		CleanupStack::Pop(PropElement);
       
   196 		}
       
   197 	
       
   198 	__FLOG(_L8("BuildServicePropertyL - Exit"));
       
   199 	}
       
   200 
       
   201 void CMTPGetServiceInfo::BuildServiceFormatL(CMTPServiceInfo& aServiceInfo)
       
   202 	{
       
   203 	__FLOG(_L8("BuildServiceFormatL - Entry"));
       
   204 
       
   205 	CMTPTypeServiceFormatElement* FormatElement = NULL; 
       
   206 	CServiceFormat* format = NULL;  
       
   207 	TInt count = aServiceInfo.ServiceFormats().Count();
       
   208 	const RPointerArray<CServiceFormat> ServiceFormats = aServiceInfo.ServiceFormats();
       
   209 	for (TInt i=0;i<count;i++)
       
   210 		{
       
   211 		format = ServiceFormats[i];
       
   212 		if(!format->IsUsed())
       
   213 		    continue;
       
   214 		
       
   215 		FormatElement = CMTPTypeServiceFormatElement::NewLC( format->Code(), format->GUID(), format->Name(), format->FormatBase(), format->MIMEType1() );
       
   216 		iServiceInfo->ServiceFormatList().AppendL(FormatElement);
       
   217 		CleanupStack::Pop(FormatElement);
       
   218 		}
       
   219 	
       
   220 	__FLOG(_L8("BuildServiceFormatL - Exit"));
       
   221 	}
       
   222 
       
   223 void CMTPGetServiceInfo::BuildServiceMethodL(CMTPServiceInfo& aServiceInfo)
       
   224 	{
       
   225 	__FLOG(_L8("BuildServiceMethodL - Entry"));
       
   226 
       
   227 	CMTPTypeServiceMethodElement* methodElement = NULL;
       
   228 	CServiceMethod* method = NULL;
       
   229 	TInt count = aServiceInfo.ServiceMethods().Count();
       
   230 	const RPointerArray<CServiceMethod> ServiceMethods = aServiceInfo.ServiceMethods();
       
   231 	for (TInt i=0;i<count;i++)
       
   232 		{
       
   233 		method = ServiceMethods[i];
       
   234 		if(!method->IsUsed())
       
   235 		    continue;
       
   236 		methodElement = CMTPTypeServiceMethodElement::NewLC( method->Code(), method->GUID(), method->Name(), method->ObjAssociateFormatCode() );
       
   237 		iServiceInfo->ServiceMethodList().AppendL(methodElement);
       
   238 		CleanupStack::Pop(methodElement);		
       
   239 		}
       
   240 	
       
   241 	__FLOG(_L8("BuildServiceMethodL - Exit"));
       
   242 	}
       
   243 
       
   244 
       
   245 void CMTPGetServiceInfo::BuildDataBlockL(CMTPServiceInfo& aServiceInfo)
       
   246     {
       
   247     __FLOG(_L8("BuildDataBlockL - Entry"));
       
   248     TInt count = aServiceInfo.DataBlockGUIDs().Count();
       
   249     const RArray<TMTPTypeGuid> DataBlockGUIDs = aServiceInfo.DataBlockGUIDs();
       
   250     for (TInt i=0;i<count;i++)
       
   251         {
       
   252         iServiceInfo->AppendServiceDataBlockL( DataBlockGUIDs[i] );
       
   253         }
       
   254 
       
   255     __FLOG(_L8("BuildDataBlockL - Exit"));
       
   256     }
       
   257 
       
   258