|
1 /* |
|
2 * Copyright (c) 2008 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: AT command URC handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <atext.h> |
|
20 #include "HfpAtCmdHandler.h" |
|
21 #include "HFPAtUrcHandler.h" |
|
22 #include "debug.h" |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // Two-phased constructor. |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CHFPAtUrcHandler* CHFPAtUrcHandler::NewL( |
|
29 RATExt* aAtCmdExt, |
|
30 MATExtObserver& aObserver ) |
|
31 { |
|
32 CHFPAtUrcHandler* self = NewLC( aAtCmdExt, aObserver ); |
|
33 CleanupStack::Pop( self ); |
|
34 return self; |
|
35 } |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // Two-phased constructor. |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CHFPAtUrcHandler* CHFPAtUrcHandler::NewLC( |
|
42 RATExt* aAtCmdExt, |
|
43 MATExtObserver& aObserver ) |
|
44 { |
|
45 CHFPAtUrcHandler* self = new (ELeave) CHFPAtUrcHandler( aAtCmdExt, |
|
46 aObserver ); |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL(); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Destructor. |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CHFPAtUrcHandler::~CHFPAtUrcHandler() |
|
57 { |
|
58 TRACE_INFO( _L("CHFPAtUrcHandler::~CHFPAtUrcHandler()") ); |
|
59 ResetData(); |
|
60 TRACE_INFO( _L("CHFPAtUrcHandler::~CHFPAtUrcHandler() complete") ); |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // Resets data to initial values |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void CHFPAtUrcHandler::ResetData() |
|
68 { |
|
69 TRACE_INFO( _L("CHFPAtUrcHandler::ResetData()") ); |
|
70 // APIs affecting this: |
|
71 // IssueRequest() |
|
72 Stop(); |
|
73 // Don't close iAtCmdExt here (it is done in CHFPAtCmdHandler)! |
|
74 // Internal |
|
75 Initialize(); |
|
76 TRACE_INFO( _L("CHFPAtUrcHandler::ResetData() complete") ); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // Starts waiting for an incoming URC message |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 TInt CHFPAtUrcHandler::IssueRequest() |
|
84 { |
|
85 TRACE_INFO( _L("CHFPAtUrcHandler::IssueRequest()") ); |
|
86 if ( iUrcHandleState != EHFPStateIdle ) |
|
87 { |
|
88 TRACE_INFO( _L("CHFPAtUrcHandler::IssueRequest() (not ready) complete") ); |
|
89 return KErrNotReady; |
|
90 } |
|
91 iStatus = KRequestPending; |
|
92 iAtCmdExt->ReceiveUnsolicitedResult( iStatus, iRecvBuffer, iOwnerUidPckg ); |
|
93 SetActive(); |
|
94 iUrcHandleState = EHFPStateAtUrcHandling; |
|
95 // Next mark ownership |
|
96 if ( !iStarted ) |
|
97 { |
|
98 TInt retTemp = iAtCmdExt->MarkUrcHandlingOwnership( iOwnerUid ); |
|
99 if ( retTemp != KErrNone ) |
|
100 { |
|
101 TRACE_INFO( _L("CHFPAtUrcHandler::IssueRequest() (not owned) complete") ); |
|
102 return KErrGeneral; |
|
103 } |
|
104 } |
|
105 iStarted = ETrue; |
|
106 TRACE_INFO( _L("CHFPAtUrcHandler::IssueRequest() complete") ); |
|
107 return KErrNone; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // Stops waiting for an incoming URC message |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 TInt CHFPAtUrcHandler::Stop() |
|
115 { |
|
116 TRACE_INFO( _L("CHFPAtUrcHandler::Stop()") ); |
|
117 if ( iUrcHandleState != EHFPStateAtUrcHandling ) |
|
118 { |
|
119 TRACE_INFO( _L("CHFPAtUrcHandler::Stop() (not ready) complete" ) ); |
|
120 return KErrNotReady; |
|
121 } |
|
122 iAtCmdExt->CancelReceiveUnsolicitedResult( iOwnerUid ); |
|
123 Cancel(); |
|
124 iUrcHandleState = EHFPStateIdle; |
|
125 TRACE_INFO( _L("CHFPAtUrcHandler::Stop() complete") ); |
|
126 // Note: Don't mark iStarted to EFalse here as it is used to get the UID |
|
127 return KErrNone; |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // UID of the owning plugin |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 TUid CHFPAtUrcHandler::OwnerUid() |
|
135 { |
|
136 return iOwnerUid; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // CHFPAtUrcHandler::CHFPAtUrcHandler |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 CHFPAtUrcHandler::CHFPAtUrcHandler( RATExt* aAtCmdExt, MATExtObserver& aObserver ) : |
|
144 CActive( EPriorityHigh ), |
|
145 iAtCmdExt( aAtCmdExt ), |
|
146 iObserver( aObserver ), |
|
147 iOwnerUidPckg( iOwnerUid ) |
|
148 |
|
149 { |
|
150 Initialize(); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CHFPAtUrcHandler::ConstructL |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CHFPAtUrcHandler::ConstructL() |
|
158 { |
|
159 TRACE_INFO( _L("CHFPAtUrcHandler::ConstructL()") ); |
|
160 if ( !iAtCmdExt ) |
|
161 { |
|
162 User::Leave( KErrGeneral ); |
|
163 } |
|
164 CActiveScheduler::Add( this ); |
|
165 TRACE_INFO( _L("CHFPAtUrcHandler::ConstructL() complete") ); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // Initializes this class |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CHFPAtUrcHandler::Initialize() |
|
173 { |
|
174 iUrcHandleState = EHFPStateIdle; |
|
175 iOwnerUid = TUid::Null(); |
|
176 iStarted = EFalse; |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // From class CActive. |
|
181 // Gets called when URC command received |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 void CHFPAtUrcHandler::RunL() |
|
185 { |
|
186 TRACE_INFO( _L("CHFPAtUrcHandler::RunL()") ); |
|
187 iUrcHandleState = EHFPStateIdle; |
|
188 TInt err = iStatus.Int(); |
|
189 |
|
190 // Send received URC message |
|
191 if (err == KErrNone) |
|
192 { |
|
193 if ( iRecvBuffer.Length() == 0 ) |
|
194 { |
|
195 TRACE_INFO( _L("CHFPAtUrcHandler::RunL() (empty buffer) complete") ); |
|
196 iObserver.UnsolicitedResultFromATExtL(err, KNullDesC8); |
|
197 } |
|
198 iObserver.UnsolicitedResultFromATExtL(err, iRecvBuffer); |
|
199 |
|
200 IssueRequest(); |
|
201 } |
|
202 else |
|
203 { |
|
204 //TRACE_INFO( _L("CHFPAtUrcHandler::RunL() (ERROR) complete (%d)"), err)); |
|
205 iObserver.UnsolicitedResultFromATExtL(err, KNullDesC8); |
|
206 } |
|
207 |
|
208 TRACE_INFO( _L("CHFPAtUrcHandler::RunL() complete") ); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // From class CActive. |
|
213 // Gets called on cancel |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 void CHFPAtUrcHandler::DoCancel() |
|
217 { |
|
218 } |