⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmexampledmadapter.cpp

📁 The Software cannot constitute the primary value of any new software derived from or incorporating
💻 CPP
字号:
/* Copyright (c) 2005, Forum Nokia. All rights reserved */

// INCLUDE FILES
#include "tmexampledmadapter.h"

// A Mime-type constant
_LIT(KMimeTypeTextPlain, "text/plain");

CTmExampleDmAdapter::~CTmExampleDmAdapter()
{
	iTmSession.Close();
}

CTmExampleDmAdapter* CTmExampleDmAdapter::NewL( MNSmlDmCallback* aDmCallback )
	{
	CTmExampleDmAdapter* self = new (ELeave) CTmExampleDmAdapter();
	CleanupStack::PushL(self);
	User::LeaveIfError(self->iTmSession.Connect());
	self->iCallback = aDmCallback;
	CleanupStack::Pop(self);
	return self;
	}

/**
* CTmExampleDmAdapter::DDFVersionL
*/
void CTmExampleDmAdapter::DDFVersionL(CBufBase& aVersion)
	{
	aVersion.InsertL(0,_L8("1.0"));
	}

/**
* CTmExampleDmAdapter::DDFStructureL
*/
void CTmExampleDmAdapter::DDFStructureL( MNSmlDmDDFObject& aDDF )
	{
	/* 
	* Create one root node and three leaf nodes:
	* TMEXAMPLE\
	* TMEXAMPLE\ServerAddress
	* TMEXAMPLE\ServerPort
	* TMEXAMPLE\ServerType
	*/
	
	TNSmlDmAccessTypes accessTypesGetReplace;
	accessTypesGetReplace.SetReplace();
	accessTypesGetReplace.SetGet();
	
	TNSmlDmAccessTypes accessTypesGet;
	accessTypesGet.SetGet();

	// TMEXAMPLE, main node
	MNSmlDmDDFObject& tmExampleRoot = aDDF.AddChildObjectL(_L("TMEXAMPLE"));
	tmExampleRoot.SetAccessTypesL(accessTypesGet);
	tmExampleRoot.SetAsObjectGroup();
	tmExampleRoot.SetOccurenceL(MNSmlDmDDFObject::EOne);
	tmExampleRoot.SetScopeL(MNSmlDmDDFObject::EPermanent);
	tmExampleRoot.SetDFFormatL(MNSmlDmDDFObject::Enode);

	// ServerAddress, a node that can be modified
	MNSmlDmDDFObject& serverAddress = tmExampleRoot.AddChildObjectL(_L("ServerAddress"));
	serverAddress.SetAccessTypesL(accessTypesGetReplace);
	serverAddress.SetOccurenceL(MNSmlDmDDFObject::EOne);
	serverAddress.SetScopeL(MNSmlDmDDFObject::EPermanent);
	serverAddress.SetDFFormatL(MNSmlDmDDFObject::Echr);
	serverAddress.AddDFTypeMimeTypeL(KMimeTypeTextPlain);
	
	// ServerPort, a node that can be modified
	MNSmlDmDDFObject& serverPort = tmExampleRoot.AddChildObjectL(_L("ServerPort"));
	serverPort.SetAccessTypesL(accessTypesGetReplace);
	serverPort.SetOccurenceL(MNSmlDmDDFObject::EOne);
	serverPort.SetScopeL(MNSmlDmDDFObject::EPermanent);
	serverPort.SetDFFormatL(MNSmlDmDDFObject::Echr);
	serverPort.AddDFTypeMimeTypeL(KMimeTypeTextPlain);

	// ServerType, a node that can be modified
	MNSmlDmDDFObject& serverType = tmExampleRoot.AddChildObjectL(_L("ServerType"));
	serverType.SetAccessTypesL(accessTypesGetReplace);
	serverType.SetOccurenceL(MNSmlDmDDFObject::EOne);
	serverType.SetScopeL(MNSmlDmDDFObject::EPermanent);
	serverType.SetDFFormatL(MNSmlDmDDFObject::Echr);
	serverType.AddDFTypeMimeTypeL(KMimeTypeTextPlain);
	}

/**
* CTmExampleDmAdapter::AddLeafObjectL
*/
void CTmExampleDmAdapter::AddLeafObjectL(const TDesC& aURI,const TDesC& aParentLUID,const TDesC8& aObject,const TDesC& /*aType*/,const TInt aStatusRef)
	{
	// Adding a node actually works like UpdateLeafObjectL and merely replaces the node's value in this example, 
	// since all the nodes are permanent nodes. This method could also just set status EAlreadyExists or EOk and do nothing.
	// In fact, since add is not allowed on any node in DDFStructureL, this method should never be called by the framework.
	CNSmlDmAdapter::TError status = SetValue(aURI, aObject);
	iCallback->SetStatusL(aStatusRef, status );
	}
	
/**
* CTmExampleDmAdapter::UpdateLeafObjectL
*/
void CTmExampleDmAdapter::UpdateLeafObjectL(const TDesC& aURI,const TDesC& aLUID,const TDesC8& aObject,const TDesC& aType,const TInt aStatusRef)
	{
	CNSmlDmAdapter::TError status = SetValue(aURI, aObject);
	iCallback->SetStatusL(aStatusRef, status );
	}	
	
