|
1 /* |
|
2 * Copyright (c) 2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <liwgenericparam.h> |
|
20 |
|
21 #include "cpliwmap.h" |
|
22 #include "cpclient.h" |
|
23 #include "cpserverdef.h" |
|
24 #include "cpdebug.h" |
|
25 #include "cpclientactivenotifier.h" |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CCPClient::CCPClient() |
|
34 { |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 void CCPClient::ConstructL() |
|
42 { |
|
43 |
|
44 #ifdef CONTENT_PUBLISHER_DEBUG |
|
45 if(!CCPDebug::Enable()) |
|
46 { |
|
47 iDebug = CCPDebug::NewL( KCPDebugFileName ); |
|
48 } |
|
49 #endif |
|
50 CP_DEBUG( _L8("CCPClient::ConstructL()") ); |
|
51 User::LeaveIfError( iServerClient.Connect( ) ); |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CCPClient* CCPClient::NewL() |
|
59 { |
|
60 CCPClient* self = CCPClient::NewLC( ); |
|
61 CleanupStack::Pop( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CCPClient* CCPClient::NewLC() |
|
70 { |
|
71 CCPClient* self = new( ELeave ) CCPClient; |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL( ); |
|
74 return self; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CCPClient::~CCPClient() |
|
82 { |
|
83 CP_DEBUG( _L8("CCPClient::~CCPClient()") ); |
|
84 delete iActiveNotifier; |
|
85 iServerClient.Close( ); |
|
86 #ifdef CONTENT_PUBLISHER_DEBUG |
|
87 delete iDebug; |
|
88 #endif |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CCPClient::GetListL( const CLiwGenericParamList& aInParamList, |
|
96 CLiwGenericParamList& aOutParamList ) |
|
97 { |
|
98 CP_DEBUG( _L8("CCPClient::GetListL()") ); |
|
99 CP_EXTENDED_DEBUG( "GetListL()" , aInParamList ); |
|
100 CheckMapL( aInParamList, KFilter ); |
|
101 CCPLiwMap* inMapForServer = CCPLiwMap::NewL( aInParamList ); |
|
102 inMapForServer->PushL( ); |
|
103 inMapForServer->IsValidForGetListL( ); |
|
104 iServerClient.GetListL( *inMapForServer, aOutParamList ); |
|
105 CleanupStack::PopAndDestroy( inMapForServer ); |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CCPClient::AddL( const CLiwGenericParamList& aInParamList, |
|
113 CLiwGenericParamList& aOutParamList, |
|
114 TUint aCmdOptions ) |
|
115 { |
|
116 CP_DEBUG( _L8("CCPClient::AddL()") ); |
|
117 CP_EXTENDED_DEBUG( "Add()" , aInParamList ); |
|
118 CheckMapL( aInParamList, KItem ); |
|
119 CCPLiwMap* inMapForServer = CCPLiwMap::NewL( aInParamList ) ; |
|
120 inMapForServer->PushL( ); |
|
121 inMapForServer->IsValidForAddL( ); |
|
122 iServerClient.AddL( *inMapForServer, aOutParamList, aCmdOptions ); |
|
123 CleanupStack::PopAndDestroy( inMapForServer ); |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CCPClient::DeleteL( const CLiwGenericParamList& aInParamList ) |
|
131 { |
|
132 CP_DEBUG( _L8("CCPClient::DeleteL()") ); |
|
133 CP_EXTENDED_DEBUG( "Delete()" , aInParamList ); |
|
134 CheckMapL( aInParamList, KData ); |
|
135 CCPLiwMap* inMapForServer = CCPLiwMap::NewL( aInParamList ); |
|
136 inMapForServer->PushL( ); |
|
137 inMapForServer->IsValidForDeleteL( ); |
|
138 iServerClient.DeleteL( *inMapForServer ); |
|
139 CleanupStack::PopAndDestroy( inMapForServer ); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CCPClient::RegisterObserverL( MLiwNotifyCallback* aObserver, |
|
147 const CLiwGenericParamList& aInParamList, |
|
148 TInt32 aTransactionId, |
|
149 TUint aCmdOptions ) |
|
150 { |
|
151 CP_DEBUG( _L8("CCPClient::RegisterObserverL()") ); |
|
152 CP_EXTENDED_DEBUG( "RegisterObserver()" , aInParamList ); |
|
153 CheckMapL( aInParamList, KFilter ); |
|
154 CCPLiwMap* inMapForServer = CCPLiwMap::NewL( aInParamList ); |
|
155 inMapForServer->PushL( ); |
|
156 inMapForServer->IsValidForNotificationL( ); |
|
157 if ( !iActiveNotifier ) |
|
158 { |
|
159 iActiveNotifier = CCPActiveNotifier::NewL( iServerClient ); |
|
160 } |
|
161 iActiveNotifier->RegisterL( aObserver, aTransactionId, inMapForServer, |
|
162 aCmdOptions ); |
|
163 CleanupStack::PopAndDestroy( inMapForServer ); |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 void CCPClient::UnregisterObserversL( const CLiwGenericParamList& aInParamList ) |
|
171 { |
|
172 CP_DEBUG( _L8("CCPClient::UnregisterObservers()") ); |
|
173 CP_EXTENDED_DEBUG( "UnregisterObservers()" , aInParamList ); |
|
174 if ( !iActiveNotifier ) |
|
175 { |
|
176 User::Leave( KErrNotFound ); |
|
177 } |
|
178 TInt32 transactionId( -1 ); |
|
179 const TLiwGenericParam* param = NULL; |
|
180 TInt pos( 0 ); |
|
181 param = aInParamList.FindFirst( pos, KTransactionID ); |
|
182 if( !param || |
|
183 pos == KErrNotFound || |
|
184 !param->Value().Get( transactionId ) || |
|
185 transactionId < 0 ) |
|
186 { |
|
187 iActiveNotifier->UnregisterAllL( ); |
|
188 delete iActiveNotifier; |
|
189 iActiveNotifier = NULL; |
|
190 } |
|
191 else |
|
192 { |
|
193 if( iActiveNotifier->UnregisterL( transactionId ) ) |
|
194 { |
|
195 //delete only if it was the last observer |
|
196 delete iActiveNotifier; |
|
197 iActiveNotifier = NULL; |
|
198 } |
|
199 } |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CCPClient::ExecuteActionL( const CLiwGenericParamList& aInParamList, |
|
207 TUint aCmdOptions) |
|
208 { |
|
209 CP_DEBUG( _L8("CCPClient::ExecuteActionL()") ); |
|
210 CP_EXTENDED_DEBUG( "ExecuteAction()" , aInParamList ); |
|
211 CheckMapL( aInParamList, KFilter ); |
|
212 CCPLiwMap* inMapForServer = CCPLiwMap::NewL( aInParamList ); |
|
213 inMapForServer->PushL( ); |
|
214 inMapForServer->IsValidForActionL( ); |
|
215 iServerClient.ExecuteActionL( *inMapForServer, aCmdOptions ); |
|
216 CleanupStack::PopAndDestroy( inMapForServer ); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CCPClient::ExecuteMultipleActionsL( |
|
224 const CLiwGenericParamList& aInParamList, TUint aCmdOptions) |
|
225 { |
|
226 CP_DEBUG( _L8("CCPClient::ExecuteMultipleActionsL()") ); |
|
227 CP_EXTENDED_DEBUG( "ExecuteMultipleActionsL()" , aInParamList ); |
|
228 CheckMultiExecuteInputParamsL(aInParamList); |
|
229 iServerClient.ExecuteMultipleActionsL( aInParamList, aCmdOptions ); |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CCPClient::CheckMapL( const CLiwGenericParamList& aInParamList, |
|
237 const TDesC8& aKey ) |
|
238 { |
|
239 const TLiwGenericParam* param = NULL; |
|
240 TInt pos( 0 ); |
|
241 param = aInParamList.FindFirst( pos, aKey ); |
|
242 if( pos !=KErrNotFound ) |
|
243 { |
|
244 if( param->Value().TypeId( ) != LIW::EVariantTypeMap ) |
|
245 { |
|
246 User::Leave( KErrBadName ); |
|
247 } |
|
248 } |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 // --------------- -------------------------------------------------------------- |
|
254 // |
|
255 void CCPClient::CheckMultiExecuteInputParamsL( |
|
256 const CLiwGenericParamList& aList) |
|
257 { |
|
258 const TLiwGenericParam* param = NULL; |
|
259 TInt pos(0); |
|
260 param = aList.FindFirst(pos, KFilters); |
|
261 User::LeaveIfError(pos); //leaves if not found |
|
262 if (param->Value().TypeId() != LIW::EVariantTypeList) |
|
263 { |
|
264 User::Leave(KErrBadName); |
|
265 } |
|
266 } |