accessoryservices/remotecontrolfw/client/extapi1/src/trackinfotarget.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2004-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 "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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include <bluetooth/logger.h>
       
    22 #include <e32base.h>
       
    23 #include <remcon/remconextapi1.h>
       
    24 #include <remcontrackinfotarget.h>
       
    25 #include <remcontrackinfotargetobserver.h>
       
    26 #include <remconinterfaceselector.h>
       
    27 
       
    28 #ifdef __FLOG_ACTIVE
       
    29 _LIT8(KLogComponent, LOG_COMPONENT_REMCON_EXTAPI1);
       
    30 #endif
       
    31 
       
    32 EXPORT_C CRemConTrackInfoTarget* CRemConTrackInfoTarget::NewL(CRemConInterfaceSelector& aInterfaceSelector, 
       
    33 																	MRemConTrackInfoTargetObserver& aObserver)
       
    34 	{
       
    35 	LOG_STATIC_FUNC
       
    36 
       
    37 	CRemConTrackInfoTarget* self = new(ELeave) CRemConTrackInfoTarget(aInterfaceSelector, aObserver);
       
    38 	CleanupStack::PushL(self);
       
    39 	self->BaseConstructL();
       
    40 	CleanupStack::Pop(self);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 CRemConTrackInfoTarget::CRemConTrackInfoTarget(CRemConInterfaceSelector& aInterfaceSelector, 
       
    45 													 MRemConTrackInfoTargetObserver& aObserver)
       
    46 :	CRemConInterfaceBase(TUid::Uid(KRemConTrackInfoApiUid), 
       
    47 						 KMaxName,
       
    48 						 aInterfaceSelector,
       
    49 						 ERemConClientTypeTarget),
       
    50 	iObserver(aObserver)
       
    51 	{
       
    52 	}
       
    53 
       
    54 EXPORT_C CRemConTrackInfoTarget::~CRemConTrackInfoTarget()
       
    55 	{
       
    56 	LOG_FUNC
       
    57 	}
       
    58 
       
    59 TAny* CRemConTrackInfoTarget::GetInterfaceIf(TUid aUid)
       
    60 	{
       
    61 	TAny* ret = NULL;
       
    62 	if ( aUid == TUid::Uid(KRemConInterfaceIf1) )
       
    63 		{
       
    64 		ret = reinterpret_cast<TAny*>(
       
    65 			static_cast<MRemConInterfaceIf*>(this)
       
    66 			);
       
    67 		}
       
    68 
       
    69 	return ret;
       
    70 	}
       
    71 
       
    72 #ifdef SYMBIAN_ENABLE_TRACKINFO_BACKTOBACK_TEST_FUNCT
       
    73 void CRemConTrackInfoTarget::MrcibNewMessage(TUint aOperationId, const TDesC8& aData)
       
    74 #else
       
    75 void CRemConTrackInfoTarget::MrcibNewMessage(TUint aOperationId, const TDesC8& /*aData*/)
       
    76 #endif //SYMBIAN_ENABLE_TRACKINFO_BACKTOBACK_TEST_FUNCT
       
    77 	{
       
    78 	LOG_FUNC
       
    79 	LOG1(_L("\taOperationId = 0x%02x"), aOperationId);
       
    80 
       
    81 	switch ( aOperationId )
       
    82 		{
       
    83 	case ERemConGetTrackName:
       
    84 		iObserver.MrctitoGetTrackName();
       
    85 		break;
       
    86 
       
    87 	case ERemConGetArtist:
       
    88 		iObserver.MrctitoGetArtist();
       
    89 		break;
       
    90 
       
    91 	case ERemConGetTrackDuration:
       
    92 		iObserver.MrctitoGetTrackDuration();
       
    93 		break;
       
    94 
       
    95 //Only used in the internal pan-shared back to back test builds. Should never be in a released product.
       
    96 #ifdef SYMBIAN_ENABLE_TRACKINFO_BACKTOBACK_TEST_FUNCT
       
    97 	case ERemConSetTrackName:
       
    98 		HandleSetTrackName(aData);
       
    99 		break;
       
   100 #endif //SYMBIAN_ENABLE_TRACKINFO_BACKTOBACK_TEST_FUNCT
       
   101 	
       
   102 	default:
       
   103 		break;
       
   104 		}
       
   105 	}
       
   106 
       
   107 EXPORT_C void CRemConTrackInfoTarget::GetTrackNameResponse(TRequestStatus& aStatus, const TDesC& aTrackName, TInt aError)
       
   108 	{
       
   109 	LOG_FUNC
       
   110 
       
   111 	// First copy aTrackName into a specific descriptor type to 
       
   112 	// nail down the structure as we don't know what type of 
       
   113 	// descriptor has been passed in. 
       
   114 	
       
   115 	// TBuf is restricted to 58 characters, this relates to the 
       
   116 	// amount of available space in iOutData.
       
   117 	TBuf<58> temp;
       
   118 	temp.Copy(aTrackName);
       
   119 
       
   120 	iOutData.Copy((TUint8*)&aError, KRemConExtApi1ResultDataLength);
       
   121 	
       
   122 	TPckgBuf<TName> buf(temp);
       
   123 	//Set buf to minimum required length
       
   124 	//Size of iLength + Size of iMaxLength + Size of aTrackName
       
   125 	//      4 Bytes   +        4 Bytes     +(Max. 58x2) 116 Bytes 
       
   126 	//                                     = 124 Bytes Max Size
       
   127 	buf.SetLength(sizeof(TUint) + sizeof(TUint) + temp.Size());
       
   128 	
       
   129 	iOutData.Append(buf);
       
   130 
       
   131 	// We pass iNumRemotes even though we're not interested in its value but 
       
   132 	// RemCon will write to this location so we need it to be somewhere safe.
       
   133 	InterfaceSelector().Send(aStatus, 
       
   134 		TUid::Uid(KRemConTrackInfoApiUid),
       
   135 		(TUint)ERemConGetTrackName, 
       
   136 		iNumRemotes,
       
   137 		ERemConResponse,
       
   138 		iOutData);
       
   139 	}
       
   140 
       
   141 EXPORT_C void CRemConTrackInfoTarget::GetArtistResponse(TRequestStatus& aStatus, const TDesC& aArtist, TInt aError)
       
   142 	{
       
   143 	LOG_FUNC
       
   144 
       
   145 	// First copy aArtist into a specific descriptor type to 
       
   146 	// nail down the structure as we don't know what type of 
       
   147 	// descriptor has been passed in. 
       
   148 	
       
   149 	// TBuf is restricted to 58 characters, this relates to the 
       
   150 	// amount of available space in iOutData.
       
   151 	TBuf<58> temp;
       
   152 	temp.Copy(aArtist);
       
   153 
       
   154 	iOutData.Copy((TUint8*)&aError, KRemConExtApi1ResultDataLength);
       
   155 	
       
   156 	TPckgBuf<TName> buf(temp);
       
   157 	//Set buf to minimum required length
       
   158 	//Size of iLength + Size of iMaxLength + Size of aTrackName
       
   159 	//      4 Bytes   +        4 Bytes     +(Max. 58x2) 116 Bytes 
       
   160 	//                                     = 124 Bytes Max Size
       
   161 	buf.SetLength(sizeof(TUint) + sizeof(TUint) + temp.Size());
       
   162 	
       
   163 	iOutData.Append(buf);
       
   164 
       
   165 	// We pass iNumRemotes even though we're not interested in its value but 
       
   166 	// RemCon will write to this location so we need it to be somewhere safe.
       
   167 	InterfaceSelector().Send(aStatus, 
       
   168 		TUid::Uid(KRemConTrackInfoApiUid),
       
   169 		(TUint)ERemConGetArtist, 
       
   170 		iNumRemotes,
       
   171 		ERemConResponse,
       
   172 		iOutData);
       
   173 	}
       
   174 
       
   175 EXPORT_C void CRemConTrackInfoTarget::GetTrackDurationResponse(TRequestStatus& aStatus, const TTime& aDuration, TInt aError)
       
   176 	{
       
   177 	LOG_FUNC
       
   178 
       
   179 	iOutData.Copy((TUint8*)&aError, KRemConExtApi1ResultDataLength);
       
   180 	TInt64 int64 = aDuration.Int64();
       
   181 	TPckgBuf<TInt64> buf(int64);
       
   182 	iOutData.Append(buf);
       
   183 
       
   184 	// We pass iNumRemotes even though we're not interested in its value but 
       
   185 	// RemCon will write to this location so we need it to be somewhere safe.
       
   186 	InterfaceSelector().Send(aStatus, 
       
   187 		TUid::Uid(KRemConTrackInfoApiUid),
       
   188 		(TUint)ERemConGetTrackDuration, 
       
   189 		iNumRemotes,
       
   190 		ERemConResponse,
       
   191 		iOutData);
       
   192 	}
       
   193 
       
   194 
       
   195 //Only used in the internal pan-shared back to back test builds. Should never be in a released product.
       
   196 #ifdef SYMBIAN_ENABLE_TRACKINFO_BACKTOBACK_TEST_FUNCT
       
   197 /**
       
   198 Sends a response to a 'set track name' command.
       
   199 	
       
   200 @param aStatus Used by RemCon to indicate completion of the send request.
       
   201 @param aError The response error.
       
   202 */
       
   203 EXPORT_C void CRemConTrackInfoTarget::SetTrackNameResponse(TRequestStatus& aStatus, TInt aError)
       
   204 	{
       
   205 	LOG_FUNC
       
   206 	
       
   207 	iOutData.Copy((TUint8*)&aError, KRemConExtApi1ResultDataLength);
       
   208 
       
   209 	InterfaceSelector().Send(aStatus,
       
   210 		TUid::Uid(KRemConTrackInfoApiUid),
       
   211 		(TUint)ERemConSetTrackName,
       
   212 		iNumRemotes,
       
   213 		ERemConResponse,
       
   214 		iOutData);	
       
   215 	}
       
   216 
       
   217 /**
       
   218 Extracts the track name from the 'set track name' command data and calls 
       
   219 the relevant mixin function on the observer.
       
   220 	
       
   221 @param aData The data passed with the command.
       
   222 */	
       
   223 void CRemConTrackInfoTarget::HandleSetTrackName(const TDesC8& aData)
       
   224 	{
       
   225 	LOG_FUNC
       
   226 
       
   227 	TPckgBuf<TName> buf;
       
   228 	buf.Copy((aData.Mid(KRemConExtApi1ResultDataLength)));
       
   229 	iObserver.MrctitoSetTrackName(buf());
       
   230 	}
       
   231 #endif //SYMBIAN_ENABLE_TRACKINFO_BACKTOBACK_TEST_FUNCT