|
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 <remconabsvolcontroller.h> |
|
25 #include <remconabsvolcontrollerobserver.h> |
|
26 #include <remconinterfaceselector.h> |
|
27 #include "absvolutils.h" |
|
28 |
|
29 #ifdef __FLOG_ACTIVE |
|
30 _LIT8(KLogComponent, LOG_COMPONENT_REMCON_EXTAPI1); |
|
31 #endif |
|
32 |
|
33 // Used to pad over the results field in the operation-specific data. |
|
34 _LIT8(KResultsPad, " "); |
|
35 |
|
36 EXPORT_C CRemConAbsVolController* CRemConAbsVolController::NewL(CRemConInterfaceSelector& aInterfaceSelector, |
|
37 MRemConAbsVolControllerObserver& aObserver) |
|
38 { |
|
39 LOG_STATIC_FUNC |
|
40 |
|
41 CRemConAbsVolController* self = new(ELeave) CRemConAbsVolController(aInterfaceSelector, aObserver); |
|
42 CleanupStack::PushL(self); |
|
43 self->BaseConstructL(); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 CRemConAbsVolController::CRemConAbsVolController(CRemConInterfaceSelector& aInterfaceSelector, |
|
49 MRemConAbsVolControllerObserver& aObserver) |
|
50 : CRemConInterfaceBase(TUid::Uid(KRemConAbsVolApiUid), |
|
51 KMaxOperationDataSize, |
|
52 aInterfaceSelector, |
|
53 ERemConClientTypeController), |
|
54 iObserver(aObserver) |
|
55 { |
|
56 } |
|
57 |
|
58 EXPORT_C CRemConAbsVolController::~CRemConAbsVolController() |
|
59 { |
|
60 LOG_FUNC |
|
61 } |
|
62 |
|
63 TAny* CRemConAbsVolController::GetInterfaceIf(TUid aUid) |
|
64 { |
|
65 TAny* ret = NULL; |
|
66 if ( aUid == TUid::Uid(KRemConInterfaceIf1) ) |
|
67 { |
|
68 ret = reinterpret_cast<TAny*>( |
|
69 static_cast<MRemConInterfaceIf*>(this) |
|
70 ); |
|
71 } |
|
72 |
|
73 return ret; |
|
74 } |
|
75 |
|
76 void CRemConAbsVolController::MrcibNewMessage(TUint aOperationId, const TDesC8& aData) |
|
77 { |
|
78 LOG_FUNC |
|
79 LOG1(_L("\taOperationId = 0x%02x"), aOperationId); |
|
80 LOG1(_L("\taData.Length = %d"), aData.Length()); |
|
81 |
|
82 // Get the response error out of aData. |
|
83 if ( aData.Length() < KRemConExtApi1MinimumDataLength ) |
|
84 { |
|
85 return; // ditch malformed messages |
|
86 } |
|
87 TInt err = static_cast<TInt>(aData.Ptr()[0]); |
|
88 |
|
89 switch ( aOperationId ) |
|
90 { |
|
91 case ERemConGetAbsoluteVolume: |
|
92 { |
|
93 // 20 is the length of the abs volume data- 10 bytes for each of two |
|
94 // '0x%08x'-formatted fields. |
|
95 if ( aData.Length() < KRemConExtApi1MinimumDataLength + 20 ) |
|
96 { |
|
97 //Silently drop the message |
|
98 LOG(_L("Warning: Message is dropped due to invalid length!")); |
|
99 __DEBUGGER(); |
|
100 return; |
|
101 } |
|
102 TUint absVol; |
|
103 TUint maxVol; |
|
104 if ( GetAbsMaxVol(aData.Mid(KRemConExtApi1MinimumDataLength, 20), absVol, maxVol) == KErrNone ) |
|
105 { |
|
106 iObserver.MrcavcoGetAbsoluteVolumeResponse(absVol, maxVol, err); |
|
107 } |
|
108 } |
|
109 break; |
|
110 |
|
111 case ERemConSetAbsoluteVolume: |
|
112 iObserver.MrcavcoSetAbsoluteVolumeResponse(err); |
|
113 break; |
|
114 |
|
115 default: |
|
116 break; |
|
117 } |
|
118 } |
|
119 |
|
120 EXPORT_C void CRemConAbsVolController::GetAbsoluteVolume(TRequestStatus& aStatus, |
|
121 TUint& aNumRemotes) |
|
122 { |
|
123 LOG_FUNC |
|
124 |
|
125 InterfaceSelector().Send(aStatus, |
|
126 TUid::Uid(KRemConAbsVolApiUid), |
|
127 (TUint)ERemConGetAbsoluteVolume, |
|
128 aNumRemotes, |
|
129 ERemConCommand, |
|
130 KNullDesC8()); |
|
131 } |
|
132 |
|
133 EXPORT_C void CRemConAbsVolController::SetAbsoluteVolume(TRequestStatus& aStatus, |
|
134 TUint aAbsVol, |
|
135 TUint aMaxVol, |
|
136 TUint& aNumRemotes) |
|
137 { |
|
138 LOG_FUNC |
|
139 |
|
140 iOutData.Copy(KResultsPad()); |
|
141 iOutData.AppendFormat(_L8("0x%08x0x%08x"), aAbsVol, aMaxVol); |
|
142 |
|
143 InterfaceSelector().Send(aStatus, |
|
144 TUid::Uid(KRemConAbsVolApiUid), |
|
145 (TUint)ERemConSetAbsoluteVolume, |
|
146 aNumRemotes, |
|
147 ERemConCommand, |
|
148 iOutData); |
|
149 } |