|
1 // Copyright (c) 2007-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 // |
|
15 |
|
16 #ifndef CMOCKSYENGINE_H |
|
17 #define CMOCKSYENGINE_H |
|
18 |
|
19 #include <e32def.h> |
|
20 #include <e32base.h> |
|
21 class CRotatingStrBuf; |
|
22 |
|
23 #define KMaxLogLineSize 255 |
|
24 |
|
25 /** |
|
26 Listener to CMockSYEngine events |
|
27 */ |
|
28 class MMockSYEngineListener |
|
29 { |
|
30 public: |
|
31 enum TNotificationType |
|
32 { |
|
33 EHandlingTerminated, //< all messages are handled |
|
34 EFailure, //< receive message doesn't correspond to the expected one |
|
35 }; |
|
36 |
|
37 virtual void Notify(TNotificationType aNotification) =0; |
|
38 }; |
|
39 |
|
40 |
|
41 /** |
|
42 Abstract class for command data |
|
43 */ |
|
44 class MMockSyEngineData |
|
45 { |
|
46 public: |
|
47 /** |
|
48 Comparator: compare the data with it packaged version from an Event |
|
49 */ |
|
50 virtual TBool operator ==(const TDesC8& aData) const =0; |
|
51 }; |
|
52 |
|
53 |
|
54 /** |
|
55 Abstract class for the logger |
|
56 */ |
|
57 |
|
58 /** |
|
59 Mock SY engine base class |
|
60 */ |
|
61 class CMockSYEngine : public CBase |
|
62 { |
|
63 public: |
|
64 IMPORT_C virtual ~CMockSYEngine(); |
|
65 |
|
66 public: |
|
67 /** |
|
68 Called by the SY, handle received command by verifing that is the expected command |
|
69 and queuing the conresponding completions |
|
70 Return KErrCorrupt it it's not the expected command |
|
71 */ |
|
72 IMPORT_C TInt ExecuteCommandL(TInt aCmdId, MMockSyEngineData& aData); |
|
73 /** |
|
74 Check data or not depending on the aCheckData |
|
75 */ |
|
76 IMPORT_C TInt ExecuteCommandL(TInt aCmdId, MMockSyEngineData& aData, TBool aCheckData); |
|
77 |
|
78 public: |
|
79 inline void SessionClosed(); |
|
80 inline void QueueEpectedCallL(TInt aCmdId, TInt aErrorCode, TBool aLeave, HBufC8* aData); |
|
81 inline void QueueReturnCallL(TInt aCmdId, TInt aErrorCode, TInt aDelay, HBufC8* aData); |
|
82 HBufC* GetNextLogLine(); |
|
83 |
|
84 inline TBool HasWaitingEvents() const; |
|
85 inline TBool HasPendingEvents() const; |
|
86 inline TBool HasFailure() const; |
|
87 |
|
88 IMPORT_C void CheckAndUpdateTransId(TUint8 aTransId, TInt aCommandId); |
|
89 |
|
90 public: // listener API |
|
91 void AddListenerL(MMockSYEngineListener& aListener); |
|
92 void RemoveListener(MMockSYEngineListener& aListener); |
|
93 |
|
94 protected: |
|
95 IMPORT_C virtual void ConstructL(); |
|
96 IMPORT_C CMockSYEngine(); |
|
97 |
|
98 protected: |
|
99 /** |
|
100 A LTSY event. |
|
101 It can be a message as received from the LTSY or a completion to send to CTSY |
|
102 */ |
|
103 class TMockSYEvent |
|
104 { |
|
105 public: |
|
106 enum TEventType |
|
107 { |
|
108 EMessage, |
|
109 ECompletion |
|
110 }; |
|
111 TEventType iEventType; //< Event type |
|
112 TInt iCmdId; //< expected cmdId or cmdId to complete |
|
113 TInt iResultCode; //< Message or completion result code |
|
114 TBool iLeave; //< If True, leave with iResultCode error |
|
115 TInt iDelay; //< for completion: delay before sending the completion |
|
116 RBuf8 iData; //< Message or completion data |
|
117 public: |
|
118 TDblQueLink iWaitingEventQueLink; //< Link for the waiting event queue |
|
119 TDeltaQueLink iPendingEventQueLink; //< Link for the pending event queue |
|
120 }; |
|
121 |
|
122 protected: |
|
123 /** |
|
124 Complete aEvent. Subclass must implement this function and complete the |
|
125 SY request |
|
126 */ |
|
127 virtual void DoCompleteEventL(const TMockSYEvent& aEvent) =0; |
|
128 /** |
|
129 Queue an event. |
|
130 */ |
|
131 IMPORT_C virtual void DoQueueEventL(TMockSYEvent::TEventType aType, TInt aCmdId, HBufC8* aData, |
|
132 TInt aResultCode, TBool aLeave, TInt aDelay); |
|
133 /** |
|
134 Returns if MockSY can ignore a given unexpected IPC error. |
|
135 */ |
|
136 IMPORT_C virtual TBool CanIgnoreUnexpectedIpc(TInt aCmdId); |
|
137 |
|
138 private: |
|
139 TDblQue<TMockSYEvent> iWaitingEventQue; |
|
140 TDeltaQue<TMockSYEvent> iPendingEventQue; |
|
141 TBool iFailure; |
|
142 |
|
143 CPeriodic* iTimer; |
|
144 |
|
145 RPointerArray<MMockSYEngineListener> iListeners; |
|
146 |
|
147 private: |
|
148 void DoTimerCallbackL(); |
|
149 |
|
150 protected: |
|
151 IMPORT_C virtual void Failure(); |
|
152 IMPORT_C virtual void Reset(); |
|
153 |
|
154 private: // listener API |
|
155 void NotifyListeners(MMockSYEngineListener::TNotificationType aNotification); |
|
156 |
|
157 protected: // logging: can be override to log specific informations |
|
158 IMPORT_C virtual void LogRequest(TInt aCmdId, const MMockSyEngineData& aData,TInt aResultCode); |
|
159 IMPORT_C virtual void LogCompletion(TInt aCmdId, const TDesC8& aData,TInt aResultCode); |
|
160 IMPORT_C virtual void LogExpectError(TInt aCmdId, const MMockSyEngineData& aData,TInt aExpectedCmd,const TDesC8& aExpectedData, TBool aIsErrorIgnored=EFalse); |
|
161 IMPORT_C virtual void Log(const TDesC& aDesc); |
|
162 |
|
163 private: // static timer callback |
|
164 CRotatingStrBuf* iRotatingLog; |
|
165 static TInt TimerCallbackL(TAny* aPtr); |
|
166 }; |
|
167 |
|
168 |
|
169 // inlines |
|
170 inline void CMockSYEngine::QueueEpectedCallL(TInt aCmdId, TInt aErrorCode, TBool aLeave, HBufC8* aData) |
|
171 { |
|
172 DoQueueEventL(TMockSYEvent::EMessage, aCmdId, aData, aErrorCode, aLeave, 0); |
|
173 } |
|
174 |
|
175 inline void CMockSYEngine::QueueReturnCallL(TInt aCmdId, TInt aErrorCode, TInt aDelay, HBufC8* aData) |
|
176 { |
|
177 DoQueueEventL(TMockSYEvent::ECompletion, aCmdId, aData, aErrorCode, EFalse, aDelay); |
|
178 } |
|
179 |
|
180 inline TBool CMockSYEngine::HasWaitingEvents() const |
|
181 { |
|
182 return !iWaitingEventQue.IsEmpty(); |
|
183 } |
|
184 |
|
185 inline TBool CMockSYEngine::HasPendingEvents() const |
|
186 { |
|
187 return !iPendingEventQue.IsEmpty(); |
|
188 } |
|
189 |
|
190 inline TBool CMockSYEngine::HasFailure() const |
|
191 { |
|
192 return iFailure; |
|
193 } |
|
194 |
|
195 /** |
|
196 Called when the session using this engine is closed |
|
197 */ |
|
198 inline void CMockSYEngine::SessionClosed() |
|
199 { |
|
200 iFailure = EFalse; |
|
201 Reset(); |
|
202 } |
|
203 |
|
204 #endif |