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

📄 tmexampledmadapter.cpp

📁 c++下s60终端对终端传输协议
💻 CPP
字号:
/* Copyright (c) 2006, Forum Nokia. All rights reserved */

// INCLUDE FILES
#include "tmexampledmadapter.h"

// CONSTANTS
_LIT8(KMimeTypeTextPlain, "text/plain");  // A Mime-type constant
_LIT8(KDDFVersion, "1.0");

// The length of a leaf node value is max 99999 bytes
const TInt KSizeStringLength = 5; 

CTmExampleDmAdapter::CTmExampleDmAdapter(MSmlDmCallback* aDmCallback)
: CSmlDmAdapter(aDmCallback)
{
}

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

CTmExampleDmAdapter* CTmExampleDmAdapter::NewL( MSmlDmCallback* aDmCallback )
	{
	CTmExampleDmAdapter* self = new (ELeave) CTmExampleDmAdapter(aDmCallback);
	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, KDDFVersion);
	}

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

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

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

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

/**
* CTmExampleDmAdapter::UpdateLeafObjectL
*/
void CTmExampleDmAdapter::UpdateLeafObjectL( const TDesC8& aURI, 
    const TDesC8& /*aLUID*/, const TDesC8& aObject, const TDesC8& /*aType*/, 
    const TInt aStatusRef )
	{
	CSmlDmAdapter::TError status = SetValue(aURI, aObject);
	iCallback->SetStatusL(aStatusRef, status );
	}	
    
/**
* CTmExampleDmAdapter::UpdateLeafObjectL    (streaming)
*/    
void CTmExampleDmAdapter::UpdateLeafObjectL( const TDesC8& /*aURI*/, 
    const TDesC8& /*aLUID*/, RWriteStream*& /*aStream*/, 
    const TDesC8& /*aType*/, TInt aStatusRef)
    {
    // Nothing to do, this adapter does not support streaming (see
    // CTmExampleDmAdapter::StreamingSupport(..)). This method should
    // never be called by the framework. The dummy implementation is here
    // just in case.
    CSmlDmAdapter::TError status = CSmlDmAdapter::EError;
    iCallback->SetStatusL(aStatusRef, status);
    }        
	
