|
1 /* |
|
2 * Copyright (c) 2002-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: This class handles services management requests. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "SrcsServiceManager.h" |
|
22 #include "debug.h" |
|
23 |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 // The granularity of the array used to hold BT, IrDA and USB connnection objects |
|
28 static const TInt KConnectionArrayGranularity = 4; |
|
29 |
|
30 // ================= MEMBER FUNCTIONS ======================= |
|
31 |
|
32 |
|
33 // --------------------------------------------------------- |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // --------------------------------------------------------- |
|
37 // |
|
38 CSrcsServiceManager::CSrcsServiceManager():CActive(CActive::EPriorityStandard) |
|
39 { |
|
40 CActiveScheduler::Add(this); |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------- |
|
44 // Destructor |
|
45 // --------------------------------------------------------- |
|
46 // |
|
47 CSrcsServiceManager::~CSrcsServiceManager() |
|
48 { |
|
49 Cancel(); |
|
50 if ( iBTConnectionArray ) |
|
51 { |
|
52 // Cleanup the array |
|
53 iBTConnectionArray->ResetAndDestroy(); |
|
54 } |
|
55 delete iBTConnectionArray; |
|
56 |
|
57 if ( iUSBConnectionArray ) |
|
58 { |
|
59 // Cleanup the array |
|
60 iUSBConnectionArray->ResetAndDestroy(); |
|
61 } |
|
62 delete iUSBConnectionArray; |
|
63 |
|
64 |
|
65 if ( iIrDAConnectionArray ) |
|
66 { |
|
67 // Cleanup the array |
|
68 iIrDAConnectionArray->ResetAndDestroy(); |
|
69 } |
|
70 delete iIrDAConnectionArray; |
|
71 |
|
72 REComSession::FinalClose(); |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // NewL |
|
77 // --------------------------------------------------------- |
|
78 // |
|
79 CSrcsServiceManager* CSrcsServiceManager::NewL() |
|
80 { |
|
81 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: NewL")); |
|
82 CSrcsServiceManager* self = new (ELeave) CSrcsServiceManager(); |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(); |
|
85 CleanupStack::Pop(); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------- |
|
90 // ConstructL |
|
91 // --------------------------------------------------------- |
|
92 // |
|
93 void CSrcsServiceManager::ConstructL() |
|
94 { |
|
95 iBTConnectionArray = new(ELeave) CArrayPtrFlat<CSrcsTransport>(KConnectionArrayGranularity); |
|
96 iUSBConnectionArray = new(ELeave) CArrayPtrFlat<CSrcsTransport>(KConnectionArrayGranularity); |
|
97 iIrDAConnectionArray = new(ELeave) CArrayPtrFlat<CSrcsTransport>(KConnectionArrayGranularity); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------- |
|
101 // ManagerServicesL |
|
102 // Method to manage service controllers on all supported transports. |
|
103 // --------------------------------------------------------- |
|
104 // |
|
105 TInt CSrcsServiceManager::ManageServices( TSrcsTransport aTransport, TBool aState, |
|
106 MObexSMRequestObserver* aObserver, |
|
107 const RMessage2& aMessage) |
|
108 { |
|
109 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServices")); |
|
110 if ( !IsActive() ) |
|
111 { |
|
112 iStatus=KRequestPending; |
|
113 DoManageServices( aTransport,aState, aObserver, aMessage ); |
|
114 SetActive(); |
|
115 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServices KErrNone")); |
|
116 return KErrNone; |
|
117 } |
|
118 else |
|
119 { |
|
120 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServices KErrServerBusy")); |
|
121 return KErrServerBusy; |
|
122 } |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------- |
|
126 // DoManageServices |
|
127 // Method to manage service controllers on all supported transports. |
|
128 // --------------------------------------------------------- |
|
129 // |
|
130 void CSrcsServiceManager::DoManageServices(TSrcsTransport aTransport, TBool aState, MObexSMRequestObserver* aObserver, |
|
131 const RMessage2& aMessage) |
|
132 { |
|
133 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: DoManageServices")); |
|
134 iObserver=aObserver; |
|
135 iMessage=aMessage; |
|
136 TRAPD(error,RealDoManageServiceL(aTransport,aState)); |
|
137 if (error != KErrNone) |
|
138 { |
|
139 iErrorState=error; |
|
140 } |
|
141 TRequestStatus* temp = &iStatus; |
|
142 User::RequestComplete( temp, iErrorState ); |
|
143 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: DoManageServices exit")); |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------- |
|
147 // RunL |
|
148 // Notifies request completion |
|
149 // --------------------------------------------------------- |
|
150 // |
|
151 void CSrcsServiceManager::RunL() |
|
152 { |
|
153 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RunL")); |
|
154 iObserver->RequestCompleted(iMessage,iStatus.Int()); |
|
155 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RunL exit")); |
|
156 } |
|
157 // --------------------------------------------------------- |
|
158 // RunErrorL |
|
159 // --------------------------------------------------------- |
|
160 // |
|
161 void CSrcsServiceManager::RunError() |
|
162 { |
|
163 } |
|
164 // --------------------------------------------------------- |
|
165 // DoCancel |
|
166 // --------------------------------------------------------- |
|
167 // |
|
168 void CSrcsServiceManager::DoCancel() |
|
169 { |
|
170 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: DoCancel")); |
|
171 } |
|
172 // --------------------------------------------------------- |
|
173 // RealDoManageServiceL |
|
174 // Method to manage service controllers on all supported transports. |
|
175 // --------------------------------------------------------- |
|
176 // |
|
177 void CSrcsServiceManager::RealDoManageServiceL(TSrcsTransport aTransport, TBool aState) |
|
178 { |
|
179 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RealDoManageServiceL")); |
|
180 CArrayPtr<CSrcsTransport>* connectionArray=NULL; |
|
181 TPtrC8 transportName; |
|
182 |
|
183 switch(aTransport) |
|
184 { |
|
185 case ESrcsTransportBT: |
|
186 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL(Bluetooth)")); |
|
187 transportName.Set(KSrcsTransportBT); |
|
188 connectionArray = iBTConnectionArray; |
|
189 break; |
|
190 case ESrcsTransportUSB: |
|
191 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL(USB)")); |
|
192 transportName.Set(KSrcsTransportUSB); |
|
193 connectionArray = iUSBConnectionArray; |
|
194 break; |
|
195 case ESrcsTransportIrDA: |
|
196 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL(IrDA)")); |
|
197 transportName.Set(KSrcsTransportIrDA); |
|
198 connectionArray = iIrDAConnectionArray; |
|
199 break; |
|
200 default: |
|
201 FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Transport not supported."))); |
|
202 iErrorState = KErrNotSupported; |
|
203 } |
|
204 // We start and stop services by aState value |
|
205 if ( aState ) // trun on service |
|
206 { |
|
207 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL(Turn ON)")); |
|
208 // We do not re-start services if they have been started |
|
209 if ( connectionArray && !(connectionArray->Count()) ) |
|
210 { |
|
211 //Declare array of service controllers |
|
212 RImplInfoPtrArray infoArrayServiceController; |
|
213 |
|
214 //Declare array of SRCS transport plugins |
|
215 RImplInfoPtrArray infoArrayTranport; |
|
216 CleanupClosePushL(infoArrayTranport); |
|
217 |
|
218 CleanupClosePushL(infoArrayServiceController); |
|
219 |
|
220 //List all SRCS transport plugin implementations |
|
221 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL about to list Transport Impl")); |
|
222 CSrcsTransport::ListImplementationsL(transportName,infoArrayTranport); |
|
223 |
|
224 //Found SRCS transport plugin. Then start to enumerate service controller and make connections. |
|
225 if(infoArrayTranport.Count()) |
|
226 { |
|
227 //There should be only one transport plugin of each type. Others are just ignored. |
|
228 if(infoArrayTranport.Count() != 1) |
|
229 { |
|
230 FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Warning: Found %d transport implementations." ), infoArrayTranport.Count())); |
|
231 } |
|
232 |
|
233 FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Using Transport ImplementationUid %x"), infoArrayTranport[0]->ImplementationUid())); |
|
234 |
|
235 //enumerate service controllers |
|
236 CSrcsInterface::ListImplementationsL(transportName,infoArrayServiceController); |
|
237 |
|
238 // Loop through each found service controller, |
|
239 // create SRCS transport connection for each found service controller |
|
240 // and instantiate the service controller. |
|
241 CSrcsTransport *cm; |
|
242 |
|
243 for (TInt i=0; i< infoArrayServiceController.Count(); i++) |
|
244 { |
|
245 // TRAP is needed because of OOM situations. |
|
246 // Otherwise whole server is leaving and panicing. |
|
247 FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Found Service Controller ImplementationUid %x"), infoArrayServiceController[i]->ImplementationUid())); |
|
248 |
|
249 TRAPD( error, cm = CSrcsTransport::NewL(infoArrayTranport[0]->ImplementationUid(), infoArrayServiceController[i] )); |
|
250 if ( error != KErrNone ) |
|
251 { |
|
252 // Error when creating service controller (e.g. no memory). Cleanup and zero. |
|
253 FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Create implementation failed with error code %d"), error)); |
|
254 } |
|
255 else |
|
256 { |
|
257 // Add this connection to the list |
|
258 connectionArray->AppendL(cm); |
|
259 FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL: Implementation created successfully."))); |
|
260 } |
|
261 } |
|
262 } |
|
263 else |
|
264 { |
|
265 FTRACE(FPrint(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL. Transport implementation not found."))); |
|
266 } |
|
267 |
|
268 // Clean up |
|
269 infoArrayTranport.ResetAndDestroy(); |
|
270 infoArrayServiceController.ResetAndDestroy(); |
|
271 CleanupStack::PopAndDestroy(2); //infoArrayServiceController |
|
272 |
|
273 } |
|
274 } |
|
275 else // turn off service |
|
276 { |
|
277 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: ManageServicesL(Turn OFF)")); |
|
278 connectionArray->ResetAndDestroy(); |
|
279 } |
|
280 FLOG(_L("[SRCS]\tserver\tCSrcsServiceManager: RealDoManageServiceL exit")); |
|
281 } |
|
282 // End of file |