mtpfws/mtpfw/dataproviders/devdp/src/cmtpgetdevicepropvalue.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 21 Jun 2010 16:36:59 +0300
branchRCL_3
changeset 32 f85613f12947
parent 0 d0791faffa3f
child 47 63cf70d3ecd8
permissions -rw-r--r--
Revision: 201020 Kit: 2010125

// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
//

#include <mtp/cmtptypestring.h>
#include <mtp/mmtpdataproviderframework.h>
#include <mtp/mtpprotocolconstants.h>
#include <mtp/tmtptyperequest.h>
#include <mtp/tmtptypeuint8.h>
#include <mtp/mmtpframeworkconfig.h>
#include "cmtpdevicedatastore.h"
#include "cmtpgetdevicepropvalue.h"
#include "mtpdevicedpconst.h"
#include "mtpdevdppanic.h"

// Class constants.
__FLOG_STMT(_LIT8(KComponent,"GetDevicePropValue");)

_LIT(KSpace, " ");

/**
Two-phase constructor.
@param aPlugin  The data provider plugin
@param aFramework The data provider framework
@param aConnection The connection from which the request comes
@return a pointer to the created request processor object.
*/  
MMTPRequestProcessor* CMTPGetDevicePropValue::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection)
    {
    CMTPGetDevicePropValue* self = new (ELeave) CMTPGetDevicePropValue(aFramework, aConnection);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(self);
    return self;
    }

/**
Destructor.
should not delete iMtpArray(ownership is belong to devicedatastore)
*/    
CMTPGetDevicePropValue::~CMTPGetDevicePropValue()
    {
    __FLOG(_L8("~CMTPGetDevicePropValue - Entry"));
    delete iString;    
    delete iData;
    //ownership of the iMtpArray pointer is belongs to devicedatastore so it should not 
    //deleted.    
    __FLOG(_L8("~CMTPGetDevicePropValue - Exit"));
    __FLOG_CLOSE;
    }

