contentmgmt/cafstreamingsupport/test/streamingtestagent/source/client/staclient.cpp
branchRCL_3
changeset 43 2f10d260163b
child 61 641f389e9157
equal deleted inserted replaced
42:eb9b28acd381 43:2f10d260163b
       
     1 // Copyright (c) 2007-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 the License "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 // RStaClient implementation.	 See class and function definitions
       
    15 // for more detail.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "staclient.h"
       
    20 
       
    21 using namespace StreamAccess;
       
    22 using namespace ContentAccess;
       
    23 
       
    24 EXPORT_C RStaClient::RStaClient()
       
    25 /**
       
    26 	This constructor provides a single point of definition from
       
    27 	which the superclass constructor is called.
       
    28  */
       
    29 	: RScsClientBase()
       
    30 		{
       
    31 		//empty
       
    32 		}
       
    33 		
       
    34 	
       
    35 EXPORT_C TInt RStaClient::Connect()
       
    36 /**
       
    37 	Connect to the Streaming Test Agent server.
       
    38 
       
    39 	@return		Symbian OS error code where KErrNone indicates
       
    40 				success and any other value indicates failure.
       
    41  */
       
    42 	{
       
    43 	TVersion v = StaVersion();
       
    44 	TUidType fullUid = StaImageFullUid();
       
    45 	
       
    46 	return RScsClientBase::Connect(KStaName, v, KStaImageName, fullUid);
       
    47 	}
       
    48 	
       
    49 	
       
    50 EXPORT_C void RStaClient::Close()
       
    51 /**
       
    52 	Closes the streaming test agent connection.
       
    53 */
       
    54 	{
       
    55 	RScsClientBase::Close();
       
    56 	}
       
    57 
       
    58 
       
    59 EXPORT_C void RStaClient::GetAttributeL(const TAttribute& aAttribute, TBool& aValue)
       
    60 /**
       
    61  	Gets the value of a requested attribute listed in TAttribute enumeration.
       
    62  	
       
    63  	@param aAttribute The requested attribute.
       
    64  	@param aValue     The value of the requested attribute
       
    65  	
       
    66  	@see StreamAccess::TAttribute
       
    67  */
       
    68 	{
       
    69 	TPckg<TAttribute> attrBuf(aAttribute);
       
    70 	TPckg<TBool> valueBuf(aValue);
       
    71 	User::LeaveIfError(CallSessionFunction(EGetAttribute, TIpcArgs(&attrBuf, &valueBuf)));
       
    72 	}
       
    73 
       
    74 
       
    75 EXPORT_C HBufC* RStaClient::GetStringAttributeLC(const TStringAttribute& aAttribute)
       
    76 /**
       
    77  	Gets the value of a requested string attribute listed in TStringAttribute enumeration.
       
    78  	
       
    79  	@param aAttribute The requested string attribute.
       
    80  	@return    A pointer to the value of the requested string attribute. 
       
    81  			   The ownership is transfered to the calling function.
       
    82  	@see StreamAccess::TStringAttribute
       
    83  */
       
    84 	{
       
    85 	TPckg<TStringAttribute> strAttr(aAttribute);
       
    86 	TInt size = 0;
       
    87 	TPckg<TInt> sizeBuf(size);
       
    88 	User::LeaveIfError(CallSessionFunction(EGetStringAttributeSize, TIpcArgs(&strAttr, &sizeBuf)));
       
    89 	
       
    90 	HBufC8* value8 = HBufC8::NewLC(size);
       
    91 	TPtr8 ptr8(value8->Des());
       
    92 	
       
    93 	User::LeaveIfError(CallSessionFunction(EGetStringAttributeData, TIpcArgs(&strAttr, &ptr8)));
       
    94 	
       
    95 	//Convert 8-bit to 16-bit
       
    96 	HBufC* value = HBufC::NewL(ptr8.Size());
       
    97 	TPtr ptr(value->Des());
       
    98 	ptr.Copy(ptr8);
       
    99 
       
   100 	CleanupStack::PopAndDestroy(value8);
       
   101 	CleanupStack::PushL(value);
       
   102 	return value;
       
   103 	}
       
   104 
       
   105 
       
   106 EXPORT_C void RStaClient::GetPostDeliveryRightsL(RFile& aFile, TDes8& aCid, TDes8& aRightsMimeType, TDes8& aContentMimeType)
       
   107 /**
       
   108  	@param aFile The file handle of the post-delivery rights object obtained from 
       
   109  		    	 the streaming test agent server. The receiving party is responsible
       
   110  		    	 to close the file handle.
       
   111  	@param aCid  The content Id
       
   112  	@param aRightsMimeType The mime type of the post-acquisition rights object.
       
   113 	@param aContentMimeType The mime type of the content.
       
   114  */
       
   115 	{
       
   116 	TInt fsh;			//session (RFs) handle
       
   117 	TPckgBuf<TInt> fh;	//subsession (RFile) handle
       
   118 	
       
   119 	//The message is completed with the file-server (RFs) session handle
       
   120 	//Pointer to the file subsession handle in slot 0
       
   121 	fsh = CallSessionFunction(EGetPostDeliveryRights, TIpcArgs(&fh, &aCid, &aRightsMimeType, &aContentMimeType));
       
   122 	User::LeaveIfError(fsh);
       
   123 	
       
   124 	// Adopt the file using the returned handles
       
   125 	User::LeaveIfError(aFile.AdoptFromServer(fsh,fh()));
       
   126 	}
       
   127 
       
   128 EXPORT_C void RStaClient::SendKeyStreamL(const TDesC8& aKey) const
       
   129 /**
       
   130  	Sends an encrypted short-term key to the test agent server.
       
   131  	@param aKey An encrypted key.
       
   132  */
       
   133 	{
       
   134 	User::LeaveIfError(CallSessionFunction(ESendKeyStream, TIpcArgs(&aKey)));
       
   135 	}
       
   136 
       
   137 EXPORT_C void RStaClient::SetKeyStreamSinkL(const CKeyStreamSink& aSink) const
       
   138 /**
       
   139  	Sends a key stream sink object to the test agent server.
       
   140  	@param aKey A key stream sink object.
       
   141  */
       
   142 	{
       
   143 	TPtr8 ptr(aSink.ExternalizeLC());
       
   144 	User::LeaveIfError(CallSessionFunction(ESetKeyStreamSink, TIpcArgs(&ptr)));
       
   145 	CleanupStack::PopAndDestroy(); // Delete the allocated buffer
       
   146 	}
       
   147 
       
   148 EXPORT_C void RStaClient::SetSdpMediaFieldL(const CSdpMediaField& aSdp) const
       
   149 /**
       
   150  	Sends an SDP key stream field to the test agent server.
       
   151  	@param aKey An SDP object data.
       
   152  */
       
   153 	{
       
   154 #ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY
       
   155 	HBufC8* sdpBuf(0);
       
   156 	TPtr8 ptr(EncodeLC(aSdp, sdpBuf));
       
   157 	User::LeaveIfError(CallSessionFunction(ESetSdpKeyStream, TIpcArgs(&ptr)));
       
   158 	CleanupStack::PopAndDestroy(sdpBuf);
       
   159 #else
       
   160 	(void) aSdp;
       
   161 #endif
       
   162 
       
   163 	}
       
   164 
       
   165 EXPORT_C void RStaClient::SetSdpDocumentL(const CSdpDocument& aSdpDoc) const
       
   166 /**
       
   167  	Sends an SDP document object data to the reference agent server.
       
   168  	@param aKey An SDP object data.
       
   169  */
       
   170 	{
       
   171 #ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY
       
   172 	HBufC8* sdpDocBuf(0);
       
   173 	TPtr8 ptr(EncodeLC(aSdpDoc, sdpDocBuf));
       
   174 	User::LeaveIfError(CallSessionFunction(ESetSdpDocument, TIpcArgs(&ptr)));
       
   175 	CleanupStack::PopAndDestroy(sdpDocBuf);
       
   176 #else
       
   177 	(void) aSdpDoc;
       
   178 #endif
       
   179 
       
   180 	}
       
   181 
       
   182 EXPORT_C void RStaClient::SendIpSecAssociationL(TInt32 aSpi, HBufC8* aEncryptionKey, HBufC8* aAuthenticationKey) const
       
   183 	{
       
   184 	CBufFlat* buf = CBufFlat::NewL(KExpandSize);
       
   185 	CleanupStack::PushL(buf);
       
   186 	
       
   187 	RBufWriteStream stream(*buf);
       
   188 	CleanupClosePushL(stream);
       
   189 	
       
   190 	stream.WriteInt32L(aSpi);
       
   191 	stream << *aEncryptionKey;
       
   192 	stream << *aAuthenticationKey;
       
   193 	
       
   194 	HBufC8* des = HBufC8::NewL(buf->Size());
       
   195 	TPtr8 ptr(des->Des());
       
   196 	buf->Read(0, ptr, buf->Size());
       
   197 	
       
   198 	CleanupStack::PopAndDestroy(2, buf);
       
   199 	CleanupStack::PushL(des);	
       
   200 	
       
   201 	User::LeaveIfError(CallSessionFunction(ESetIpSecAssoc, TIpcArgs(&ptr)));
       
   202 	CleanupStack::PopAndDestroy(des);
       
   203 	}