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: Modem's mode listener and notifier |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "DunAtModeListen.h" |
|
20 #include "DunDebug.h" |
|
21 |
|
22 // --------------------------------------------------------------------------- |
|
23 // Two-phased constructor. |
|
24 // --------------------------------------------------------------------------- |
|
25 // |
|
26 CDunAtModeListen* CDunAtModeListen::NewL( RATExtCommon* aAtCmdExtCommon, |
|
27 MDunAtModeListen* aCallback ) |
|
28 { |
|
29 CDunAtModeListen* self = NewLC( aAtCmdExtCommon, aCallback ); |
|
30 CleanupStack::Pop( self ); |
|
31 return self; |
|
32 } |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // Two-phased constructor. |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CDunAtModeListen* CDunAtModeListen::NewLC( RATExtCommon* aAtCmdExtCommon, |
|
39 MDunAtModeListen* aCallback ) |
|
40 { |
|
41 CDunAtModeListen* self = new (ELeave) CDunAtModeListen( aAtCmdExtCommon, |
|
42 aCallback ); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Destructor. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CDunAtModeListen::~CDunAtModeListen() |
|
53 { |
|
54 FTRACE(FPrint( _L("CDunAtModeListen::~CDunAtModeListen()") )); |
|
55 ResetData(); |
|
56 FTRACE(FPrint( _L("CDunAtModeListen::~CDunAtModeListen() complete") )); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Resets data to initial values |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CDunAtModeListen::ResetData() |
|
64 { |
|
65 FTRACE(FPrint( _L("CDunAtModeListen::ResetData()") )); |
|
66 // APIs affecting this: |
|
67 // IssueRequest() |
|
68 Stop(); |
|
69 // Internal |
|
70 Initialize(); |
|
71 FTRACE(FPrint( _L("CDunAtModeListen::ResetData() complete") )); |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // Issues request to start monitoring for mode status changes |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 TInt CDunAtModeListen::IssueRequest() |
|
79 { |
|
80 FTRACE(FPrint( _L("CDunAtModeListen::IssueRequest()" ))); |
|
81 if ( iModeListenState != EDunStateIdle ) |
|
82 { |
|
83 FTRACE(FPrint( _L("CDunAtModeListen::IssueRequest() (not ready) complete" ) )); |
|
84 return KErrNotReady; |
|
85 } |
|
86 iStatus = KRequestPending; |
|
87 iAtCmdExtCommon->ReceiveModeStatusChange( iStatus, iModePckg ); |
|
88 SetActive(); |
|
89 iModeListenState = EDunStateModeListening; |
|
90 FTRACE(FPrint( _L("CDunAtModeListen::IssueRequest() complete" ))); |
|
91 return KErrNone; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // Stops monitoring for mode status changes |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 TInt CDunAtModeListen::Stop() |
|
99 { |
|
100 FTRACE(FPrint( _L("CDunAtModeListen::Stop()" ))); |
|
101 if ( iModeListenState != EDunStateModeListening ) |
|
102 { |
|
103 FTRACE(FPrint( _L("CDunAtModeListen::Stop() (not ready) complete" ) )); |
|
104 return KErrNotReady; |
|
105 } |
|
106 iAtCmdExtCommon->CancelReceiveModeStatusChange(); |
|
107 Cancel(); |
|
108 iModeListenState = EDunStateIdle; |
|
109 FTRACE(FPrint( _L("CDunAtModeListen::Stop() complete" ))); |
|
110 return KErrNone; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CDunAtModeListen::CDunAtModeListen |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 CDunAtModeListen::CDunAtModeListen( RATExtCommon* aAtCmdExtCommon, |
|
118 MDunAtModeListen* aCallback ) : |
|
119 CActive( EPriorityHigh ), |
|
120 iAtCmdExtCommon( aAtCmdExtCommon ), |
|
121 iCallback( aCallback ), |
|
122 iModePckg( iMode ) |
|
123 { |
|
124 Initialize(); |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CDunAtModeListen::ConstructL |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CDunAtModeListen::ConstructL() |
|
132 { |
|
133 FTRACE(FPrint( _L("CDunAtModeListen::ConstructL()") )); |
|
134 if ( !iAtCmdExtCommon || !iCallback ) |
|
135 { |
|
136 User::Leave( KErrGeneral ); |
|
137 } |
|
138 CActiveScheduler::Add( this ); |
|
139 FTRACE(FPrint( _L("CDunAtModeListen::ConstructL() complete") )); |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // Initializes this class |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CDunAtModeListen::Initialize() |
|
147 { |
|
148 // Don't initialize iAtCmdExtCommon here (it is set through NewL) |
|
149 // Don't initialize iCallback here (it is set through NewL) |
|
150 iModeListenState = EDunStateIdle; |
|
151 iMode = 0; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // From class CActive. |
|
156 // Gets called when mode changes |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CDunAtModeListen::RunL() |
|
160 { |
|
161 FTRACE(FPrint( _L("CDunAtModeListen::RunL()") )); |
|
162 iModeListenState = EDunStateIdle; |
|
163 TInt retTemp = iStatus.Int(); |
|
164 if ( retTemp != KErrNone ) |
|
165 { |
|
166 FTRACE(FPrint( _L("CDunAtModeListen::RunL() (ERROR) complete (%d)"), retTemp )); |
|
167 return; |
|
168 } |
|
169 FTRACE(FPrint( _L("CDunAtModeListen::RunL() managing 0x%08X" ), iMode )); |
|
170 iCallback->NotifyModeStatusChange( iMode ); |
|
171 IssueRequest(); |
|
172 FTRACE(FPrint( _L("CDunAtModeListen::RunL() complete") )); |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // From class CActive. |
|
177 // Gets called on cancel |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void CDunAtModeListen::DoCancel() |
|
181 { |
|
182 } |
|