|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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 "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: CUpnpMetadataCommand |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "upnpmetadatacommand.h" |
|
20 |
|
21 #include "upnppathresolver.h" |
|
22 #include "upnppathelement.h" |
|
23 #include "upnpavcpmanager.h" |
|
24 #include "upnpavcontrolpoint.h" |
|
25 |
|
26 #include "upnpavcpenginehelper.h" |
|
27 using namespace UpnpAVCPEngine; |
|
28 |
|
29 #include "upnpstring.h" |
|
30 |
|
31 |
|
32 _LIT8(KFilterFlag, "*"); |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CUpnpMetadataCommand::NewL |
|
36 // Two-phased constructor. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CUpnpMetadataCommand* CUpnpMetadataCommand::NewL(CUpnpAVCPManager& aAVCPManager, CUpnpAVCPEngineSession& aSession, const RMessage2& aMessage) |
|
40 { |
|
41 CUpnpMetadataCommand* self = new( ELeave ) CUpnpMetadataCommand(aAVCPManager, aSession, aMessage); |
|
42 |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop( self ); |
|
46 |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CUpnpMetadataCommand::ConstructL |
|
52 // Symbian 2nd phase constructor can leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void CUpnpMetadataCommand::ConstructL() |
|
56 { |
|
57 CUpnpCommand::BaseConstructL(); |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CUpnpMetadataCommand::CUpnpMetadataCommand |
|
62 // C++ default constructor can NOT contain any code, that |
|
63 // might leave. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CUpnpMetadataCommand::CUpnpMetadataCommand(CUpnpAVCPManager& aAVCPManager, |
|
67 CUpnpAVCPEngineSession& aSession, |
|
68 const RMessage2& aMessage): |
|
69 CUpnpCommand( aAVCPManager, |
|
70 aSession, |
|
71 aMessage) |
|
72 { |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CUpnpMetadataCommand::~CUpnpMetadataCommand |
|
77 // desctructor |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CUpnpMetadataCommand::~CUpnpMetadataCommand() |
|
81 { |
|
82 delete iObjectId; |
|
83 delete iResult; |
|
84 delete iOldMetadata; |
|
85 delete iNewMetadata; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CUpnpMetadataCommand::SessionId |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TInt CUpnpMetadataCommand::SessionId() |
|
93 { |
|
94 return CUpnpCommand::SessionId(); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CUpnpMetadataCommand::RunError |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void CUpnpMetadataCommand::RunError(TInt aErrorCode) |
|
102 { |
|
103 return CUpnpCommand::RunError(aErrorCode); |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CUpnpMetadataCommand::ExecuteL |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void CUpnpMetadataCommand::ExecuteL() |
|
111 { |
|
112 //ASSERT(iType == EPrepareMetadata || iType == ESetMetadata); |
|
113 |
|
114 HBufC8* uuid = NULL; |
|
115 HBufC8* path = NULL; |
|
116 if (iType == EPrepareMetadata) |
|
117 { |
|
118 DEBUGSTRING(("Execute Metadata command (EPrepareMetadata)")); |
|
119 // set command id |
|
120 TPckg<TInt> numPckg(iId); |
|
121 iMessage.WriteL(0, numPckg); |
|
122 |
|
123 uuid = ReadDes8FromMessageLC(2); |
|
124 DEBUGSTRING8((" uuid: %S",uuid)); |
|
125 path = ReadDes8FromMessageLC(3); |
|
126 DEBUGSTRING8((" path: %S",path)); |
|
127 } |
|
128 else |
|
129 { |
|
130 DEBUGSTRING(("Execute Metadata command (ESetMetadata)")); |
|
131 uuid = ReadDes8FromMessageLC(0); |
|
132 DEBUGSTRING8((" uuid: %S",uuid)); |
|
133 path = ReadDes8FromMessageLC(1); |
|
134 DEBUGSTRING8((" path: %S",path)); |
|
135 |
|
136 HBufC8* old = ReadDes8FromMessageLC(2); |
|
137 iOldMetadata = UpnpString::EncodeXmlStringL(old); |
|
138 CleanupStack::PopAndDestroy( old ); |
|
139 |
|
140 HBufC8* newXML = ReadDes8FromMessageLC(3); |
|
141 iNewMetadata = UpnpString::EncodeXmlStringL( newXML ); |
|
142 CleanupStack::PopAndDestroy( newXML); |
|
143 } |
|
144 |
|
145 iPathResolver = &(iAVCPManager.PathResolverL(*uuid, &iSession)); |
|
146 |
|
147 iPathResolver->ResolveIdL(*path, *this); |
|
148 |
|
149 CleanupStack::PopAndDestroy(path); |
|
150 CleanupStack::PopAndDestroy(uuid); |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CUpnpMetadataCommand::SetResultL |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CUpnpMetadataCommand::SetResultL(const RMessage2& aMessage) |
|
158 { |
|
159 //ASSERT(aMessage.Function() == EDownloadMetadata); |
|
160 if (iResult) |
|
161 { |
|
162 TPtr8 result = iResult->Des(); |
|
163 aMessage.WriteL(1, result); |
|
164 } |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CUpnpMetadataCommand::Interpret |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 void CUpnpMetadataCommand::InterpretL(TInt aErrorCode, CUpnpAction* aAction) |
|
172 { |
|
173 DEBUGSTRING(("Interpret action response %d", aErrorCode)); |
|
174 if (aErrorCode == EHttp200Ok) |
|
175 { |
|
176 |
|
177 if (iType == EPrepareMetadata) |
|
178 { |
|
179 iResult = aAction->ArgumentValue( KResult ).AllocL(); |
|
180 TInt num = iResult->Length(); |
|
181 TPckg<TInt> numPckg(num); |
|
182 // size of metadata information |
|
183 iMessage.WriteL(1, numPckg); |
|
184 iMessage.Complete(KErrNone); |
|
185 // don't destroy and wait for next command |
|
186 } |
|
187 else |
|
188 { |
|
189 // for set metadata |
|
190 iMessage.Complete(KErrNone); |
|
191 delete this; |
|
192 } |
|
193 |
|
194 } |
|
195 else |
|
196 { |
|
197 iMessage.Complete(KErrAbort); |
|
198 delete this; |
|
199 } |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CUpnpMetadataCommand::ResolvedId |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CUpnpMetadataCommand::ResolvedIdL(TInt aErrCode, CUpnpPathElement* aIdElement) |
|
207 { |
|
208 |
|
209 if (aErrCode == KErrNone) |
|
210 { |
|
211 iObjectId = aIdElement->Id().AllocL(); |
|
212 if (iType == EPrepareMetadata) |
|
213 { |
|
214 iSessionId = iAVCPManager.CdsBrowseActionL(iPathResolver->UUID(), *iObjectId, KBrowseMetadata, KFilterFlag, 0, 0, KNullDesC8); |
|
215 } |
|
216 else //set metadata |
|
217 { |
|
218 iSessionId = iAVCPManager.CdsUpdateObjectActionL(iPathResolver->UUID(), *iObjectId, *iOldMetadata, *iNewMetadata); |
|
219 delete iOldMetadata; |
|
220 iOldMetadata = NULL; |
|
221 delete iNewMetadata; |
|
222 iNewMetadata = NULL; |
|
223 } |
|
224 iAVCPManager.RegisterForAction(*this); |
|
225 } |
|
226 else |
|
227 { |
|
228 iMessage.Complete(KErrNotFound); |
|
229 delete this; |
|
230 } |
|
231 } |
|
232 // End of File |