40
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2010 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: This class handles services management requests.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include "SrcsServiceManager.h"
|
|
22 |
#include "debug.h"
|
|
23 |
#include <e32property.h>
|
|
24 |
#include "obexservicemanprop.h"
|
|
25 |
|
|
26 |
|
|
27 |
// CONSTANTS
|
|
28 |
|
|
29 |
// The granularity of the array used to hold BT, IrDA and USB connnection objects
|
|
30 |
static const TInt KConnectionArrayGranularity = 4;
|
|
31 |
|
|
32 |
const TUint32 KObexSMSid = {0x101F7C87};
|
|
33 |
static _LIT_SECURITY_POLICY_S0(KObexSMOnlyPolicy,KObexSMSid);
|
|
34 |
static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
|
|
35 |
|
|
36 |
// ================= MEMBER FUNCTIONS =======================
|
|
37 |
|
|
38 |
|
|
39 |
// ---------------------------------------------------------
|
|
40 |
// C++ default constructor can NOT contain any code, that
|
|
41 |
// might leave.
|
|
42 |
// ---------------------------------------------------------
|
|
43 |
//
|
|
44 |
CSrcsServiceManager::CSrcsServiceManager():CActive(CActive::EPriorityStandard)
|
|
45 |
{
|
|
46 |
CActiveScheduler::Add(this);
|
|
47 |
}
|
|
48 |
|
|
49 |
// ---------------------------------------------------------
|
|
50 |
// Destructor
|
|
51 |
// ---------------------------------------------------------
|
|
52 |
//
|
|
53 |
CSrcsServiceManager::~CSrcsServiceManager()
|
|
54 |
{
|
|
55 |
Cancel();
|
|
56 |
RProperty::Delete(KUidObexSMCategory, KObexSMPostInitErrorProperty);
|
|
57 |
if ( iBTConnectionArray )
|
|
58 |
{
|
|
59 |
// Cleanup the array
|
|
60 |
iBTConnectionArray->ResetAndDestroy();
|
|
61 |
}
|
|
62 |
delete iBTConnectionArray;
|
|
63 |
|
|
64 |
if ( iUSBConnectionArray )
|
|
65 |
{
|
|
66 |
// Cleanup the array
|
|
67 |
iUSBConnectionArray->ResetAndDestroy();
|
|
68 |
}
|
|
69 |
delete iUSBConnectionArray;
|
|
70 |
|
|
71 |
|
|
72 |
if ( iIrDAConnectionArray )
|
|
73 |
{
|
|
74 |
// Cleanup the array
|
|
75 |
iIrDAConnectionArray->ResetAndDestroy();
|
|
76 |
}
|
|
77 |
delete iIrDAConnectionArray;
|
|
78 |
|
|
79 |
REComSession::FinalClose();
|
|
80 |
}
|
|
81 |
|
|
82 |
// ---------------------------------------------------------
|
|
83 |
// NewL
|
|
84 |
// ---------------------------------------------------------
|
|
85 |
//
|
|
86 |
CSrcsServiceManager* CSrcsServiceManager::NewL()
|
|
87 |
{
|
|
88 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: NewL"));
|
|
89 |
CSrcsServiceManager* self = new (ELeave) CSrcsServiceManager();
|
|
90 |
CleanupStack::PushL(self);
|
|
91 |
self->ConstructL();
|
|
92 |
CleanupStack::Pop();
|
|
93 |
return self;
|
|
94 |
}
|
|
95 |
|
|
96 |
// ---------------------------------------------------------
|
|
97 |
// ConstructL
|
|
98 |
// ---------------------------------------------------------
|
|
99 |
//
|
|
100 |
void CSrcsServiceManager::ConstructL()
|
|
101 |
{
|
|
102 |
iBTConnectionArray = new(ELeave) CArrayPtrFlat<CSrcsTransport>(KConnectionArrayGranularity);
|
|
103 |
iUSBConnectionArray = new(ELeave) CArrayPtrFlat<CSrcsTransport>(KConnectionArrayGranularity);
|
|
104 |
iIrDAConnectionArray = new(ELeave) CArrayPtrFlat<CSrcsTransport>(KConnectionArrayGranularity);
|
|
105 |
|
|
106 |
TInt err = RProperty::Define(KUidObexSMCategory, KObexSMPostInitErrorProperty, RProperty::EInt, KAllowAllPolicy, KObexSMOnlyPolicy);
|
|
107 |
if ( err != KErrNone && err != KErrAlreadyExists )
|
|
108 |
{
|
|
109 |
User::LeaveIfError(err);
|
|
110 |
}
|
|
111 |
(void)RProperty::Set(KUidObexSMCategory,KObexSMPostInitErrorProperty,KErrNone);
|
|
112 |
}
|
|
113 |
|
|
114 |
// ---------------------------------------------------------
|
|
115 |
// ManagerServicesL
|
|
116 |
// Method to manage service controllers on all supported transports.
|
|
117 |
// ---------------------------------------------------------
|
|
118 |
//
|
|
119 |
TInt CSrcsServiceManager::ManageServices( TSrcsTransport aTransport, TBool aState,
|
|
120 |
MObexSMRequestObserver* aObserver,
|
|
121 |
const RMessage2& aMessage)
|
|
122 |
{
|
|
123 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServices"));
|
|
124 |
if ( !IsActive() )
|
|
125 |
{
|
|
126 |
iStatus=KRequestPending;
|
|
127 |
DoManageServices( aTransport,aState, aObserver, aMessage );
|
|
128 |
SetActive();
|
|
129 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServices KErrNone"));
|
|
130 |
return KErrNone;
|
|
131 |
}
|
|
132 |
else
|
|
133 |
{
|
|
134 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServices KErrServerBusy"));
|
|
135 |
return KErrServerBusy;
|
|
136 |
}
|
|
137 |
}
|
|
138 |
|
|
139 |
// ---------------------------------------------------------
|
|
140 |
// DoManageServices
|
|
141 |
// Method to manage service controllers on all supported transports.
|
|
142 |
// ---------------------------------------------------------
|
|
143 |
//
|
|
144 |
void CSrcsServiceManager::DoManageServices(TSrcsTransport aTransport, TBool aState, MObexSMRequestObserver* aObserver,
|
|
145 |
const RMessage2& aMessage)
|
|
146 |
{
|
|
147 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: DoManageServices"));
|
|
148 |
iObserver=aObserver;
|
|
149 |
iMessage=aMessage;
|
|
150 |
iTransportType = aTransport;
|
|
151 |
iTransportState = aState;
|
|
152 |
TRAPD(error,RealDoManageServiceL(aTransport,aState));
|
|
153 |
if (error != KErrNone)
|
|
154 |
{
|
|
155 |
iErrorState=error;
|
|
156 |
}
|
|
157 |
TRequestStatus* temp = &iStatus;
|
|
158 |
User::RequestComplete( temp, iErrorState );
|
|
159 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: DoManageServices exit"));
|
|
160 |
}
|
|
161 |
|
|
162 |
// ---------------------------------------------------------
|
|
163 |
// RunL
|
|
164 |
// Notifies request completion
|
|
165 |
// ---------------------------------------------------------
|
|
166 |
//
|
|
167 |
void CSrcsServiceManager::RunL()
|
|
168 |
{
|
|
169 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RunL"));
|
|
170 |
iObserver->RequestCompleted(iMessage,iStatus.Int());
|
|
171 |
|
|
172 |
// If the transport is being turned on, launch post-initialization routine
|
|
173 |
// for appropriate service controllers array
|
|
174 |
if (iTransportState)
|
|
175 |
{
|
|
176 |
switch(iTransportType)
|
|
177 |
{
|
|
178 |
case ESrcsTransportBT:
|
|
179 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RunL(Bluetooth)"));
|
|
180 |
PostInitialize(*iBTConnectionArray);
|
|
181 |
break;
|
|
182 |
case ESrcsTransportUSB:
|
|
183 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RunL(USB)"));
|
|
184 |
PostInitialize(*iUSBConnectionArray);
|
|
185 |
break;
|
|
186 |
case ESrcsTransportIrDA:
|
|
187 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RunL(IrDA)"));
|
|
188 |
PostInitialize(*iIrDAConnectionArray);
|
|
189 |
break;
|
|
190 |
default:
|
|
191 |
FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Transport not supported.")));
|
|
192 |
break;
|
|
193 |
}
|
|
194 |
}
|
|
195 |
else
|
|
196 |
{
|
|
197 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RunL() - transport is turned off"));
|
|
198 |
}
|
|
199 |
|
|
200 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RunL exit"));
|
|
201 |
}
|
|
202 |
// ---------------------------------------------------------
|
|
203 |
// RunErrorL
|
|
204 |
// ---------------------------------------------------------
|
|
205 |
//
|
|
206 |
void CSrcsServiceManager::RunError()
|
|
207 |
{
|
|
208 |
}
|
|
209 |
// ---------------------------------------------------------
|
|
210 |
// DoCancel
|
|
211 |
// ---------------------------------------------------------
|
|
212 |
//
|
|
213 |
void CSrcsServiceManager::DoCancel()
|
|
214 |
{
|
|
215 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: DoCancel"));
|
|
216 |
}
|
|
217 |
// ---------------------------------------------------------
|
|
218 |
// RealDoManageServiceL
|
|
219 |
// Method to manage service controllers on all supported transports.
|
|
220 |
// ---------------------------------------------------------
|
|
221 |
//
|
|
222 |
void CSrcsServiceManager::RealDoManageServiceL(TSrcsTransport aTransport, TBool aState)
|
|
223 |
{
|
|
224 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RealDoManageServiceL"));
|
|
225 |
|
|
226 |
switch(aTransport)
|
|
227 |
{
|
|
228 |
case ESrcsTransportBT:
|
|
229 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL(Bluetooth)"));
|
|
230 |
iTransportName.Set(KSrcsTransportBT);
|
|
231 |
ServiceArray(*iBTConnectionArray, aState);
|
|
232 |
break;
|
|
233 |
case ESrcsTransportUSB:
|
|
234 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL(USB)"));
|
|
235 |
iTransportName.Set(KSrcsTransportUSB);
|
|
236 |
ServiceArray(*iUSBConnectionArray, aState);
|
|
237 |
break;
|
|
238 |
case ESrcsTransportIrDA:
|
|
239 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL(IrDA)"));
|
|
240 |
iTransportName.Set(KSrcsTransportIrDA);
|
|
241 |
ServiceArray(*iIrDAConnectionArray, aState);
|
|
242 |
break;
|
|
243 |
default:
|
|
244 |
FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Transport not supported.")));
|
|
245 |
User::Leave(KErrNotSupported);
|
|
246 |
}
|
|
247 |
|
|
248 |
}
|
|
249 |
|
|
250 |
// ---------------------------------------------------------
|
|
251 |
// CSrcsServiceManager
|
|
252 |
// Method to manage Service arrays
|
|
253 |
// ---------------------------------------------------------
|
|
254 |
//
|
|
255 |
void CSrcsServiceManager::ServiceArray(CArrayPtr<CSrcsTransport> &aTransport, TBool aState)
|
|
256 |
{
|
|
257 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ServiceArray"));
|
|
258 |
|
|
259 |
// We start and stop services by aState value
|
|
260 |
if ( aState ) // trun on service
|
|
261 |
{
|
|
262 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL(Turn ON)"));
|
|
263 |
// We do not re-start services if they have been started
|
|
264 |
if (!(aTransport.Count()))
|
|
265 |
{
|
|
266 |
//Declare array of service controllers
|
|
267 |
RImplInfoPtrArray infoArrayServiceController;
|
|
268 |
|
|
269 |
//Declare array of SRCS transport plugins
|
|
270 |
RImplInfoPtrArray infoArrayTranport;
|
|
271 |
CleanupClosePushL(infoArrayTranport);
|
|
272 |
|
|
273 |
CleanupClosePushL(infoArrayServiceController);
|
|
274 |
|
|
275 |
//List all SRCS transport plugin implementations
|
|
276 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL about to list Transport Impl"));
|
|
277 |
CSrcsTransport::ListImplementationsL(iTransportName,infoArrayTranport);
|
|
278 |
|
|
279 |
//Found SRCS transport plugin. Then start to enumerate service controller and make connections.
|
|
280 |
if(infoArrayTranport.Count())
|
|
281 |
{
|
|
282 |
//There should be only one transport plugin of each type. Others are just ignored.
|
|
283 |
if(infoArrayTranport.Count() != 1)
|
|
284 |
{
|
|
285 |
FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Warning: Found %d transport implementations." ), infoArrayTranport.Count()));
|
|
286 |
}
|
|
287 |
|
|
288 |
FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Using Transport ImplementationUid %x"), infoArrayTranport[0]->ImplementationUid()));
|
|
289 |
|
|
290 |
//enumerate service controllers
|
|
291 |
CSrcsInterface::ListImplementationsL(iTransportName,infoArrayServiceController);
|
|
292 |
|
|
293 |
// Loop through each found service controller,
|
|
294 |
// create SRCS transport connection for each found service controller
|
|
295 |
// and instantiate the service controller.
|
|
296 |
CSrcsTransport *cm;
|
|
297 |
|
|
298 |
for (TInt i=0; i< infoArrayServiceController.Count(); i++)
|
|
299 |
{
|
|
300 |
// TRAP is needed because of OOM situations.
|
|
301 |
// Otherwise whole server is leaving and panicing.
|
|
302 |
FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Found Service Controller ImplementationUid %x"), infoArrayServiceController[i]->ImplementationUid()));
|
|
303 |
|
|
304 |
TRAPD( error, cm = CSrcsTransport::NewL(infoArrayTranport[0]->ImplementationUid(), infoArrayServiceController[i] ));
|
|
305 |
if ( error != KErrNone )
|
|
306 |
{
|
|
307 |
// Error when creating service controller (e.g. no memory). Cleanup and zero.
|
|
308 |
FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Create implementation failed with error code %d"), error));
|
|
309 |
}
|
|
310 |
else
|
|
311 |
{
|
|
312 |
// Add this connection to the list
|
|
313 |
aTransport.AppendL(cm);
|
|
314 |
FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL: Implementation created successfully.")));
|
|
315 |
}
|
|
316 |
}
|
|
317 |
}
|
|
318 |
else
|
|
319 |
{
|
|
320 |
FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Transport implementation not found.")));
|
|
321 |
}
|
|
322 |
|
|
323 |
// Clean up
|
|
324 |
infoArrayTranport.ResetAndDestroy();
|
|
325 |
infoArrayServiceController.ResetAndDestroy();
|
|
326 |
CleanupStack::PopAndDestroy(2); //infoArrayServiceController
|
|
327 |
|
|
328 |
}
|
|
329 |
}
|
|
330 |
else // turn off service
|
|
331 |
{
|
|
332 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL(Turn OFF)"));
|
|
333 |
aTransport.ResetAndDestroy();
|
|
334 |
// This is a special case for USB transport. Clear errors.
|
|
335 |
if (iTransportType == ESrcsTransportUSB)
|
|
336 |
{
|
|
337 |
(void)RProperty::Set(KUidObexSMCategory,KObexSMPostInitErrorProperty,KErrNone);
|
|
338 |
}
|
|
339 |
}
|
|
340 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RealDoManageServiceL exit"));
|
|
341 |
}
|
|
342 |
|
|
343 |
// ------------------------------------------------------------------------------------------
|
|
344 |
// CSrcsServiceManager
|
|
345 |
// This function iterates through all detected service controllers for given transport
|
|
346 |
// and calls post-initialization routines.
|
|
347 |
// This solution is implemented mainly to satisfy tough timing requirements for USB transport
|
|
348 |
// ------------------------------------------------------------------------------------------
|
|
349 |
//
|
|
350 |
void CSrcsServiceManager::PostInitialize(CArrayPtr<CSrcsTransport> &aTransport)
|
|
351 |
{
|
|
352 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: PostInitialize()"));
|
|
353 |
for (TInt i=0; i < aTransport.Count(); ++i)
|
|
354 |
{
|
|
355 |
FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: PostInitilize. Processing Service Controller[%d]"), i));
|
|
356 |
TRAPD(err,aTransport[i]->PostInitializeL());
|
|
357 |
|
|
358 |
// This is a special case for USB transport to notify the USB OBEX class controller about any errors occured
|
|
359 |
// at Post-Initialization stage.
|
|
360 |
// Post-initialization is not implemented for Bluetooth and IrDA transports, so there is no need to notify.
|
|
361 |
if ((err != KErrNone) && (iTransportType == ESrcsTransportUSB))
|
|
362 |
{
|
|
363 |
(void)RProperty::Set(KUidObexSMCategory,KObexSMPostInitErrorProperty,err);
|
|
364 |
FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: PostInitialize. Transport[%d]::PostInitializeL() returned %d, exiting..."), i, err));
|
|
365 |
break;
|
|
366 |
}
|
|
367 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: PostInitialize() - DONE post initialization"));
|
|
368 |
}
|
|
369 |
FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: PostInitialize() exit"));
|
|
370 |
}
|
|
371 |
|
|
372 |
// End of file
|