|
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 // @file T_Lbschannel.cpp |
|
15 // This is the Cpp file which contains the channel for communication between |
|
16 // the test harness and the test AGps module. |
|
17 // |
|
18 // |
|
19 |
|
20 // User includes |
|
21 #include "tlbschannel.h" |
|
22 |
|
23 const TInt KLbsChannelIdMax = RT_LbsChannel::EChannelTAGPS2TH; |
|
24 //const TInt KCategoryKeyIndex = 0; |
|
25 const TInt KReadPropKeyIndex = 1; |
|
26 const TInt KReadPropAckKeyIndex = 2; |
|
27 const TInt KWritePropKeyIndex = 3; |
|
28 const TInt KWritePropAckKeyIndex = 4; |
|
29 |
|
30 /** The array contains description (property size, keys and Ids) of all the channels supported by |
|
31 the RT_LbsChannel interface */ |
|
32 const TUint KPropTable[KLbsChannelIdMax+1][5]= |
|
33 { |
|
34 {0, KTH2TAGPSMessageKey, KTH2TAGPSMessageReadAckKey, KTAGPS2THMessageKey, KTAGPS2THMessageReadAckKey}, |
|
35 {0, KTAGPS2THMessageKey, KTAGPS2THMessageReadAckKey, KTH2TAGPSMessageKey, KTH2TAGPSMessageReadAckKey}, |
|
36 }; |
|
37 |
|
38 // |
|
39 // RT_LbsChannel |
|
40 // |
|
41 |
|
42 EXPORT_C void RT_LbsChannel::InitializeL(TT_LbsChannelId aChannelId) |
|
43 { |
|
44 const TSecurityPolicy KReadPolicy(ECapability_None); |
|
45 const TSecurityPolicy KWritePolicy(ECapabilityWriteDeviceData); |
|
46 |
|
47 TInt err = RProperty::Define(KUidSystemCategory, |
|
48 KPropTable[aChannelId][KWritePropKeyIndex], |
|
49 RProperty::ELargeByteArray, |
|
50 KReadPolicy, KWritePolicy, |
|
51 sizeof(TT_LbsMsgBase)); |
|
52 if (err != KErrNone && err != KErrAlreadyExists) |
|
53 { |
|
54 User::Leave(err); |
|
55 } |
|
56 |
|
57 err = RProperty::Define(KUidSystemCategory, |
|
58 KPropTable[aChannelId][KWritePropAckKeyIndex], |
|
59 RProperty::EInt, |
|
60 KReadPolicy, KWritePolicy); |
|
61 if (err != KErrNone && err != KErrAlreadyExists) |
|
62 { |
|
63 User::Leave(err); |
|
64 } |
|
65 |
|
66 User::LeaveIfError(RProperty::Set(KUidSystemCategory, KPropTable[aChannelId][KWritePropAckKeyIndex], 0)); |
|
67 } |
|
68 |
|
69 |
|
70 EXPORT_C void RT_LbsChannel::ShutDownL(TT_LbsChannelId aChannelId) |
|
71 { |
|
72 User::LeaveIfError(RProperty::Delete(KPropTable[aChannelId][KWritePropKeyIndex])); |
|
73 User::LeaveIfError(RProperty::Delete(KPropTable[aChannelId][KWritePropAckKeyIndex])); |
|
74 } |
|
75 |
|
76 |
|
77 EXPORT_C RT_LbsChannel::RT_LbsChannel() |
|
78 { |
|
79 } |
|
80 |
|
81 |
|
82 /** |
|
83 |
|
84 The channel must first be initialised before this is called, otherwise the |
|
85 resources needed by the channel will not have been allocated. |
|
86 |
|
87 @param aObserver Reference to the observer class used to notify of new messages. |
|
88 @param aChannelId Uid of the RProperty category used for this channel. |
|
89 |
|
90 @leave |
|
91 */ |
|
92 EXPORT_C void RT_LbsChannel::OpenL(TT_LbsChannelId aChannelId, MT_LbsChannelObserver& aObserver) |
|
93 { |
|
94 __ASSERT_DEBUG(iSendProperty.Handle()==NULL, User::Invariant()); |
|
95 __ASSERT_DEBUG(iSendMsgReadProperty.Handle()==NULL, User::Invariant()); |
|
96 |
|
97 User::LeaveIfError(iSendProperty.Attach(KUidSystemCategory, KPropTable[aChannelId][KWritePropKeyIndex])); |
|
98 User::LeaveIfError(iSendMsgReadProperty.Attach(KUidSystemCategory, KPropTable[aChannelId][KWritePropAckKeyIndex])); |
|
99 |
|
100 iMonitor = CT_ChannelMonitor::NewL(aObserver, aChannelId, KUidSystemCategory, |
|
101 KPropTable[aChannelId][KReadPropKeyIndex], |
|
102 KPropTable[aChannelId][KReadPropAckKeyIndex]); |
|
103 } |
|
104 |
|
105 /** Close the connection. |
|
106 |
|
107 This function closes the connection and frees any resources |
|
108 created in RTbsChannel::OpenL(). |
|
109 */ |
|
110 EXPORT_C void RT_LbsChannel::Close() |
|
111 { |
|
112 CancelSendMessageNotification(); |
|
113 |
|
114 delete iMonitor; |
|
115 iSendProperty.Close(); |
|
116 iSendMsgReadProperty.Close(); |
|
117 } |
|
118 |
|
119 /** Send a message through the channel. |
|
120 |
|
121 This is an asynchronous function that only completes when the message |
|
122 has been read. |
|
123 |
|
124 If another call is made to this function before a previous one has |
|
125 completed then aStatus will be completed straight away, with the |
|
126 completion code KErrInUse. |
|
127 |
|
128 @param aMessage The message to be sent. |
|
129 @param aStatus Request status that is completed when the message has |
|
130 been read. If there is an error sending the message |
|
131 it will be stored in aStatus.Int(). |
|
132 */ |
|
133 EXPORT_C void RT_LbsChannel::SendMessage(const TT_LbsMsgBase& aMessage, |
|
134 TRequestStatus& aStatus) |
|
135 { |
|
136 // Must check that the previous message was read |
|
137 TInt sendAck; |
|
138 iSendMsgReadProperty.Get(sendAck); |
|
139 if (sendAck == 1) |
|
140 { |
|
141 // Pending message has not been read yet; flag an error |
|
142 TRequestStatus* statPtr = &aStatus; |
|
143 User::RequestComplete(statPtr, KErrInUse); |
|
144 } |
|
145 else |
|
146 { |
|
147 // Publish the new message |
|
148 iSendMsgReadProperty.Set(1); |
|
149 iSendMsgReadProperty.Subscribe(aStatus); |
|
150 TPckgC<TT_LbsMsgBase> pckg(aMessage); |
|
151 iSendProperty.Set(pckg); |
|
152 } |
|
153 } |
|
154 |
|
155 /** Cancel the current request status for SendMessage(). |
|
156 */ |
|
157 EXPORT_C void RT_LbsChannel::CancelSendMessageNotification() |
|
158 { |
|
159 iSendMsgReadProperty.Cancel(); |
|
160 } |
|
161 |
|
162 |
|
163 // |
|
164 // CT_ChannelMonitor - used to listen for incoming messages |
|
165 // |
|
166 CT_ChannelMonitor* CT_ChannelMonitor::NewL(MT_LbsChannelObserver& aObserver, RT_LbsChannel::TT_LbsChannelId aChannelId, TUid aPropId, TUint aPropKey, TUint aAckPropKey) |
|
167 { |
|
168 CT_ChannelMonitor* self = new (ELeave) CT_ChannelMonitor(aObserver, aChannelId); |
|
169 CleanupStack::PushL(self); |
|
170 self->ConstructL(aPropId, aPropKey, aAckPropKey); |
|
171 CleanupStack::Pop(); |
|
172 return self; |
|
173 } |
|
174 |
|
175 CT_ChannelMonitor::CT_ChannelMonitor(MT_LbsChannelObserver& aObserver, RT_LbsChannel::TT_LbsChannelId aChannelId) : |
|
176 CActive(EPriorityStandard), |
|
177 iObserver(aObserver), |
|
178 iChannelId(aChannelId) |
|
179 { |
|
180 CActiveScheduler::Add(this); |
|
181 } |
|
182 |
|
183 CT_ChannelMonitor::~CT_ChannelMonitor() |
|
184 { |
|
185 Cancel(); |
|
186 iReceiveProperty.Close(); |
|
187 iReceiveMsgReadProperty.Close(); |
|
188 } |
|
189 |
|
190 void CT_ChannelMonitor::ConstructL(TUid aPropId, TUint aPropKey, TUint aAckPropKey) |
|
191 { |
|
192 __ASSERT_DEBUG(iReceiveProperty.Handle()==NULL, User::Invariant()); //Handle open. |
|
193 __ASSERT_DEBUG(iReceiveMsgReadProperty.Handle()==NULL, User::Invariant()); //Handle open. |
|
194 |
|
195 User::LeaveIfError(iReceiveProperty.Attach(aPropId, aPropKey)); |
|
196 User::LeaveIfError(iReceiveMsgReadProperty.Attach(aPropId, aAckPropKey)); |
|
197 |
|
198 NotifyChannelMessage(); |
|
199 // flag we are ready for receiving messages |
|
200 iReceiveMsgReadProperty.Set(0); |
|
201 } |
|
202 |
|
203 void CT_ChannelMonitor::NotifyChannelMessage() |
|
204 { |
|
205 iReceiveProperty.Subscribe(iStatus); |
|
206 SetActive(); |
|
207 } |
|
208 |
|
209 void CT_ChannelMonitor::RunL() |
|
210 { |
|
211 TInt result = iStatus.Int(); |
|
212 switch (result) |
|
213 { |
|
214 case KErrNone: |
|
215 { |
|
216 // Read property |
|
217 TT_LbsMsgBase msg; |
|
218 TPckg<TT_LbsMsgBase> pckg(msg); |
|
219 iReceiveProperty.Get(pckg); |
|
220 |
|
221 // resubscribe for further messages |
|
222 NotifyChannelMessage(); |
|
223 |
|
224 // Notify observer |
|
225 iObserver.ProcessChannelMessage(iChannelId, msg); |
|
226 |
|
227 // flag message as read |
|
228 iReceiveMsgReadProperty.Set(0); |
|
229 break; |
|
230 } |
|
231 default: |
|
232 { |
|
233 User::Leave(result); |
|
234 break; |
|
235 } |
|
236 } |
|
237 } |
|
238 |
|
239 void CT_ChannelMonitor::DoCancel() |
|
240 { |
|
241 iReceiveProperty.Cancel(); |
|
242 } |
|
243 |
|
244 TInt CT_ChannelMonitor::RunError(TInt /*aError*/) |
|
245 { |
|
246 return KErrNone; |
|
247 } |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |