|
1 /* |
|
2 * Copyright (c) 2006 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 the License "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: Header file for CCseSchedulerThreadCrossroads-class.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 #ifndef _CCSESCHEDULERLANDLORD_H |
|
21 #define _CCSESCHEDULERLANDLORD_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include "MCseSemaphoreSignalObserver.h" |
|
26 |
|
27 // CONSTANTS |
|
28 #define KThreadNameSize 19 |
|
29 |
|
30 // MACROS |
|
31 // None |
|
32 |
|
33 // DATA TYPES |
|
34 // None |
|
35 |
|
36 // FUNCTION PROTOTYPES |
|
37 // None |
|
38 |
|
39 // FORWARD DECLARATIONS |
|
40 class MCseScheduleObserver; |
|
41 class RThread; |
|
42 class CCseScheduledProgram; |
|
43 class CCseSchedulerThreadPacket; |
|
44 class CCseSemaphoreController; |
|
45 class CActiveSchedulerWait; |
|
46 |
|
47 /** |
|
48 * LandLord controlling shared data that is given to thread. After plugin thread is started, |
|
49 * nothing should be accessed before thread has died. |
|
50 * |
|
51 * Also observes thread when it dies. |
|
52 */ |
|
53 class CCseSchedulerLandLord : public CActive, |
|
54 public MCseSemaphoreSignalObserver |
|
55 |
|
56 { |
|
57 public: // Constructors and destructors |
|
58 /** |
|
59 * Destructor. |
|
60 */ |
|
61 virtual ~CCseSchedulerLandLord(); |
|
62 |
|
63 /** |
|
64 * Two-phased constructor. |
|
65 * @param aObserver A pointer back to plugin controller. |
|
66 */ |
|
67 static CCseSchedulerLandLord* NewL( MCseScheduleObserver* aObserver ); |
|
68 |
|
69 private: // Constructors and destructors |
|
70 /** |
|
71 * By default Symbian 2nd phase constructor is private. |
|
72 */ |
|
73 void ConstructL(); |
|
74 |
|
75 /** |
|
76 * C++ default constructor. |
|
77 * @param aObserver A pointer back to plugin controller. |
|
78 */ |
|
79 CCseSchedulerLandLord( MCseScheduleObserver* aObserver ); |
|
80 |
|
81 public: |
|
82 /** |
|
83 * Set schedule to LandLord. |
|
84 * @param aData CCseScheduledProgram to be set. |
|
85 */ |
|
86 void SetScheduleL( CCseScheduledProgram& aData ); |
|
87 |
|
88 /** |
|
89 * Returns ThreadPacket of the LandLord |
|
90 * @return pointer to ThreadPacket |
|
91 */ |
|
92 CCseSchedulerThreadPacket* ThreadPacket( ); |
|
93 |
|
94 /** |
|
95 * Run plugin. Creates thread where the CCseSchedulerPluginStarter is run |
|
96 * and sets itself observing when thread dies. |
|
97 */ |
|
98 void RunPluginL( ); |
|
99 |
|
100 /** |
|
101 * Clears landlord. Uses semaphore to signal plugin thread that thread needs |
|
102 * to be taken down. |
|
103 * Synchronous. |
|
104 */ |
|
105 void ClearL(); |
|
106 |
|
107 /** |
|
108 * Returns ETrue if LandLord is working (plugin is running). |
|
109 */ |
|
110 TBool IsWorking(); |
|
111 |
|
112 private: // CActive |
|
113 /** |
|
114 * RunL |
|
115 * @return None |
|
116 */ |
|
117 void RunL(); |
|
118 |
|
119 /** |
|
120 * RunError |
|
121 * @return |
|
122 */ |
|
123 TInt RunError( TInt aError ); |
|
124 |
|
125 /** |
|
126 * DoCancel |
|
127 * @return None |
|
128 */ |
|
129 void DoCancel(); |
|
130 |
|
131 private: // from MCseSemaphoreSignalObserver |
|
132 void SemaphoreSignalled( ); |
|
133 |
|
134 private: // New methods |
|
135 /** |
|
136 * Generates unique thread name to internal iThreadName-buffer. |
|
137 */ |
|
138 void GenerateThreadNameL(); |
|
139 |
|
140 /** |
|
141 * Generates semaphores to signal thread shutdown and when shutdown |
|
142 * is completed. |
|
143 */ |
|
144 void GenerateSemaphoresL( ); |
|
145 |
|
146 /** |
|
147 * Starts or stops active wait. Used when thread needs to be taken down. |
|
148 */ |
|
149 void ActiveWait( TBool aStart ); |
|
150 |
|
151 private: // Data |
|
152 /** |
|
153 * Pointer back to plugin controller. Own. |
|
154 */ |
|
155 MCseScheduleObserver* iObserver; |
|
156 |
|
157 /** |
|
158 * ThreadPacket. Contains data to be given plugin thread when run. Own. |
|
159 */ |
|
160 CCseSchedulerThreadPacket* iThreadPacket; |
|
161 |
|
162 /** |
|
163 * Thread where plugin is run. |
|
164 */ |
|
165 RThread iThread; |
|
166 |
|
167 /** |
|
168 * Unique thread name. Own. |
|
169 */ |
|
170 HBufC* iThreadName; |
|
171 |
|
172 /** |
|
173 * ETrue if thread is running, EFalse if not. |
|
174 */ |
|
175 TBool iThreadRunning; |
|
176 |
|
177 /** |
|
178 * Semaphore signalled when plugin is wanted to take down. |
|
179 */ |
|
180 RSemaphore iPluginShutdownSemaphore; |
|
181 |
|
182 /** |
|
183 * Semaphore signalled when plugin has been taken down. |
|
184 */ |
|
185 RSemaphore iPluginShutdownCompleteSemaphore; |
|
186 |
|
187 /** |
|
188 * ActiveSchedulerWait. Own. |
|
189 */ |
|
190 CActiveSchedulerWait* iActiveSchedulerWait; |
|
191 |
|
192 /** |
|
193 * Checks once a while if plugin shutdown has been completed. |
|
194 * Own. |
|
195 */ |
|
196 CCseSemaphoreController* iShutdownCompleteMonitor; |
|
197 |
|
198 /** |
|
199 * ETrue if shutdown has been signalled to CCSeSchedulerPluginStarter. |
|
200 * EFalse if not. |
|
201 */ |
|
202 TBool iTakedownRequested; |
|
203 }; |
|
204 |
|
205 #endif //_CCSESCHEDULERLANDLORD_H |