|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Core activity mutex policies |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @publishedPartner |
|
21 @released |
|
22 */ |
|
23 |
|
24 #ifndef SYMBIAN_MM_MUTEXPOLICIES_H |
|
25 #define SYMBIAN_MM_MUTEXPOLICIES_H |
|
26 |
|
27 #include <elements/mm_context.h> |
|
28 |
|
29 namespace MeshMachine |
|
30 { |
|
31 |
|
32 /** |
|
33 Template to aggregate two mutexes with an logical AND operator |
|
34 |
|
35 @code |
|
36 typedef TAggregatedMutex_AND<THasDataClientsMutex, TNodeIsStartedMutex> THasDataClientsAndNodeIsStartedMutex; |
|
37 @endcode |
|
38 |
|
39 @param TMUTEX1 First mutex to test |
|
40 @param TMUTEX2 Second mutex to test |
|
41 */ |
|
42 template <class TMUTEX1, class TMUTEX2> |
|
43 class TAggregatedMutex_AND |
|
44 { |
|
45 public: |
|
46 /** |
|
47 @param aContext context in which to evaluate the mutexes |
|
48 @return ETrue if both mutex conditions have been met, EFalse otherwise |
|
49 */ |
|
50 inline static TBool IsBlocked(const MeshMachine::TNodeContextBase& aContext) |
|
51 { |
|
52 #ifdef __GCCXML__ |
|
53 return EFalse; |
|
54 #else |
|
55 return TMUTEX1::IsBlocked(aContext) && TMUTEX2::IsBlocked(aContext); |
|
56 #endif |
|
57 } |
|
58 }; |
|
59 |
|
60 /** |
|
61 Template to aggregate two mutexes with an logical OR operator |
|
62 |
|
63 @code |
|
64 typedef TAggregatedMutex_OR<THaveDataClientsMutex, THaveControlClientsMutex> THaveDataClientsOrControlClientsMutex; |
|
65 @endcode |
|
66 |
|
67 @param TMUTEX1 First mutex to test |
|
68 @param TMUTEX2 Second mutex to test |
|
69 */ |
|
70 template <class TMUTEX1, class TMUTEX2> |
|
71 class TAggregatedMutex_OR |
|
72 { |
|
73 public: |
|
74 /** |
|
75 @param aContext context in which to evaluate the mutexes |
|
76 @return ETrue if operation should be blocked, EFalse if neither mutex condition has been met |
|
77 */ |
|
78 inline static TBool IsBlocked(const MeshMachine::TNodeContextBase& aContext) |
|
79 { |
|
80 #ifdef __GCCXML__ |
|
81 return EFalse; |
|
82 #else |
|
83 return TMUTEX1::IsBlocked(aContext) || TMUTEX2::IsBlocked(aContext); |
|
84 #endif |
|
85 } |
|
86 }; |
|
87 |
|
88 |
|
89 /** |
|
90 Template to block if an activity is running |
|
91 @param ACTIVITYID activity to test for |
|
92 */ |
|
93 template <TInt ACTIVITYID> |
|
94 class TActivityIdMutex |
|
95 { |
|
96 public: |
|
97 /** |
|
98 @param aContext context in which to evaluate the mutexes |
|
99 @return ETrue if operation should be blocked, EFalse if mutex condition has been met |
|
100 */ |
|
101 inline static TBool IsBlocked(const MeshMachine::TNodeContextBase& aContext) |
|
102 { |
|
103 return aContext.iNode.CountActivities(ACTIVITYID) != 0; |
|
104 } |
|
105 }; |
|
106 |
|
107 /** |
|
108 Template to block if there is an activity on a node in a non waiting state |
|
109 @param ACTIVITYID id of activities to search for |
|
110 */ |
|
111 template <TInt ACTIVITYID> |
|
112 class TNonWaitingActivityIdMutex |
|
113 { |
|
114 public: |
|
115 /** |
|
116 @param aContext context in which to evaluate the mutexes |
|
117 @return ETrue if there exists activities with specified id, which are not in a waiting state. |
|
118 */ |
|
119 inline static TBool IsBlocked(const MeshMachine::TNodeContextBase& aContext) |
|
120 { |
|
121 const RPointerArray<CNodeActivityBase>& activities = aContext.iNode.Activities(); |
|
122 TInt i = activities.Count(); |
|
123 while (i>0) |
|
124 { |
|
125 CNodeActivityBase* a = activities[--i]; |
|
126 if (ACTIVITYID == a->ActivitySigId()) |
|
127 { |
|
128 AActivitySemaphore* as = static_cast<AActivitySemaphore*>(a->FetchExtInterface(AActivitySemaphore::KInterfaceId)); |
|
129 if (as && !as->IsWaiting()) |
|
130 { |
|
131 return ETrue; |
|
132 } |
|
133 } |
|
134 } |
|
135 return EFalse; |
|
136 } |
|
137 }; |
|
138 |
|
139 /** |
|
140 Mutex checking multiple non waiting activities |
|
141 @param ACTIVITYID1 First activity to check for |
|
142 @param ACTIVITYID2 Second activity to check for |
|
143 @param ACTIVITYID3 Third activity to check for, defaults to 0 in which case the parameter is ignored |
|
144 @param ACTIVITYID4 Fourth activity to check for, defaults to 0 in which case the parameter is ignored |
|
145 @param ACTIVITYID5 Fifth activity to check for, defaults to 0 in which case the parameter is ignored |
|
146 */ |
|
147 template <TInt ACTIVITYID1, TInt ACTIVITYID2, TInt ACTIVITYID3 = 0, TInt ACTIVITYID4 = 0, TInt ACTIVITYID5 = 0> |
|
148 class TNonWaitingActivitiesIdMutex |
|
149 { |
|
150 public: |
|
151 /** |
|
152 @param aContext context in which to evaluate the mutexes |
|
153 @return ETrue if there exists all the activities with the specified ids, which are not in a waiting state. |
|
154 */ |
|
155 inline static TBool IsBlocked(const MeshMachine::TNodeContextBase& aContext) |
|
156 { |
|
157 const RPointerArray<CNodeActivityBase>& activities = aContext.iNode.Activities(); |
|
158 TInt i = activities.Count(); |
|
159 while (i>0) |
|
160 { |
|
161 CNodeActivityBase* a = activities[--i]; |
|
162 TInt sigId = a->ActivitySigId(); |
|
163 |
|
164 if (ACTIVITYID1 == sigId || ACTIVITYID2 == sigId || ACTIVITYID3 == sigId || ACTIVITYID4 == sigId || ACTIVITYID5 == sigId) |
|
165 { |
|
166 AActivitySemaphore* as = static_cast<AActivitySemaphore*>(a->FetchExtInterface(AActivitySemaphore::KInterfaceId)); |
|
167 if (as && !as->IsWaiting()) |
|
168 { |
|
169 return ETrue; |
|
170 } |
|
171 } |
|
172 } |
|
173 return EFalse; |
|
174 } |
|
175 }; |
|
176 |
|
177 /** |
|
178 Mutex checking multiple incompatible activities ids |
|
179 @param ACTIVITYID1 First activity to check for |
|
180 @param ACTIVITYID2 Second activity to check for |
|
181 @param ACTIVITYID3 Third activity to check for, defaults to 0 in which case the parameter is ignored |
|
182 @param ACTIVITYID4 Fourth activity to check for, defaults to 0 in which case the parameter is ignored |
|
183 @param ACTIVITYID5 Fifth activity to check for, defaults to 0 in which case the parameter is ignored |
|
184 */ |
|
185 template <TInt ACTIVITYID1, TInt ACTIVITYID2, TInt ACTIVITYID3 = 0, TInt ACTIVITYID4 = 0, TInt ACTIVITYID5 = 0> |
|
186 class TActivitiesIdMutex |
|
187 { |
|
188 public: |
|
189 /** |
|
190 @param aContext context in which to evaluate the mutexes |
|
191 @return ETrue if there exists all the activities with the specified ids, EFalse otherwise |
|
192 */ |
|
193 inline static TBool IsBlocked(const MeshMachine::TNodeContextBase& aContext) |
|
194 { |
|
195 TBool isBlocked = aContext.iNode.CountActivities(ACTIVITYID1) != 0; |
|
196 isBlocked |= aContext.iNode.CountActivities(ACTIVITYID2) != 0; |
|
197 isBlocked |= (ACTIVITYID3)? aContext.iNode.CountActivities(ACTIVITYID3) != 0 : EFalse; |
|
198 isBlocked |= (ACTIVITYID4)? aContext.iNode.CountActivities(ACTIVITYID4) != 0 : EFalse; |
|
199 isBlocked |= (ACTIVITYID5)? aContext.iNode.CountActivities(ACTIVITYID5) != 0 : EFalse; |
|
200 return isBlocked; |
|
201 } |
|
202 }; |
|
203 |
|
204 /** |
|
205 Mutex checking all activities |
|
206 */ |
|
207 class TAllActivitiesMutex |
|
208 { |
|
209 public: |
|
210 /** |
|
211 @param aContext context in which to evaluate the mutexes |
|
212 @return ETrue if there are any activities running, EFalse otherwise |
|
213 */ |
|
214 inline static TBool IsBlocked(const MeshMachine::TNodeContextBase& aContext) |
|
215 { |
|
216 return aContext.iNode.CountAllActivities() != 0; |
|
217 } |
|
218 }; |
|
219 |
|
220 /** |
|
221 Mutex checking presence of a particular client |
|
222 @param TMATCHPOLICY Match policy |
|
223 @param TYPE Type to match against |
|
224 @param FLAGS Flags to match against |
|
225 |
|
226 @see ANodeBase::CountClients |
|
227 */ |
|
228 template <class TMATCHPOLICY, TInt TYPE, TInt FLAGS = 0> |
|
229 class TClientMutex |
|
230 { |
|
231 public: |
|
232 /** |
|
233 @param aContext context in which to evaluate the mutexes |
|
234 @return ETrue if a client exists which matches the criteria. EFalse otherwise |
|
235 */ |
|
236 inline static TBool IsBlocked(const MeshMachine::TNodeContextBase& aContext) |
|
237 { |
|
238 #ifdef __GCCXML__ |
|
239 return EFalse; |
|
240 #else |
|
241 return aContext.iNode.CountClients<TMATCHPOLICY>(Messages::TClientType(TYPE,FLAGS)) != 0; |
|
242 #endif |
|
243 } |
|
244 }; |
|
245 |
|
246 /** |
|
247 Mutex checking lack of presence of a particular client |
|
248 @param TMATCHPOLICY Match policy |
|
249 @param TYPE Type to match against |
|
250 @param FLAGS Flags to match against |
|
251 |
|
252 @see ANodeBase::CountClients |
|
253 */ |
|
254 template <class TMATCHPOLICY, TInt TYPE, TInt FLAGS = 0> |
|
255 class TNoClientMutex |
|
256 { |
|
257 public: |
|
258 /** |
|
259 @param aContext context in which to evaluate the mutexes |
|
260 @return ETrue if a client does not exist which matches the criteria. EFalse otherwise |
|
261 */ |
|
262 inline static TBool IsBlocked(const MeshMachine::TNodeContextBase& aContext) |
|
263 { |
|
264 #ifdef __GCCXML__ |
|
265 return EFalse; |
|
266 #else |
|
267 return aContext.iNode.CountClients<TMATCHPOLICY>(Messages::TClientType(TYPE,FLAGS)) == 0; |
|
268 #endif |
|
269 } |
|
270 }; |
|
271 |
|
272 } //namespace MeshMachine |
|
273 |
|
274 #endif |
|
275 //SYMBIAN_MM_MUTEXPOLICIES_H |
|
276 |