1 // Copyright (c) 2008-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 @publishedAll |
|
19 @released |
|
20 */ |
|
21 |
|
22 #include <bluetooth/logger.h> |
|
23 #include <remconbatterytarget.h> |
|
24 #include <remconbatterytargetobserver.h> |
|
25 #include <remcon/avrcpspec.h> |
|
26 #include <remconinterfaceselector.h> |
|
27 |
|
28 #include "remconbattery.h" |
|
29 |
|
30 #ifdef __FLOG_ACTIVE |
|
31 _LIT8(KLogComponent, LOG_COMPONENT_AVRCP_BATTERY_STATUS); |
|
32 #endif |
|
33 |
|
34 EXPORT_C CRemConBatteryApiTarget* CRemConBatteryApiTarget::NewL(CRemConInterfaceSelector& aInterfaceSelector, |
|
35 MRemConBatteryTargetObserver& aObserver) |
|
36 { |
|
37 LOG_STATIC_FUNC |
|
38 |
|
39 CRemConBatteryApiTarget* self = new(ELeave) CRemConBatteryApiTarget(aInterfaceSelector, aObserver); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 CRemConBatteryApiTarget::CRemConBatteryApiTarget(CRemConInterfaceSelector& aInterfaceSelector, |
|
47 MRemConBatteryTargetObserver& aObserver) |
|
48 : CRemConInterfaceBase(TUid::Uid(KRemConBatteryApiUid), |
|
49 KLengthBatteryStatusMsg, |
|
50 aInterfaceSelector, |
|
51 ERemConClientTypeTarget), |
|
52 iObserver(aObserver) |
|
53 { |
|
54 } |
|
55 |
|
56 void CRemConBatteryApiTarget::ConstructL() |
|
57 { |
|
58 // Create a output buffer (arbitrary value of 32 for granularity of buffer expansion) |
|
59 iOutData = CBufFlat::NewL(32); |
|
60 |
|
61 // allocate a output buffer big enough for a TRemConBatteryApiResponse |
|
62 iOutData->SetReserveL(sizeof(TPckg<TRemConBatteryApiResponse>)); //do this now for easier writing to buffer |
|
63 BaseConstructL(); |
|
64 } |
|
65 |
|
66 EXPORT_C CRemConBatteryApiTarget::~CRemConBatteryApiTarget() |
|
67 { |
|
68 delete iOutData; |
|
69 } |
|
70 |
|
71 /** Gets a pointer to a specific interface version. |
|
72 @return A pointer to the interface, NULL if not supported. |
|
73 @internalComponent |
|
74 @released |
|
75 */ |
|
76 TAny* CRemConBatteryApiTarget::GetInterfaceIf(TUid aUid) |
|
77 { |
|
78 TAny* ret = NULL; |
|
79 if ( aUid == TUid::Uid(KRemConInterfaceIf1) ) |
|
80 { |
|
81 ret = reinterpret_cast<TAny*>( |
|
82 static_cast<MRemConInterfaceIf*>(this) |
|
83 ); |
|
84 } |
|
85 |
|
86 return ret; |
|
87 } |
|
88 |
|
89 // from MRemConInterfaceIf |
|
90 void CRemConBatteryApiTarget::MrcibNewMessage(TUint /* aOperationId */, const TDesC8& aData) |
|
91 { |
|
92 // don't bother to log the operation ID as this was causing a build warning |
|
93 LOG1(_L("\taInformBatteryStatusOfCT Data.Length = %d"), aData.Length()); |
|
94 |
|
95 TRemConBatteryApiResponse batteryApiResponse; |
|
96 batteryApiResponse.iError = KErrNone; |
|
97 iOutData->Reset(); |
|
98 |
|
99 // check for malformed messages, there should be 1 byte of data |
|
100 if ( aData.Length() == 1 ) |
|
101 { |
|
102 // check the battery status is validvalue to the client observer |
|
103 if ( aData[0] <= EFullCharge ) |
|
104 { |
|
105 TControllerBatteryStatus value = (TControllerBatteryStatus)aData[0]; |
|
106 iObserver.MrcbstoBatteryStatus(value); |
|
107 } |
|
108 else |
|
109 { |
|
110 LOG(_L("\tMalformed message, data out range")); |
|
111 batteryApiResponse.iError = KErrAvrcpMetadataInvalidParameter; |
|
112 } |
|
113 } |
|
114 else |
|
115 { |
|
116 LOG(_L("\tMalformed message, data missing")); |
|
117 batteryApiResponse.iError = KErrAvrcpMetadataParameterNotFound; |
|
118 } |
|
119 |
|
120 // send a response to remcon (if OOM silently drop message) |
|
121 TRAPD(error, iOutData->ResizeL(sizeof(TRemConBatteryApiResponse))); |
|
122 if (error == KErrNone) |
|
123 { |
|
124 iOutData->Write(0,TPckg<TRemConBatteryApiResponse>(batteryApiResponse)); |
|
125 InterfaceSelector().SendUnreliable(TUid::Uid(KRemConBatteryApiUid), |
|
126 EInformBatteryStatusOfCT, ERemConResponse, iOutData->Ptr(0)); |
|
127 } |
|
128 } |
|
129 |
|