|
1 // Copyright (c) 1999-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 BTSTATE_H__ |
|
17 #define BTSTATE_H__ |
|
18 |
|
19 #include "btcommutil.h" |
|
20 |
|
21 class TBTPortState; |
|
22 NONSHARABLE_CLASS(CBTPortStateFactory) : public CBase |
|
23 { |
|
24 friend class CBTPortFactory; |
|
25 // only a friend can instantiate a CBTPortStateFactory... |
|
26 public: |
|
27 enum TCSYState |
|
28 { |
|
29 EIdle, |
|
30 ELoadingProtocol, |
|
31 EDiscovering, |
|
32 ESDPConnected, |
|
33 ESDPServiceQuery, |
|
34 ESDPServiceIDListRetrieved, |
|
35 ESDPAttribListRetrieved, |
|
36 ESecuritySetup, |
|
37 EConnecting, |
|
38 EOpen, |
|
39 EClosing, |
|
40 EError, |
|
41 // *** keep next one last *** |
|
42 EMaxCSYStates, |
|
43 }; |
|
44 |
|
45 ~CBTPortStateFactory(); |
|
46 TBTPortState& GetState(const TCSYState aState); |
|
47 TInt StateIndex(const TBTPortState* aState) const; |
|
48 private: |
|
49 static CBTPortStateFactory *NewL(); |
|
50 CBTPortStateFactory(); |
|
51 void InitL(); |
|
52 private: |
|
53 TFixedArray<TBTPortState*, EMaxCSYStates> iStates; |
|
54 public: |
|
55 TInt iSDPServRecordHandleCount; |
|
56 TInt iExtractedHandleCount; |
|
57 }; |
|
58 |
|
59 NONSHARABLE_CLASS(TBTPortState) |
|
60 // abstract base class for CSY state objects. |
|
61 { |
|
62 public: |
|
63 TBTPortState(CBTPortStateFactory* aFactory); |
|
64 virtual ~TBTPortState()=0; |
|
65 virtual void Open(CBTPortProxy* aContext)=0; |
|
66 virtual void Read(CBTPortProxy* aContext,TAny* aPtr,TInt aLength)=0; |
|
67 virtual void Write(CBTPortProxy* aContext,TAny* aPtr,TInt aLength)=0; |
|
68 virtual void Close(CBTPortProxy* aContext)=0; |
|
69 virtual void DoRunL(CBTPortProxy* aContext)=0; |
|
70 virtual void DoCancel(CBTPortProxy* aContext)=0; |
|
71 virtual void WriteCancel(CBTPortProxy* aContext)=0; |
|
72 virtual void ReadCancel(CBTPortProxy* aContext)=0; |
|
73 virtual void DoWriteCompleted(CBTPortProxy* aContext,TInt aError)=0; |
|
74 virtual void DoReadCompleted(CBTPortProxy* aContext,TInt aError)=0; |
|
75 virtual void DoLockedAction(CBTPortProxy* aContext)=0; |
|
76 virtual void Error(CBTPortProxy* aContext,TInt aError)=0; |
|
77 protected: |
|
78 void PanicInState(TBTCommPanic aPanic) const; |
|
79 protected: |
|
80 CBTPortStateFactory* iFactory; |
|
81 private: |
|
82 // Forbid copying |
|
83 TBTPortState(const TBTPortState&); |
|
84 const TBTPortState& operator=(const TBTPortState&); |
|
85 }; |
|
86 |
|
87 NONSHARABLE_CLASS(TBTPortDefaultState) : public TBTPortState |
|
88 // contains default overrides for TBTPortState functions |
|
89 { |
|
90 public: |
|
91 TBTPortDefaultState(CBTPortStateFactory* aParent); |
|
92 virtual ~TBTPortDefaultState(); |
|
93 virtual void Open(CBTPortProxy* aContext); |
|
94 virtual void Read(CBTPortProxy* aContext,TAny* aPtr, TInt aLength); |
|
95 virtual void Write(CBTPortProxy* aContext,TAny* aPtr, TInt aLength); |
|
96 virtual void Close(CBTPortProxy* aContext); |
|
97 virtual void DoRunL(CBTPortProxy* aContext); |
|
98 virtual void DoCancel(CBTPortProxy* aContext); |
|
99 virtual void WriteCancel(CBTPortProxy* aContext); |
|
100 virtual void ReadCancel(CBTPortProxy* aContext); |
|
101 virtual void DoLockedAction(CBTPortProxy* aContext); |
|
102 virtual void DoWriteCompleted(CBTPortProxy* aContext, TInt aError); |
|
103 virtual void DoReadCompleted(CBTPortProxy* aContext, TInt aError); |
|
104 virtual void Error(CBTPortProxy* aContext,TInt aError); |
|
105 virtual void LogStateError(CBTPortProxy* aContext, TInt aError)=0; |
|
106 }; |
|
107 |
|
108 |
|
109 NONSHARABLE_CLASS(TBTPortCommonBaseState) : public TBTPortDefaultState |
|
110 { |
|
111 public: |
|
112 TBTPortCommonBaseState(CBTPortStateFactory* aParent); |
|
113 virtual void Read(CBTPortProxy* aContext,TAny* aPtr, TInt aLength); |
|
114 virtual void Write(CBTPortProxy* aContext,TAny* aPtr, TInt aLength); |
|
115 virtual void WriteCancel(CBTPortProxy* aContext); |
|
116 virtual void ReadCancel(CBTPortProxy* aContext); |
|
117 virtual void Close(CBTPortProxy* aContext); |
|
118 }; |
|
119 |
|
120 NONSHARABLE_CLASS(TBTPortStateIdle) : public TBTPortCommonBaseState |
|
121 { |
|
122 public: |
|
123 TBTPortStateIdle(CBTPortStateFactory* aParent); |
|
124 ~TBTPortStateIdle(); |
|
125 virtual void DoRunL(CBTPortProxy* aContext); |
|
126 virtual void Open(CBTPortProxy* aContext); |
|
127 virtual void Close(CBTPortProxy* aContext); |
|
128 virtual void Read(CBTPortProxy* aContext,TAny* aPtr, TInt aLength); |
|
129 virtual void Write(CBTPortProxy* aContext,TAny* aPtr, TInt aLength); |
|
130 virtual void LogStateError(CBTPortProxy* aContext, TInt aError); |
|
131 private: |
|
132 void SockServConnect(CBTPortProxy* aContext); // to be called by friendly class |
|
133 //upon re-opening while closing |
|
134 friend class CBTPortProxy; |
|
135 }; |
|
136 |
|
137 NONSHARABLE_CLASS(TBTPortStateLoadingProtocol) : public TBTPortCommonBaseState |
|
138 { |
|
139 public: |
|
140 TBTPortStateLoadingProtocol(CBTPortStateFactory* aParent); |
|
141 ~TBTPortStateLoadingProtocol(); |
|
142 virtual void DoRunL(CBTPortProxy* aContext); |
|
143 virtual void Close(CBTPortProxy* aContext); |
|
144 virtual void Read(CBTPortProxy* aContext,TAny* aPtr, TInt aLength); |
|
145 virtual void Write(CBTPortProxy* aContext,TAny* aPtr, TInt aLength); |
|
146 virtual void LogStateError(CBTPortProxy* aContext, TInt aError); |
|
147 private: |
|
148 void StartProtocol(CBTPortProxy* aContext); |
|
149 private: |
|
150 TBool iClosePending; |
|
151 |
|
152 friend class CBTPortProxy; |
|
153 }; |
|
154 |
|
155 NONSHARABLE_CLASS(TBTPortStateDiscovering) : public TBTPortCommonBaseState |
|
156 { |
|
157 public: |
|
158 TBTPortStateDiscovering(CBTPortStateFactory* aParent); |
|
159 ~TBTPortStateDiscovering(); |
|
160 virtual void DoRunL(CBTPortProxy* aContext); |
|
161 virtual void DoLockedAction(CBTPortProxy* aContext); |
|
162 virtual void LogStateError(CBTPortProxy* aContext, TInt aError); |
|
163 }; |
|
164 |
|
165 |
|
166 NONSHARABLE_CLASS(TBTPortStateSDPConnected) : public TBTPortCommonBaseState |
|
167 { |
|
168 public: |
|
169 TBTPortStateSDPConnected(CBTPortStateFactory* aParent); |
|
170 ~TBTPortStateSDPConnected(); |
|
171 virtual void DoRunL(CBTPortProxy* aContext); |
|
172 virtual void LogStateError(CBTPortProxy* aContext, TInt aError); |
|
173 }; |
|
174 |
|
175 NONSHARABLE_CLASS(TBTPortStateSDPServiceQuery) : public TBTPortCommonBaseState |
|
176 { |
|
177 public: |
|
178 TBTPortStateSDPServiceQuery(CBTPortStateFactory* aParent); |
|
179 ~TBTPortStateSDPServiceQuery(); |
|
180 virtual void DoRunL(CBTPortProxy* aContext); |
|
181 virtual void LogStateError(CBTPortProxy* aContext, TInt aError); |
|
182 }; |
|
183 |
|
184 NONSHARABLE_CLASS(TBTPortStateServiceIDListRetrieved) : public TBTPortCommonBaseState |
|
185 { |
|
186 public: |
|
187 TBTPortStateServiceIDListRetrieved(CBTPortStateFactory* aParent); |
|
188 ~TBTPortStateServiceIDListRetrieved(); |
|
189 virtual void DoRunL(CBTPortProxy* aContext); |
|
190 virtual void LogStateError(CBTPortProxy* aContext, TInt aError); |
|
191 }; |
|
192 |
|
193 |
|
194 NONSHARABLE_CLASS(TBTPortStateSDPAttributeListRetrieved) : public TBTPortCommonBaseState |
|
195 { |
|
196 public: |
|
197 TBTPortStateSDPAttributeListRetrieved(CBTPortStateFactory* aParent); |
|
198 ~TBTPortStateSDPAttributeListRetrieved(); |
|
199 virtual void DoRunL(CBTPortProxy* aContext); |
|
200 virtual void DoLockedAction(CBTPortProxy* aContext); |
|
201 virtual void LogStateError(CBTPortProxy* aContext, TInt aError); |
|
202 }; |
|
203 |
|
204 NONSHARABLE_CLASS(TBTPortStateConnecting) : public TBTPortCommonBaseState |
|
205 { |
|
206 public: |
|
207 TBTPortStateConnecting(CBTPortStateFactory* aParent); |
|
208 ~TBTPortStateConnecting(); |
|
209 virtual void DoRunL(CBTPortProxy* aContext); |
|
210 virtual void LogStateError(CBTPortProxy* aContext,TInt aError); |
|
211 }; |
|
212 |
|
213 NONSHARABLE_CLASS(TBTPortStateOpen) : public TBTPortCommonBaseState |
|
214 { |
|
215 public: |
|
216 TBTPortStateOpen(CBTPortStateFactory* aParent); |
|
217 ~TBTPortStateOpen(); |
|
218 virtual void Read(CBTPortProxy* aContext,TAny* aPtr,TInt aLength); |
|
219 virtual void Write(CBTPortProxy* aContext,TAny* aPtr,TInt aLength); |
|
220 virtual void WriteCancel(CBTPortProxy* aContext); |
|
221 virtual void ReadCancel(CBTPortProxy* aContext); |
|
222 virtual void Close(CBTPortProxy* aContext); |
|
223 virtual void DoLockedAction(CBTPortProxy* aContext); |
|
224 virtual void DoWriteCompleted(CBTPortProxy* aContext,TInt aError); |
|
225 virtual void DoReadCompleted(CBTPortProxy* aContext,TInt aError); |
|
226 virtual void LogStateError(CBTPortProxy* aContext,TInt aError); |
|
227 private: |
|
228 void HandleIPCWriteToClient(CBTPortProxy* aContext); |
|
229 }; |
|
230 |
|
231 NONSHARABLE_CLASS(TBTPortStateClosing) : public TBTPortCommonBaseState |
|
232 { |
|
233 public: |
|
234 TBTPortStateClosing(CBTPortStateFactory* aParent); |
|
235 ~TBTPortStateClosing(); |
|
236 virtual void Read(CBTPortProxy* aContext,TAny* aPtr,TInt aLength); |
|
237 virtual void Write(CBTPortProxy* aContext,TAny* aPtr,TInt aLength); |
|
238 virtual void Close(CBTPortProxy* aContext); |
|
239 virtual void DoRunL(CBTPortProxy* aContext); |
|
240 virtual void DoLockedAction(CBTPortProxy* aContext); |
|
241 virtual void DoWriteCompleted(CBTPortProxy* aContext,TInt aError); |
|
242 virtual void DoReadCompleted(CBTPortProxy* aContext,TInt aError); |
|
243 virtual void LogStateError(CBTPortProxy* aContext,TInt aError); |
|
244 }; |
|
245 |
|
246 NONSHARABLE_CLASS(TBTPortErrorState) : public TBTPortState |
|
247 /** |
|
248 Error State. |
|
249 The CSY will move in this state after an error has been returned. |
|
250 From this state on Read and Write (from the client) we will return |
|
251 the error code, hence notify the client. Unfortunately this is the only |
|
252 way that we can notify C32 (and hence the client). |
|
253 */ |
|
254 { |
|
255 public: |
|
256 TBTPortErrorState(CBTPortStateFactory* aParent); |
|
257 virtual ~TBTPortErrorState(); |
|
258 virtual void Open(CBTPortProxy* aContext); |
|
259 virtual void Read(CBTPortProxy* aContext,TAny* aPtr,TInt aLength); |
|
260 virtual void Write(CBTPortProxy* aContext,TAny* aPtr,TInt aLength); |
|
261 virtual void Close(CBTPortProxy* aContext); |
|
262 virtual void DoRunL(CBTPortProxy* aContext); |
|
263 virtual void DoCancel(CBTPortProxy* aContext); |
|
264 virtual void WriteCancel(CBTPortProxy* aContext); |
|
265 virtual void ReadCancel(CBTPortProxy* aContext); |
|
266 virtual void DoLockedAction(CBTPortProxy* aContext); |
|
267 virtual void DoWriteCompleted(CBTPortProxy* aContext,TInt aError); |
|
268 virtual void DoReadCompleted(CBTPortProxy* aContext,TInt aError); |
|
269 virtual void Error(CBTPortProxy* aContext,TInt aError); |
|
270 }; |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 #endif |