/**
Constructor.
*/    
CMTPGetDevicePropValue::CMTPGetDevicePropValue(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
    CMTPGetDevicePropDesc(aFramework, aConnection)
    {
    
    }

/**
Second-phase constructor.
*/
void CMTPGetDevicePropValue::ConstructL()
    {
    __FLOG_OPEN(KMTPSubsystem, KComponent);
    __FLOG(_L8("ConstructL - Entry")); 
    CMTPGetDevicePropDesc::ConstructL();
    iString = CMTPTypeString::NewL();
    __FLOG(_L8("ConstructL - Exit")); 
    }

/**
Services the battery level property.
*/    
void CMTPGetDevicePropValue::ServiceBatteryLevelL()
    {
    __FLOG(_L8("ServiceBatteryLevelL - Entry"));
    iBatteryLevel.Set(iBatteryLevelValue);
    SendDataL(iBatteryLevel);
    __FLOG(_L8("ServiceBatteryLevelL - Exit"));
    }

/**
Services the device friendly name property.
*/   
void CMTPGetDevicePropValue::ServiceDeviceFriendlyNameL()
    {
    __FLOG(_L8("ServiceDeviceFriendlyNameL - Entry")); 
    //if device friendly name is blank, which means it is the first time the device get connected,
    //, so will use "manufacture + model id" firstly; if neither manufacture nor model
    //id not able to be fetched by API, then use the default device friendly name     if ( iDpSingletons.DeviceDataStore().DeviceFriendlyName().Length()<=0 )
    if ( iDpSingletons.DeviceDataStore().DeviceFriendlyName().Length()<=0 ) 
        {
        if ( iDpSingletons.DeviceDataStore().Manufacturer().Compare(KMTPDefaultManufacturer) && 
                iDpSingletons.DeviceDataStore().Model().Compare(KMTPDefaultModel) )
            {
            HBufC* friendlyName = HBufC::NewLC( iDpSingletons.DeviceDataStore().Manufacturer().Length()+1+  iDpSingletons.DeviceDataStore().Model().Length());
            TPtr ptrName = friendlyName->Des();
            ptrName.Copy( iDpSingletons.DeviceDataStore().Manufacturer());
            ptrName.Append(KSpace);
            ptrName.Append( iDpSingletons.DeviceDataStore().Model());
            iDpSingletons.DeviceDataStore().SetDeviceFriendlyNameL(ptrName);
            iString->SetL(ptrName);
            CleanupStack::PopAndDestroy(friendlyName);
            }
        else
            {
            iString->SetL(iDpSingletons.DeviceDataStore().DeviceFriendlyNameDefault());
            }
        }
    else
        {
        iString->SetL(iDpSingletons.DeviceDataStore().DeviceFriendlyName());
        }
      
    SendDataL(*iString);  
    __FLOG(_L8("ServiceDeviceFriendlyNameL - Exit"));   
    }
        
/**
Services the synchronisation partner property.
*/ 
void CMTPGetDevicePropValue::ServiceSynchronisationPartnerL()
    {
    __FLOG(_L8("ServiceSynchronisationPartnerL - Entry")); 
    iString->SetL(iDpSingletons.DeviceDataStore().SynchronisationPartner());
    SendDataL(*iString);
    __FLOG(_L8("ServiceSynchronisationPartnerL - Exit"));
    }

/**
Services the ServiceSessionInitiatorVersionInfo property. 
*/ 
void CMTPGetDevicePropValue::ServiceSessionInitiatorVersionInfoL()
   {
   __FLOG(_L8("ServiceSessionInitiatorVersionInfo - Entry")); 
   iString->SetL(iDpSingletons.DeviceDataStore().SessionInitiatorVersionInfo());
   SendDataL(*iString);
   __FLOG(_L8("ServiceSessionInitiatorVersionInfo - Exit"));
   }

/**
Services the ServicePerceivedDeviceType property. 
*/ 
void CMTPGetDevicePropValue::ServicePerceivedDeviceTypeL()
   {
   __FLOG(_L8("ServiceSessionInitiatorVersionInfo - Entry")); 
   iUint32.Set(iDpSingletons.DeviceDataStore().PerceivedDeviceType());
   SendDataL(iUint32);
   __FLOG(_L8("ServiceSessionInitiatorVersionInfo - Exit"));
   }

/**
Services the Date time device property. 
*/ 
void CMTPGetDevicePropValue::ServiceDateTimeL()
  {
  __FLOG(_L8("ServiceDateTime - Entry")); 
  iString->SetL(iDpSingletons.DeviceDataStore().DateTimeL());
  SendDataL(*iString);
  __FLOG(_L8("ServiceDateTime - Exit"));
  }

/**
Services the DiviceIcon property. 
*/ 
void CMTPGetDevicePropValue::ServiceDeviceIconL()
    {
    __FLOG(_L8("DeviceIcon - Entry")); 
    //iMtpArray is not owned by this class DO NOT DELET IT.
    iMtpArray = &(iDpSingletons.DeviceDataStore().DeviceIcon());
    SendDataL(*iMtpArray);
    __FLOG(_L8("DeviceIcon - Exit"));
    }

/**
Services the ServicePerceivedDeviceType property. 
*/ 
void CMTPGetDevicePropValue::ServiceSupportedFormatsOrderedL()
    {
    __FLOG(_L8("ServiceSessionInitiatorVersionInfo - Entry"));    
    iUint8.Set(GetFormatOrdered());
    SendDataL(iUint8);
    __FLOG(_L8("ServiceSessionInitiatorVersionInfo - Exit"));
    }

 void CMTPGetDevicePropValue::HandleExtnServiceL(TInt aPropCode, MExtnDevicePropDp* aExtnDevplugin)
    {
    MMTPType* mtptype = NULL;
    aExtnDevplugin->GetDevPropertyL((TMTPDevicePropertyCode)aPropCode, &mtptype);

    if(NULL != mtptype)
        {
        SendDataL(*mtptype);	
        }
    else
        {
        SendResponseL(EMTPRespCodeDevicePropNotSupported); 	
        }
    }
 
 /*
 *Service Supported FuntionalID.
 */
 void CMTPGetDevicePropValue::ServiceFunctionalIDL()
     {
     __FLOG(_L8("ServiceFuntionalIDL - Entry")); 

    delete iData;
    iData = GetGUIDL(MMTPFrameworkConfig::EDeviceCurrentFuncationalID); 
    
     SendDataL(*iData); 
     __FLOG(_L8("ServiceFuntionalIDL - Exit")); 
     }

 /*
 *Service Supported ModelID.
 */
 void CMTPGetDevicePropValue::ServiceModelIDL()
     {
     __FLOG(_L8("ServiceModelIDL - Entry")); 
     
     delete iData;
     iData = GetGUIDL(MMTPFrameworkConfig::EDeviceCurrentModelID); 
 	
     SendDataL(*iData); 
     __FLOG(_L8("ServiceModelIDL - Exit")); 
     }

 /*
 *Service Supported UseDeviceStage.
 */
 void CMTPGetDevicePropValue::ServiceUseDeviceStageL()
     {
     __FLOG(_L8("ServiceUseDeviceStageL - Entry")); 
 	iUint8.Set(1);
 	SendDataL(iUint8); 
     __FLOG(_L8("ServiceUseDeviceStageL - Exit")); 
     }