1 // Copyright (c) 2010 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 "cmtppbcresetdevicepropvalue.h" |
|
22 #include "mtpplaybackcontroldpconst.h" |
|
23 #include "cmtpplaybackcontroldp.h" |
|
24 #include "cmtpplaybackproperty.h" |
|
25 #include "cmtpplaybackcommand.h" |
|
26 #include "mtpplaybackcontrolpanic.h" |
|
27 |
|
28 // Class constants. |
|
29 __FLOG_STMT(_LIT8(KComponent,"ResetPlaybackDevicePropValue");) |
|
30 |
|
31 /** |
|
32 Two-phase constructor. |
|
33 @param aPlugin The data provider plugin |
|
34 @param aFramework The data provider framework |
|
35 @param aConnection The connection from which the request comes |
|
36 @return a pointer to the created request processor object. |
|
37 */ |
|
38 MMTPRequestProcessor* CMTPPbcResetDevicePropValue::NewL(MMTPDataProviderFramework& aFramework, |
|
39 MMTPConnection& aConnection, |
|
40 CMTPPlaybackControlDataProvider& aDataProvider) |
|
41 { |
|
42 CMTPPbcResetDevicePropValue* self = new (ELeave) CMTPPbcResetDevicePropValue(aFramework, aConnection, aDataProvider); |
|
43 return self; |
|
44 } |
|
45 |
|
46 /** |
|
47 Destructor |
|
48 */ |
|
49 CMTPPbcResetDevicePropValue::~CMTPPbcResetDevicePropValue() |
|
50 { |
|
51 __FLOG(_L8("~CMTPPbcResetDevicePropValue - Entry")); |
|
52 delete iPbCmd; |
|
53 __FLOG(_L8("~CMTPPbcResetDevicePropValue - Exit")); |
|
54 __FLOG_CLOSE; |
|
55 } |
|
56 |
|
57 /** |
|
58 Standard c++ constructor |
|
59 */ |
|
60 CMTPPbcResetDevicePropValue::CMTPPbcResetDevicePropValue(MMTPDataProviderFramework& aFramework, |
|
61 MMTPConnection& aConnection, |
|
62 CMTPPlaybackControlDataProvider& aDataProvider): |
|
63 CMTPRequestProcessor(aFramework, aConnection, 0, NULL), |
|
64 iPlaybackControlDp(aDataProvider) |
|
65 { |
|
66 //Open the log system |
|
67 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
68 } |
|
69 |
|
70 /** |
|
71 SetDevicePropValue request validator. |
|
72 @return EMTPRespCodeOK if request is verified, otherwise one of the error response codes |
|
73 */ |
|
74 TMTPResponseCode CMTPPbcResetDevicePropValue::CheckRequestL() |
|
75 { |
|
76 __FLOG(_L8("CheckRequestL - Entry")); |
|
77 TMTPResponseCode respCode = CMTPRequestProcessor::CheckRequestL(); |
|
78 if(respCode == EMTPRespCodeOK) |
|
79 { |
|
80 respCode = EMTPRespCodeDevicePropNotSupported; |
|
81 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
82 const TInt count = sizeof(KMTPPlaybackControlDpSupportedProperties) / sizeof(KMTPPlaybackControlDpSupportedProperties[0]); |
|
83 for (TUint i(0); (i < count); i++) |
|
84 { |
|
85 if (propCode == KMTPPlaybackControlDpSupportedProperties[i]) |
|
86 { |
|
87 respCode = EMTPRespCodeOK; |
|
88 break; |
|
89 } |
|
90 } |
|
91 } |
|
92 |
|
93 __FLOG(_L8("CheckRequestL - Exit")); |
|
94 return respCode; |
|
95 } |
|
96 /** |
|
97 ResetDevicePropValue request handler. |
|
98 */ |
|
99 void CMTPPbcResetDevicePropValue::ServiceL() |
|
100 { |
|
101 __FLOG(_L8("ServiceL - Entry")); |
|
102 |
|
103 CMTPPlaybackMap& map(iPlaybackControlDp.GetPlaybackMap()); |
|
104 //Destroy the previous playback command. |
|
105 delete iPbCmd; |
|
106 iPbCmd = NULL; |
|
107 |
|
108 //Get a new playback command. |
|
109 iData.iOptCode = EMTPOpCodeResetDevicePropValue; |
|
110 TMTPDevicePropertyCode propCode(static_cast<TMTPDevicePropertyCode>(Request(). |
|
111 Uint32(TMTPTypeRequest::ERequestParameter1))); |
|
112 iData.iDevPropCode = propCode; |
|
113 CMTPPlaybackProperty& property(iPlaybackControlDp.GetPlaybackProperty()); |
|
114 property.GetDefaultPropertyValueL(iData); |
|
115 |
|
116 TInt result = map.GetPlaybackControlCommand(iData, &iPbCmd); |
|
117 |
|
118 if(KErrNone == result) |
|
119 { |
|
120 MMTPPlaybackControl& control(iPlaybackControlDp.GetPlaybackControlL()); |
|
121 TRAPD(err, control.CommandL(*iPbCmd, this)); |
|
122 __ASSERT_ALWAYS((err == KErrNone), SendResponseL(EMTPRespCodeParameterNotSupported)); |
|
123 } |
|
124 else if(KErrNotSupported == result) |
|
125 { |
|
126 SendResponseL(EMTPRespCodeDevicePropNotSupported); |
|
127 } |
|
128 else |
|
129 { |
|
130 SendResponseL(EMTPRespCodeParameterNotSupported); |
|
131 } |
|
132 |
|
133 __FLOG(_L8("ServiceL - Exit")); |
|
134 } |
|
135 |
|
136 void CMTPPbcResetDevicePropValue::HandlePlaybackCommandCompleteL(CMTPPlaybackCommand* aCmd, TInt aErr) |
|
137 { |
|
138 __FLOG(_L8("HandlePlaybackCommandCompleteL - Entry")); |
|
139 __FLOG_1(_L8("aErr %d"), aErr); |
|
140 |
|
141 //Handle error response. |
|
142 TMTPResponseCode response; |
|
143 switch(aErr) |
|
144 { |
|
145 case KPlaybackErrNone: |
|
146 { |
|
147 response = EMTPRespCodeOK; |
|
148 } |
|
149 break; |
|
150 case KPlaybackErrDeviceUnavailable: |
|
151 { |
|
152 response = EMTPRespCodeDeviceBusy; |
|
153 iPlaybackControlDp.RequestToResetPbCtrl(); |
|
154 } |
|
155 break; |
|
156 case KPlaybackErrContextInvalid: |
|
157 { |
|
158 response = EMTPRespCodeAccessDenied; |
|
159 } |
|
160 break; |
|
161 default: |
|
162 { |
|
163 response = EMTPRespCodeDeviceBusy; |
|
164 } |
|
165 break; |
|
166 } |
|
167 |
|
168 SendResponseL(response); |
|
169 |
|
170 if(aCmd != NULL) |
|
171 { |
|
172 __ASSERT_DEBUG((aCmd->PlaybackCommand() == iPbCmd->PlaybackCommand()), Panic(EMTPPBArgumentErr)); |
|
173 __FLOG_1(_L8("aCmd %d"), aCmd->PlaybackCommand()); |
|
174 } |
|
175 |
|
176 __FLOG(_L8("HandlePlaybackCommandCompleteL - Exit")); |
|
177 } |
|