/**
* CTmExampleDmAdapter::DeleteObjectL
*/
void CTmExampleDmAdapter::DeleteObjectL( const TDesC& aURI, const TDesC& aLUID, const TInt aStatusRef )
	{
	// Deletion not allowed on any of the nodes, this method should never be called by the framework.
	// The dummy implementation is here just in case.
	CNSmlDmAdapter::TError status = CNSmlDmAdapter::EError;
	iCallback->SetStatusL(aStatusRef, status);
	}

/**
* CTmExampleDmAdapter::FetchLeafObjectL
*/
void CTmExampleDmAdapter::FetchLeafObjectL( const TDesC& aURI, const TDesC& aLUID, const TDesC& aType, const TInt aResultsRef, const TInt aStatusRef )
	{
	CNSmlDmAdapter::TError status = CNSmlDmAdapter::EOk;
	// The length constant is from ClientServerCommon.h
	TBuf<KTmMaxClientDescriptorLength> value(_L(""));
	CBufBase *object = CBufFlat::NewL(255);
	CleanupStack::PushL(object);

 	if (aURI.Compare(_L("TMEXAMPLE/ServerAddress")) == 0)
		{
		iTmSession.GetServerAddress(value);
		}
	else if (aURI.Compare(_L("TMEXAMPLE/ServerPort")) == 0)		
		{
		iTmSession.GetServerPort(value);
		}
	else if (aURI.Compare(_L("TMEXAMPLE/ServerType")) == 0)
		{
		iTmSession.GetServerType(value);				
		}
	else
		{
			status = CNSmlDmAdapter::EInvalidObject;
		}

	iCallback->SetStatusL(aStatusRef, status );
	if (status == CNSmlDmAdapter::EOk)
		{
		// Copy the received 16-bit value into a 8-bit descriptor and return it to the framework.
		TBuf8<KTmMaxClientDescriptorLength> eightBitValue;
		eightBitValue.Copy(value);
		object->InsertL(0, eightBitValue);
		iCallback->SetResultsL(aResultsRef,*object,KMimeTypeTextPlain);		
		}
	
	CleanupStack::PopAndDestroy(object);
	}

/**
* CTmExampleDmAdapter::ChildURIListL
*/
void CTmExampleDmAdapter::ChildURIListL( const TDesC& aURI, const TDesC& aLUID, const CArrayFix<TNSmlDmMappingInfo>& aPreviousURISegmentList, const TInt aResultsRef, const TInt aStatusRef )
	{
	// Return the names of the child nodes of our root node "TMEXAMPLE". The other nodes are not interior nodes, so aURI referring to them
	// cannot be valid.
	CNSmlDmAdapter::TError status = CNSmlDmAdapter::EInvalidObject;
	if (aURI.Compare(_L("TMEXAMPLE")) == 0)
		{
		CBufBase *currentList = CBufFlat::NewL(255);
		CleanupStack::PushL(currentList);
		currentList->InsertL(0, _L8("ServerAddress/ServerPort/ServerType"));
		iCallback->SetResultsL(aResultsRef,*currentList,KNullDesC);
		CleanupStack::PopAndDestroy(currentList);
		status = CNSmlDmAdapter::EOk;
		}
	iCallback->SetStatusL(aStatusRef, status );
	}

/**
* CTmExampleDmAdapter::AddNodeObjectL
*/
void CTmExampleDmAdapter::AddNodeObjectL( const TDesC& aURI, const TDesC& aParentLUID, const TInt aStatusRef )
	{
	// Should never be called by the framework.
	CNSmlDmAdapter::TError status = CNSmlDmAdapter::EError;
	iCallback->SetStatusL(aStatusRef, status);
	}
	
/**
* A helper method that sets the value of the leaf node received from the DM server.
*/
CNSmlDmAdapter::TError CTmExampleDmAdapter::SetValue(const TDesC& aURI, const TDesC8& aObject)
	{
	CNSmlDmAdapter::TError status = CNSmlDmAdapter::EOk;
	if (aObject.Length() <= KTmMaxClientDescriptorLength)
		{
		// Convert aObject into a 16-bit descriptor
		TBuf16<KTmMaxClientDescriptorLength> myObject;
		myObject.Copy(aObject);
	
		if (aURI.Compare(_L("TMEXAMPLE/ServerAddress")) == 0)
			{
			iTmSession.SetServerAddress(myObject);
			}
		else if (aURI.Compare(_L("TMEXAMPLE/ServerPort")) == 0)		
			{
			iTmSession.SetServerPort(myObject);
			}
		else if (aURI.Compare(_L("TMEXAMPLE/ServerType")) == 0)
			{
			iTmSession.SetServerType(myObject);				
			}
		else
			{
			status = CNSmlDmAdapter::EInvalidObject;
			}
		}
	else
		{
		// The given descriptor was too long to be stored
		status = CNSmlDmAdapter::EInvalidObject;
		}
	return status;
	}


// -----------------------------------------------------------------------------
// E32Dll()
// DLL entry point, return that everything is ok
// -----------------------------------------------------------------------------
//
GLDEF_C TInt E32Dll( TDllReason )
    {
    return KErrNone;
    }

	
// End of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -