|
1 /* |
|
2 * Copyright (c) 2005-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef BTGPSMESSAGERECEIVER_H |
|
22 #define BTGPSMESSAGERECEIVER_H |
|
23 |
|
24 // INCLUDES |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <badesca.h> |
|
28 #include "BTGPSDeviceListener.h" |
|
29 #include "BTGPSMessageDef.h" |
|
30 |
|
31 |
|
32 // CONSTANTS |
|
33 /** |
|
34 * The size of the input buffer size. |
|
35 */ |
|
36 const TInt KReadMessageSize = 120; |
|
37 |
|
38 // MACROS |
|
39 |
|
40 // DATA TYPES |
|
41 |
|
42 // FUNCTION PROTOTYPES |
|
43 |
|
44 // FORWARD DECLARATIONS |
|
45 class RSocket; |
|
46 class MBTGPSMessageListener; |
|
47 class CBTGPSDeviceManager; |
|
48 |
|
49 // CLASS DECLARATION |
|
50 |
|
51 /** |
|
52 * This class is used to receive message from socket. It contains buffer |
|
53 * that store the received message and informs all the listeners on received |
|
54 * message. |
|
55 * |
|
56 */ |
|
57 class CBTGPSMessageReceiver: public CActive, private MBTGPSDeviceListener |
|
58 { |
|
59 public: |
|
60 |
|
61 /** |
|
62 * Two-phase construction. |
|
63 * @param aSocket Reference to RSocket. |
|
64 * @param aDeviceManager Reference to device manager. |
|
65 */ |
|
66 static CBTGPSMessageReceiver * NewL( |
|
67 RSocket& aSocket, |
|
68 CBTGPSDeviceManager& aDeviceManager); |
|
69 |
|
70 /** |
|
71 * Destructor |
|
72 */ |
|
73 virtual ~CBTGPSMessageReceiver(); |
|
74 |
|
75 /** |
|
76 * Add message listener |
|
77 * @param aListener Reference to listener |
|
78 */ |
|
79 void AddMessageListenerL(MBTGPSMessageListener& aListener); |
|
80 |
|
81 /** |
|
82 * Remove message listener; |
|
83 * @param aListener Reference to listener |
|
84 */ |
|
85 void RemoveMessageListener(MBTGPSMessageListener& aListener); |
|
86 |
|
87 private: |
|
88 /** |
|
89 * From CActive |
|
90 */ |
|
91 virtual void RunL(); |
|
92 |
|
93 /** |
|
94 * From CActive |
|
95 */ |
|
96 virtual void DoCancel(); |
|
97 |
|
98 /** |
|
99 * From CActive |
|
100 */ |
|
101 virtual TInt RunError(TInt aError); |
|
102 |
|
103 /** |
|
104 * From MDeviceListener |
|
105 */ |
|
106 virtual void BTDeviceStatusChanged( |
|
107 TInt aConnectStatus, |
|
108 TInt aDeviceType, |
|
109 TInt aErr=KErrNone); |
|
110 |
|
111 |
|
112 private: |
|
113 |
|
114 /** |
|
115 * Second phase of the construction |
|
116 */ |
|
117 void ConstructL(); |
|
118 |
|
119 /** |
|
120 * Receive message from socket |
|
121 */ |
|
122 void Receive(); |
|
123 |
|
124 /** |
|
125 * Handle received message from RSocket |
|
126 */ |
|
127 void HandleReceivedMessage(); |
|
128 |
|
129 /** |
|
130 * Inform listeners on received NMEA sentence |
|
131 */ |
|
132 void InformListeners(); |
|
133 |
|
134 /** |
|
135 * Private constructor |
|
136 */ |
|
137 CBTGPSMessageReceiver( |
|
138 RSocket& aSocket, |
|
139 CBTGPSDeviceManager& aDeviceManager); |
|
140 |
|
141 private: |
|
142 //Socket |
|
143 RSocket& iSocket; |
|
144 |
|
145 //Device manager |
|
146 CBTGPSDeviceManager& iDeviceManager; |
|
147 |
|
148 //Message listener |
|
149 RArray<MBTGPSMessageListener*> iListenerArray; |
|
150 |
|
151 //Buffer for receiving |
|
152 TBuf8<KReadMessageSize> iBuffer; |
|
153 |
|
154 //Buffer for NMEA message |
|
155 TBuf8<KMaxNmeaMessageSize> iNmeaBuf; |
|
156 |
|
157 //Received message length |
|
158 TSockXfrLength iRecLen; |
|
159 }; |
|
160 #endif |
|
161 // End of File |
|
162 |