|
1 /* |
|
2 * Copyright (c) 2008 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: An Active Object offering its request status for any |
|
15 * asynchronous request handling. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef C_GENERICACTIVE_H |
|
21 #define C_GENERICACTIVE_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 |
|
26 class CGenericActive; |
|
27 |
|
28 /** |
|
29 * The observer of CGenericActive's request events |
|
30 * |
|
31 * This class defines the interface to handle request events from CGenericActive. |
|
32 * |
|
33 * @since S60 v3.1 |
|
34 */ |
|
35 class MGenericActiveObserver |
|
36 { |
|
37 |
|
38 public: |
|
39 |
|
40 /** |
|
41 * Called by CGenericActive::RunL() to handle the request completion event. |
|
42 * |
|
43 * @since S60 v3.1 |
|
44 * @param aActive the Active Object to which the request is assigned to. |
|
45 */ |
|
46 virtual void RequestCompletedL(CGenericActive& aActive) = 0; |
|
47 |
|
48 /** |
|
49 * alled by CGenericActive::RunL() to handle the cancellation of an outstanding request. |
|
50 * |
|
51 * @since S60 v3.1 |
|
52 * @param aActive the Active Object to which the request is assigned to. |
|
53 */ |
|
54 virtual void CancelRequest(CGenericActive& aActive) = 0; |
|
55 |
|
56 }; |
|
57 |
|
58 /** |
|
59 * |
|
60 * CGenericActive provides TRequestStatus for an async operation but it doesn't know the |
|
61 * detail of the request. CGenericActive could be used to implement timers, P&S subscribes |
|
62 * that are "simple" enough operations. |
|
63 * |
|
64 * @since S60 v3.1 |
|
65 */ |
|
66 class CGenericActive : public CActive |
|
67 { |
|
68 |
|
69 public: |
|
70 |
|
71 static CGenericActive* New(MGenericActiveObserver& aObserver, |
|
72 CActive::TPriority aPriority, TInt aRequestId); |
|
73 |
|
74 static CGenericActive* NewL(MGenericActiveObserver& aObserver, |
|
75 CActive::TPriority aPriority, TInt aRequestId); |
|
76 |
|
77 virtual ~CGenericActive(); |
|
78 |
|
79 public: |
|
80 |
|
81 /** |
|
82 * Calls SetActive(). |
|
83 * |
|
84 * @since S60 v3.1 |
|
85 */ |
|
86 virtual void GoActive(); |
|
87 |
|
88 /** |
|
89 * Gets the identifier of the request that this active object is serving. |
|
90 * |
|
91 * @since S60 v3.1 |
|
92 * @return the request identifier |
|
93 */ |
|
94 TInt RequestId() const; |
|
95 |
|
96 /** |
|
97 * Gets the identifier of the request that this active object is serving. |
|
98 * |
|
99 * @since S60 v3.1 |
|
100 * @param the request identifier |
|
101 */ |
|
102 void SetRequestId(TInt aRequestId); |
|
103 |
|
104 TRequestStatus& RequestStatus(); |
|
105 |
|
106 protected: |
|
107 |
|
108 /** |
|
109 * From CActive. |
|
110 * cancels the outstanding request. |
|
111 * |
|
112 * @since S60 v3.1 |
|
113 */ |
|
114 virtual void DoCancel(); |
|
115 |
|
116 /** |
|
117 * From CActive. |
|
118 * Handles the request completion event. |
|
119 * |
|
120 * @since S60 v3.1 |
|
121 */ |
|
122 virtual void RunL(); |
|
123 |
|
124 /** |
|
125 * From CActive. |
|
126 * Handles the leave from RunL(). |
|
127 * |
|
128 * @since S60 v3.1 |
|
129 * @param aError the leave code in RunL() |
|
130 * @return the error code to Active Scheduler |
|
131 */ |
|
132 virtual TInt RunError(TInt aError); |
|
133 |
|
134 protected: |
|
135 |
|
136 CGenericActive(MGenericActiveObserver& aObserver, |
|
137 CActive::TPriority aPriority, TInt aRequestId); |
|
138 |
|
139 private: |
|
140 |
|
141 /** |
|
142 * The observer which is interested in the request handling events. |
|
143 * Not own. |
|
144 */ |
|
145 MGenericActiveObserver& iObserver; |
|
146 |
|
147 /** |
|
148 * The request identifier assigned to this active object. |
|
149 */ |
|
150 TInt iRequestId; |
|
151 |
|
152 }; |
|
153 |
|
154 #endif // C_GENERICACTIVE_H |