contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/client/sraclient.cpp
changeset 8 35751d3474b7
child 17 cd501b96611d
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * RSraClient implementation.	 See class and function definitions
       
    16 * for more detail.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include "sraclient.h"
       
    22 
       
    23 using namespace StreamAccess;
       
    24 
       
    25 EXPORT_C RSraClient::RSraClient()
       
    26 //Constructor
       
    27 	: RSessionBase()
       
    28 		{
       
    29 		//empty
       
    30 		}
       
    31 		
       
    32 	
       
    33 EXPORT_C TInt RSraClient::Connect()
       
    34 /**
       
    35 	Connect to the Streaming Reference Agent server.
       
    36 
       
    37 	@return		Symbian OS error code where KErrNone indicates
       
    38 				success and any other value indicates failure.
       
    39  */
       
    40 	{
       
    41 	TVersion ver = SraVersion();
       
    42 	TUidType fullUid = SraImageFullUid();
       
    43 	TInt retries = 2;		// number of remaining retries
       
    44 
       
    45 	for (;;)
       
    46 		{
       
    47 		TInt r = CreateSession(KSraName, ver);
       
    48 		
       
    49 		// if connected then finished
       
    50 		if (r == KErrNone)
       
    51 			return r;
       
    52 
       
    53 		// if any reason other than server not available then abort
       
    54 		if (r != KErrNotFound && r != KErrServerTerminated)
       
    55 			return r;
       
    56 
       
    57 		if (--retries == 0)
       
    58 			return r;
       
    59 
       
    60 		r = StartServerProcess(KSraImageName, fullUid);
       
    61 		if (r != KErrNone && r != KErrAlreadyExists)
       
    62 			return r;
       
    63 		}	// for (;;)
       
    64 	}
       
    65 	
       
    66 
       
    67 TInt RSraClient::StartServerProcess(const TDesC& aExeName, const TUidType& aFullExeUid)
       
    68 /**
       
    69 	This function is defined for the convenience of subclasses which need to start
       
    70 	a server process before they can connect to the server.
       
    71 
       
    72 	@param	aExeName		Executable which hosts the server.
       
    73 	@param	aFullExeUid		The server executable's full UID.  This is used to ensure the
       
    74 							intended executable is started, and not another executable
       
    75 							with the same name.
       
    76 	@return					Symbian OS error code.  KErrNone indicates success, and any other
       
    77 							value indicates failure.
       
    78  */
       
    79 	{
       
    80 	RProcess pr;
       
    81 	TInt r = pr.Create(aExeName, /* aCommand */ KNullDesC, aFullExeUid);
       
    82 	if (r != KErrNone)
       
    83 		return r;
       
    84 
       
    85 	TRequestStatus rs;
       
    86 	pr.Rendezvous(rs);
       
    87 	if (rs != KRequestPending)
       
    88 		r = rs.Int();
       
    89 	else
       
    90 		{
       
    91 		pr.Resume();
       
    92 		User::WaitForRequest(rs);
       
    93 		r = (pr.ExitType() == EExitPending) ? rs.Int() : KErrGeneral;
       
    94 		}
       
    95 
       
    96 	pr.Close();
       
    97 	return r;
       
    98 	}
       
    99 
       
   100 
       
   101 EXPORT_C void RSraClient::GetAttributeL(const TAttribute& aAttribute, TBool& aValue)
       
   102 /**
       
   103  	Gets the value of a requested attribute listed in TAttribute enumeration.
       
   104  	
       
   105  	@param aAttribute The requested attribute.
       
   106  	@param aValue     The value of the requested attribute
       
   107  	
       
   108  	@see StreamAccess::TAttribute
       
   109  */
       
   110 	{
       
   111 	TPckg<TAttribute> pckgAttr(aAttribute);
       
   112 	TPckg<TBool> pckgVal(aValue);
       
   113 	User::LeaveIfError(RSessionBase::SendReceive(EGetAttribute, TIpcArgs(&pckgAttr, &pckgVal)));
       
   114 	}
       
   115 
       
   116 
       
   117 EXPORT_C HBufC* RSraClient::GetStringAttributeLC(const TStringAttribute& aAttribute)
       
   118 /**
       
   119  	Gets the value of a requested string attribute listed in TStringAttribute enumeration.
       
   120  	
       
   121  	@param aAttribute The requested string attribute.
       
   122  	@return    A pointer to the value of the requested string attribute. 
       
   123  			   The ownership is transfered to the calling function.
       
   124  	@see StreamAccess::TStringAttribute
       
   125  */
       
   126 	{
       
   127 	TPckg<TStringAttribute> pckgStrAttr(aAttribute);
       
   128 	TInt size = 0;
       
   129 	TPckg<TInt> pckgSize(size);
       
   130 	User::LeaveIfError(RSessionBase::SendReceive(EGetStringAttributeSize, TIpcArgs(&pckgStrAttr, &pckgSize)));
       
   131 	
       
   132 	HBufC8* value8 = HBufC8::NewLC(size);
       
   133 	TPtr8 ptr8(value8->Des());
       
   134 	
       
   135 	User::LeaveIfError(RSessionBase::SendReceive(EGetStringAttributeData, TIpcArgs(&pckgStrAttr, &ptr8)));
       
   136 	
       
   137 	//Convert 8-bit to 16-bit
       
   138 	HBufC* value = HBufC::NewL(ptr8.Size());
       
   139 	TPtr ptr(value->Des());
       
   140 	ptr.Copy(ptr8);
       
   141 
       
   142 	CleanupStack::PopAndDestroy(value8);
       
   143 	CleanupStack::PushL(value);
       
   144 	return value;
       
   145 	}
       
   146 
       
   147 
       
   148 EXPORT_C void RSraClient::GetPostDeliveryRightsL(RFile& aFile, TDes8& aCid, TDes8& aRightsMimeType, TDes8& aContentMimeType)
       
   149 /**
       
   150  	@param aFile The file handle of the post-delivery rights object obtained from 
       
   151  		    	 the streaming reference agent server. The receiving party is responsible
       
   152  		    	 to close the file handle.
       
   153  	@param aCid  The content Id.
       
   154  	@param aRightsMimeType The mime type of the post-acquisition rights object.
       
   155 	@param aContentMimeType The mime type of the content.
       
   156  */
       
   157 	{
       
   158 	TInt fsh;			//session (RFs) handle
       
   159 	TPckgBuf<TInt> fh;	//subsession (RFile) handle
       
   160 	
       
   161 	//The message is completed with the file-server (RFs) session handle
       
   162 	//Pointer to the file subsession handle in slot 0
       
   163 	fsh = RSessionBase::SendReceive(EGetPostDeliveryRights, TIpcArgs(&fh, &aCid, &aRightsMimeType, &aContentMimeType));
       
   164 	User::LeaveIfError(fsh);
       
   165 	
       
   166 	// Adopt the file using the returned handles
       
   167 	User::LeaveIfError(aFile.AdoptFromServer(fsh,fh()));
       
   168 	}
       
   169 
       
   170 
       
   171 EXPORT_C void RSraClient::SendKeyStreamSinkL(const CKeyStreamSink& aSink) const
       
   172 /**
       
   173  	Sends a key stream sink object to the reference agent server.
       
   174  	@param aKey A key stream sink object.
       
   175  */
       
   176 	{
       
   177 	TPtr8 ptr(aSink.ExternalizeLC());
       
   178 	User::LeaveIfError(RSessionBase::SendReceive(ESetKeyStreamSink, TIpcArgs(&ptr)));
       
   179 	CleanupStack::PopAndDestroy(); // Delete the allocated buffer
       
   180 	}
       
   181 
       
   182 EXPORT_C void RSraClient::SendSdpMediaFieldL(const CSdpMediaField& aSdp) const
       
   183 /**
       
   184  	Sends an SDP media field object data to the reference agent server.
       
   185  	@param aKey An SDP object data.
       
   186  */
       
   187 	{
       
   188 	HBufC8* sdpBuf(0);
       
   189 	TPtr8 ptr(EncodeLC(aSdp, sdpBuf));
       
   190 	
       
   191 	User::LeaveIfError(RSessionBase::SendReceive(ESetSdpKeyStream, TIpcArgs(&ptr)));
       
   192 	CleanupStack::PopAndDestroy(sdpBuf);
       
   193 	}
       
   194 
       
   195 EXPORT_C void RSraClient::SendSdpDocumentL(const CSdpDocument& aSdpDoc) const
       
   196 /**
       
   197  	Sends an SDP document object data to the reference agent server.
       
   198  	@param aKey An SDP object data.
       
   199  */
       
   200 	{
       
   201 	HBufC8* sdpDocBuf(0);
       
   202 	TPtr8 ptr(EncodeLC(aSdpDoc, sdpDocBuf));
       
   203 	
       
   204 	User::LeaveIfError(RSessionBase::SendReceive(ESetSdpDocument, TIpcArgs(&ptr)));
       
   205 	CleanupStack::PopAndDestroy(sdpDocBuf);
       
   206 	}