|
1 /* |
|
2 * Copyright (c) 2002 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 * This file contains the neccessary clases to access to the Dos Server |
|
16 * Services. Client side API. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef __DOSSVRSERVICES_H__ |
|
22 #define __DOSSVRSERVICES_H__ |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include <psvariables.h> |
|
27 #include <bttypes.h> // TBTDevAddr, THCIConnHandle |
|
28 |
|
29 /** |
|
30 * This represents parameter info and it is used when transfering |
|
31 * paramenter data between client and server in case of extended |
|
32 * functions i.e. usage of RDosExtension API. |
|
33 */ |
|
34 struct TExtensionPar |
|
35 { |
|
36 // Function flag used to identify between different RDosExtension |
|
37 // function calls (multiple extensions are supported at the same time). |
|
38 TInt iFunc; |
|
39 |
|
40 // Length or size of the parameter data. |
|
41 // Can not be negative value, otherwise call to CallFunction will |
|
42 // return KErrGeneral. |
|
43 // Server needs to know the size to be able to allocate memory from heap. |
|
44 TInt iParLength; |
|
45 |
|
46 // Auto complete flag. |
|
47 // ETrue if the function is completed by the server, |
|
48 // EFalse if it's gonna be completed by the DSY. |
|
49 TBool iAutoComplete; |
|
50 }; |
|
51 |
|
52 // Convenience type definitions to wrap package buffers: |
|
53 typedef TPckgBuf<TExtensionPar> TExtensionParPckg; |
|
54 |
|
55 /** |
|
56 * This class represents a session with Dos Server and has some general |
|
57 * purpose services. |
|
58 */ |
|
59 class RDosServer : public RSessionBase |
|
60 { |
|
61 public: |
|
62 /** |
|
63 * Starts the server. |
|
64 * @return Symbian error code. |
|
65 */ |
|
66 IMPORT_C TInt StartServer() const; |
|
67 |
|
68 /** |
|
69 * Connects and registers a session to ther server. |
|
70 * If the server has not been started before a call to this function |
|
71 * will start it. |
|
72 * @return Symbian error code. |
|
73 */ |
|
74 IMPORT_C TInt Connect(); |
|
75 |
|
76 /** |
|
77 * Closes the session. |
|
78 */ |
|
79 IMPORT_C void Close(); |
|
80 |
|
81 /** |
|
82 * Shuts down the server. |
|
83 */ |
|
84 IMPORT_C void ServerShutdown() const; |
|
85 }; |
|
86 |
|
87 /** |
|
88 * This the base class for all the Dos Server subsessions. |
|
89 */ |
|
90 class RDosSubSession : public RSubSessionBase |
|
91 { |
|
92 public: |
|
93 /** |
|
94 * Closes the subsession. |
|
95 */ |
|
96 IMPORT_C void Close(); |
|
97 |
|
98 protected: |
|
99 // Deprecated |
|
100 TPtr8* NewPtr(TAny* aDataPtr,TInt aDataSize); |
|
101 |
|
102 protected: |
|
103 RPointerArray<TPtr8>* iParArray; |
|
104 }; |
|
105 |
|
106 /** |
|
107 * This subsession offers possibilities for licensees to extend the functionality of the |
|
108 * dos server. |
|
109 */ |
|
110 class RDosExtension : public RDosSubSession |
|
111 { |
|
112 public: |
|
113 /** |
|
114 * Opens the subsession. |
|
115 * @param aServer A connected session with the Server. |
|
116 * @return Symbian error code. |
|
117 */ |
|
118 IMPORT_C TInt Open(RDosServer& aServer); |
|
119 |
|
120 //================================================ |
|
121 // Subsession services |
|
122 //================================================ |
|
123 |
|
124 protected: |
|
125 /** |
|
126 * Deprecated, please use the overloaded function taking descriptors; |
|
127 * TInt CallFunction(const TExtensionParPckg& aParamInfo, TDes8& aParameter) |
|
128 * |
|
129 * Implements a synchronous raw function call that has to be implement in the Dsy plug-in. |
|
130 * Internal implementation creates temporary descriptors and calls the overloaded |
|
131 * CallFunction -function taking TExtensionParPckg and TDes8 parameters. |
|
132 * @param aFunc Unique integer among the extended functions what function we are calling. |
|
133 * @param aParameter A pointer to the parameter. |
|
134 * @param aParLength Length of the parameter. |
|
135 * @param aAutoComplete ETrue if the function is completed by the server, EFalse if it's gonna be completed |
|
136 * in the plug-in. |
|
137 * @return Symbian error code. |
|
138 */ |
|
139 IMPORT_C TInt CallFunction(TInt aFunc, TAny* aParameter=NULL, TInt aParLength=0,TBool aAutoComplete=ETrue); |
|
140 |
|
141 /** |
|
142 * Implements a function call that has to be implement in the Dsy plug-in |
|
143 * @param aParamInfo Package buffer containing parameter information (see TExtensionPar). |
|
144 * @param aParameter Reference to a descriptor containing parameter data. |
|
145 * @return Symbian error code. |
|
146 */ |
|
147 IMPORT_C TInt CallFunction(const TExtensionParPckg& aParamInfo, TDes8& aParameter); |
|
148 |
|
149 /** |
|
150 * Implements an asynchronous raw function call that has to be implement in the Dsy plug-in |
|
151 * @param aStatus Status variable to control the completion of the asynchronous request. |
|
152 * @param aParamInfo Package buffer containing parameter information (see TExtensionPar). |
|
153 * @param aParameter Reference to a descriptor containing parameter data. |
|
154 * @return Symbian error code. |
|
155 */ |
|
156 IMPORT_C void CallFunction(TRequestStatus& aStatus, const TExtensionParPckg& aParamInfo, TDes8& aParameter); |
|
157 }; |
|
158 |
|
159 /** |
|
160 * This enumeration describes the different types of queues when registering for events. |
|
161 */ |
|
162 enum TQueueType |
|
163 { |
|
164 ENoQueue, //The incoming events when the client is busy will be discarded. |
|
165 EQueue, //The incoming events when the client is busy will be queued. |
|
166 EOnlyLast //Only the last incoming event will be queued when the client is busy, deleting the previous queued one. |
|
167 }; |
|
168 |
|
169 |
|
170 /** |
|
171 * This type represents an event when the client registers for it. |
|
172 */ |
|
173 struct TRegisterEvent |
|
174 { |
|
175 // The unique identifier of the event. |
|
176 TUint iEvent; |
|
177 |
|
178 // The size of the event's parameter. |
|
179 TInt iParamSize; |
|
180 |
|
181 // The type of queue that the client wishes to have for the event. |
|
182 TQueueType iQueue; |
|
183 }; |
|
184 |
|
185 /** |
|
186 * This subsession offers services to register and listen for events. |
|
187 * It should not be used directly. Instead derive your class from CDosEventListenerBase |
|
188 */ |
|
189 class RDosEventRcv : public RDosSubSession |
|
190 { |
|
191 public: |
|
192 /** |
|
193 * Constructor |
|
194 */ |
|
195 RDosEventRcv(); |
|
196 |
|
197 /** |
|
198 * Desctructor |
|
199 */ |
|
200 ~RDosEventRcv(); |
|
201 |
|
202 /** |
|
203 * Opens the subsession. |
|
204 * @param aServer A connected session with the Server. |
|
205 * @return Symbian error code. |
|
206 */ |
|
207 TInt Open(RDosServer& aServer); |
|
208 |
|
209 /** |
|
210 * Informs the server that the client wished to receive an event. |
|
211 * @param aEvent The unique identifier of the event. |
|
212 * @param aParamSize The size of the parameter that event is going to carry. |
|
213 * @param aQueue The type of queue that the event is going to have. |
|
214 * @return Symbian error code. |
|
215 */ |
|
216 TInt Register(TInt aEvent,TInt aParamSize,TQueueType aQueue); |
|
217 |
|
218 /** |
|
219 * It asynchronously tells the server that the client doesn't wish to receive the event anymore. |
|
220 */ |
|
221 void UnRegister(); |
|
222 |
|
223 /** |
|
224 * Puts the client to wait for the event. |
|
225 * @param aStatus Status varibale that informs about the incoming events. |
|
226 * @return Symbian error code. |
|
227 */ |
|
228 TInt WaitEvent(TRequestStatus& aStatus) const; |
|
229 |
|
230 /** |
|
231 * Cancels outstanding requests. |
|
232 * @return Symbian error code. |
|
233 */ |
|
234 TInt CancelWaitEvent() const; |
|
235 |
|
236 |
|
237 /** |
|
238 * Returns a pointer to the buffer containing the parameter that came with the latest received event. |
|
239 * @return A pointer to the paramater buffer. |
|
240 */ |
|
241 inline HBufC8* Parameter() const; |
|
242 |
|
243 /** |
|
244 * Returns the size of the parameter that came with the latest received event. |
|
245 * @return Size of the parameter. |
|
246 */ |
|
247 inline TInt ParameterSize() const; |
|
248 |
|
249 /** |
|
250 * Returns the type of queue that the event has. |
|
251 * @return The type of queue. |
|
252 */ |
|
253 inline TQueueType Queue() const; |
|
254 |
|
255 /** |
|
256 * Returns the unique id of the event that the object is listening for. |
|
257 * @return An event identifier. |
|
258 */ |
|
259 inline TUint Event() const; |
|
260 |
|
261 private: |
|
262 |
|
263 // Pointer to the buffer containing the parameter of the latest received event. |
|
264 HBufC8* iParamContent; |
|
265 |
|
266 //A Descriptor pointer pointing to iParamContent. |
|
267 TPtr8* iContentPtr; |
|
268 |
|
269 //Indicates if the client has been already registerd or not. |
|
270 TBool iRegistered; |
|
271 |
|
272 //Queue type for the event. |
|
273 TQueueType iQueue; |
|
274 |
|
275 //The event. |
|
276 TUint iDosEvent; |
|
277 }; |
|
278 |
|
279 // |
|
280 // Events Constants |
|
281 // |
|
282 |
|
283 class CDosEventListenerBase; //Forward declaration |
|
284 |
|
285 /** |
|
286 * This active object is used to wait for the event provided by the server throught the class RDosEventRcv. |
|
287 * It is not recomended to use this class directly but instead use a derived class from CDosEventListenerBase. |
|
288 */ |
|
289 class CDosEventNotifier : public CActive |
|
290 { |
|
291 public: |
|
292 /** |
|
293 * Constructor. |
|
294 * @param aListener A pointer to the CDosListenerBase-derived object that owns this object. |
|
295 * @param aPriority The priority of the CActive object. |
|
296 */ |
|
297 CDosEventNotifier(CDosEventListenerBase* aListener,TPriority aPriority=EPriorityStandard); |
|
298 |
|
299 /** |
|
300 * Destructor. |
|
301 */ |
|
302 ~CDosEventNotifier(); |
|
303 |
|
304 /** |
|
305 * NewL that creates the object. |
|
306 * @param aServer A connected session to the DosServer. |
|
307 * @param aListener A pointer to the CDosListenerBase-derived object that owns this object. |
|
308 * @return A pointer to the created CDosEventNotifier object. |
|
309 */ |
|
310 static CDosEventNotifier* NewL(RDosServer& aServer,CDosEventListenerBase* aListener); |
|
311 |
|
312 /** |
|
313 * Registers the event in the Server and starts the listening for incoming events. |
|
314 * @param aEvent Event to listen to. |
|
315 * @param aParamSize Size of the parameter that the event is going to carry. |
|
316 * @param aQueue Desired type of the event queue. |
|
317 */ |
|
318 void StartListeningL(TUint aEvent,TInt aParamSize,TQueueType aQueue); |
|
319 |
|
320 private: |
|
321 /** |
|
322 * Symbian two-phased constructor. |
|
323 * @param aServer A connected session to the DosServer. |
|
324 */ |
|
325 void ConstructL(RDosServer& aServer); |
|
326 |
|
327 private: //Inherited from CActive |
|
328 |
|
329 /** |
|
330 * It's called by CActive on error situations. |
|
331 * @param aError Symbian error code. |
|
332 * @return Returns KErrNone if the error was handled or aError otherwise. |
|
333 */ |
|
334 TInt RunError(TInt aError); |
|
335 |
|
336 /** |
|
337 * It's called by CActive when the active object is scheduled to be executed. |
|
338 */ |
|
339 void RunL(); |
|
340 |
|
341 /** |
|
342 * It's called by CActve when Cancel() is called and process the cancelation of the request. |
|
343 */ |
|
344 void DoCancel(); |
|
345 |
|
346 public: |
|
347 // To part of a list of Notifiers |
|
348 TSglQueLink iLink; |
|
349 private: |
|
350 //The RDosEventRcv subsession with the server. |
|
351 RDosEventRcv iReceiver; |
|
352 |
|
353 //A pointer to the owner. |
|
354 CDosEventListenerBase* iListener; |
|
355 }; |
|
356 |
|
357 |
|
358 |
|
359 /** |
|
360 * This class provides with services to listen for events. |
|
361 * The class is intended for derivation. |
|
362 * The derived class should override all the events that its objects are going to register to. |
|
363 */ |
|
364 class CDosEventListenerBase : public CBase |
|
365 { |
|
366 public: |
|
367 /** |
|
368 * Constructor. |
|
369 * @param aServer A connected session to the DosServer. |
|
370 */ |
|
371 IMPORT_C CDosEventListenerBase(RDosServer& aServer); |
|
372 |
|
373 /** |
|
374 * Constructor. It creates the sessions to the DosServer. |
|
375 */ |
|
376 IMPORT_C CDosEventListenerBase(); |
|
377 |
|
378 /** |
|
379 * Destructor. |
|
380 */ |
|
381 IMPORT_C ~CDosEventListenerBase(); |
|
382 |
|
383 /** |
|
384 * It registers the object to all the events contained in aEventArray. |
|
385 * @param aEventArray An array of event for registration. |
|
386 * @param aEventCount Number of events in the array. |
|
387 */ |
|
388 IMPORT_C void StartListeningL(TRegisterEvent* aEventArray, TInt aEventCount); |
|
389 |
|
390 /** |
|
391 * It registers only one event. |
|
392 * @param aEvent Unique Id of the event. |
|
393 * @param aParamSize Size of the parameter that the event carries. |
|
394 * @param aQueue Type of queue wished for the event. |
|
395 */ |
|
396 IMPORT_C void StartListeningL(TUint aEvent,TInt aParamSize=0, TQueueType aQueue=EQueue); |
|
397 |
|
398 /** |
|
399 * Stops the listening. |
|
400 */ |
|
401 IMPORT_C void Stop(); |
|
402 |
|
403 /** |
|
404 * The function gets called whenever an error occurs and it can be overrided by the derived class. |
|
405 * @param aError Symbian error code. |
|
406 * @param aStopListening Put this parameter as ETrue if you wish the Listener to stop listening for the event |
|
407 * that caused the error. |
|
408 */ |
|
409 IMPORT_C virtual void OnError(TInt aError, TBool& aStopListening); |
|
410 |
|
411 /** |
|
412 * Returns the session with the DosServer. |
|
413 * @return A session with the DosServer. |
|
414 */ |
|
415 inline const RDosServer& DosServer() const; |
|
416 |
|
417 protected: |
|
418 |
|
419 //================================================ |
|
420 // Events: To be overriden by the derived class |
|
421 //================================================ |
|
422 |
|
423 /** |
|
424 * This a raw event that is intended for expansion of the event functionality by licensees. |
|
425 * @param aEvent The event. |
|
426 * @param aParameter A pointer to the parameter. |
|
427 */ |
|
428 IMPORT_C virtual void GeneralEventL(const TRegisterEvent& aEvent,TAny* aParameter); |
|
429 |
|
430 private: |
|
431 |
|
432 /** |
|
433 * This function handles the raw event and calls one of the "event functions". |
|
434 * @param aEvent The event. |
|
435 * @param aParameter A pointer to the parameter. |
|
436 */ |
|
437 void HandleEventL(const TRegisterEvent& aEvent,HBufC8* aParameter); |
|
438 |
|
439 /** |
|
440 * Register the events and start listening for them. |
|
441 */ |
|
442 void RegisterAndListenL(); |
|
443 |
|
444 private: |
|
445 friend class CDosEventNotifier; |
|
446 |
|
447 private: |
|
448 //A list of notifiers listening to this event. |
|
449 TSglQue<CDosEventNotifier> iNotifierList; |
|
450 |
|
451 //The TSglQueIter class to browser iNotifierList. |
|
452 TSglQueIter<CDosEventNotifier> iNotifierIter; |
|
453 |
|
454 //A pointer to the event list. |
|
455 TRegisterEvent* iEventList; |
|
456 |
|
457 //Number of events to listen to. |
|
458 TInt iNotifierCount; |
|
459 |
|
460 //Session with the DosServer. |
|
461 RDosServer iDosServer; |
|
462 |
|
463 //To check if the server was connected by this object |
|
464 TBool iOwnServer; |
|
465 }; |
|
466 |
|
467 #include "dossvrservices.inl" |
|
468 |
|
469 |
|
470 #endif // __DOSSVRSERVICES_H__ |