/**
* CTmExampleDmAdapter::DeleteObjectL
*/
void CTmExampleDmAdapter::DeleteObjectL( const TDesC8& /*aURI*/, 
    const TDesC8& /*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.
	CSmlDmAdapter::TError status = CSmlDmAdapter::EError;
	iCallback->SetStatusL(aStatusRef, status);
	}

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

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

	iCallback->SetStatusL(aStatusRef, status );
	if (status == CSmlDmAdapter::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::FetchLeafObjectSizeL
*/
void CTmExampleDmAdapter::FetchLeafObjectSizeL( const TDesC8& aURI, 
    const TDesC8& aLUID, const TDesC8& aType, TInt aResultsRef, 
    TInt aStatusRef )
    {
    CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
    // The length constant is from ClientServerCommon.h
    TBuf<KTmMaxClientDescriptorLength> value(_L(""));
    CBufBase *object = CBufFlat::NewL(255);
    CleanupStack::PushL(object);

    if (aURI.Compare(_L8("TMEXAMPLE/ServerAddress")) == 0)
        {
        iTmSession.GetServerAddress(value);
        }
    else if (aURI.Compare(_L8("TMEXAMPLE/ServerPort")) == 0)        
        {
        iTmSession.GetServerPort(value);
        }
    else if (aURI.Compare(_L8("TMEXAMPLE/ServerType")) == 0)
        {
        iTmSession.GetServerType(value);                
        }
    else
        {
        status = CSmlDmAdapter::EInvalidObject;
        }
        
    if (status == CSmlDmAdapter::EOk)
        {
        // Copy the received 16-bit value into a 8-bit descriptor and calculate 
        // its length.
        TBuf8<KTmMaxClientDescriptorLength> eightBitValue;
        eightBitValue.Copy(value);

        TInt size = eightBitValue.Size();
        TBuf8<KSizeStringLength> sizeStr;
        sizeStr.AppendNum( size );
        
        // Give size to the framework
        object->InsertL( 0, sizeStr );
        iCallback->SetResultsL( aResultsRef, *object, aType );
        }
    iCallback->SetStatusL(aStatusRef, status );
    CleanupStack::PopAndDestroy(object);
    }    

/**
* CTmExampleDmAdapter::ChildURIListL
*/
void CTmExampleDmAdapter::ChildURIListL( const TDesC8& aURI, 
    const TDesC8& /*aLUID*/, 
    const CArrayFix<TSmlDmMappingInfo>& /*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.
	CSmlDmAdapter::TError status = CSmlDmAdapter::EInvalidObject;
	if (aURI.Compare(_L8("TMEXAMPLE")) == 0)
		{
		CBufBase *currentList = CBufFlat::NewL(255);
		CleanupStack::PushL(currentList);
		currentList->InsertL(0, _L8("ServerAddress/ServerPort/ServerType"));
		iCallback->SetResultsL(aResultsRef,*currentList,KNullDesC8);
		CleanupStack::PopAndDestroy(currentList);
		status = CSmlDmAdapter::EOk;
		}
	iCallback->SetStatusL(aStatusRef, status );
	}

/**
* CTmExampleDmAdapter::AddNodeObjectL
*/
void CTmExampleDmAdapter::AddNodeObjectL( const TDesC8& /*aURI*/, 
    const TDesC8& /*aParentLUID*/, const TInt aStatusRef )
	{
	// Should never be called by the framework.
	CSmlDmAdapter::TError status = CSmlDmAdapter::EError;
	iCallback->SetStatusL(aStatusRef, status);
	}

/**
* CTmExampleDmAdapter::ExecuteCommandL
*/
void CTmExampleDmAdapter::ExecuteCommandL( const TDesC8& /*aURI*/, 
    const TDesC8& /*aLUID*/, const TDesC8& /*aArgument*/, 
    const TDesC8& /*aType*/, TInt aStatusRef )
    {
    // Should never be called by the framework.
    CSmlDmAdapter::TError status = CSmlDmAdapter::EError;
    iCallback->SetStatusL(aStatusRef, status);
    }

/**
* CTmExampleDmAdapter::ExecuteCommandL   (streaming)
*/
void CTmExampleDmAdapter::ExecuteCommandL( const TDesC8& /*aURI*/, 
    const TDesC8& /*aLUID*/, RWriteStream*& /*aStream*/, 
    const TDesC8& /*aType*/, TInt aStatusRef )
    {
    // Should never be called by the framework.
    CSmlDmAdapter::TError status = CSmlDmAdapter::EError;
    iCallback->SetStatusL(aStatusRef, status);
    }

/**
* CTmExampleDmAdapter::CopyCommandL
*/
void CTmExampleDmAdapter::CopyCommandL( const TDesC8& /*aTargetURI*/, 
    const TDesC8& /*aTargetLUID*/, const TDesC8& /*aSourceURI*/, 
    const TDesC8& /*aSourceLUID*/, const TDesC8& /*aType*/, TInt aStatusRef )
    {
    // Should never be called by the framework.
    CSmlDmAdapter::TError status = CSmlDmAdapter::EError;
    iCallback->SetStatusL(aStatusRef, status);
    }    

/**
* CTmExampleDmAdapter::StartAtomicL
*/
void CTmExampleDmAdapter::StartAtomicL()
    {
    // Nothing to do, should never be called by the framework.
    }
    
/**
* CTmExampleDmAdapter::CommitAtomicL
*/
void CTmExampleDmAdapter::CommitAtomicL()
    {
    // Nothing to do, should never be called by the framework.
    }

/**
* CTmExampleDmAdapter::RollbackAtomicL
*/
void CTmExampleDmAdapter::RollbackAtomicL()
    {
    // Nothing to do, should never be called by the framework.
    }

/**
* CTmExampleDmAdapter::StreamingSupport
*/
TBool CTmExampleDmAdapter::StreamingSupport( TInt& aItemSize )
    {
    aItemSize = 5000;  // 5 kB, this value has no meaning in our case        
    return EFalse;  // We do not support streaming (there is no need to)
    }
    
/**
* CTmExampleDmAdapter::StreamCommittedL
*/
void CTmExampleDmAdapter::StreamCommittedL()
    {
    // Nothing to do, should never be called by the framework.
    }    

/**
* CTmExampleDmAdapter::CompleteOutstandingCmdsL
*/
void CTmExampleDmAdapter::CompleteOutstandingCmdsL()
    {
    // All our commands are synchronous, nothing to do here
    }

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

// End of file

⌨️ 快捷键说明

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