|
1 /* |
|
2 * Copyright (c) 2003 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: Implementation of the class CMcn. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <cmcn.h> |
|
21 #include <ccbsmcnlistener.h> |
|
22 #include <mcbsmcnobserver.h> |
|
23 #include <cbsmcnpanic.h> |
|
24 #include "CbsLogger.h" |
|
25 #include <cmcntopicarray.h> |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KReservedSpaceForMcnObservers = 3; |
|
29 |
|
30 // ==================== LOCAL FUNCTIONS ==================== |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CMcn::CMcn |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CMcn::CMcn() |
|
41 { |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CMcn::ConstructL |
|
46 // Symbian 2nd phase constructor can leave. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void CMcn::ConstructL() |
|
50 { |
|
51 CBSLOGSTRING("CBSMCNCLIENT: >>> CMcn::ConstructL()"); |
|
52 |
|
53 User::LeaveIfError( iSession.Connect() ); |
|
54 iObservers = new ( ELeave ) CArrayPtrFlat< MCbsMcnObserver > |
|
55 ( KReservedSpaceForMcnObservers ); |
|
56 iMcnListener = CCbsMcnListener::NewL( *this, iSession ); |
|
57 |
|
58 CBSLOGSTRING("CBSMCNCLIENT: <<< CMcn::ConstructL()"); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CMcn::NewL |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C CMcn* CMcn::NewL() |
|
67 { |
|
68 CMcn* self = new ( ELeave ) CMcn; |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop(); |
|
72 return self; |
|
73 } |
|
74 |
|
75 |
|
76 // Destructor |
|
77 EXPORT_C CMcn::~CMcn() |
|
78 { |
|
79 if ( iObservers != NULL ) |
|
80 { |
|
81 iObservers->ResetAndDestroy(); |
|
82 } |
|
83 delete iObservers; |
|
84 delete iMcnListener; |
|
85 iSession.Close(); |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CMcn::RegisterL |
|
90 // Registers an observer to CBS server. |
|
91 // (other items were commented in a header). |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C void CMcn::RegisterL( |
|
95 MCbsMcnObserver* aObserver, |
|
96 const CMcnTopicArray& aArray ) |
|
97 { |
|
98 CBSLOGSTRING("CBSMCNCLIENT: >>> CMcn::RegisterL()"); |
|
99 |
|
100 __ASSERT_DEBUG( aObserver != 0, CbsMcnPanic( EMcnObserverNull ) ); |
|
101 iObservers->AppendL( aObserver ); |
|
102 iSession.RegisterL( aArray ); |
|
103 |
|
104 CBSLOGSTRING("CBSMCNCLIENT: <<< CMcn::RegisterL()"); |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CMcn::UnregisterL |
|
109 // Unregisters a previously registered MCN observer clearing |
|
110 // any topic subscriptions of this client in CBS server. |
|
111 // (other items were commented in a header). |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 EXPORT_C void CMcn::Unregister( |
|
115 MCbsMcnObserver* aObserver ) |
|
116 { |
|
117 CBSLOGSTRING("CBSMCNCLIENT: >>> CMcn::Unregister()"); |
|
118 |
|
119 __ASSERT_DEBUG( aObserver !=0 , CbsMcnPanic( EMcnObserverNull ) ); |
|
120 TInt count( iObservers->Count() ); |
|
121 for( TInt i = 0; i < count; i++ ) |
|
122 { |
|
123 MCbsMcnObserver* observer = iObservers->At( i ); |
|
124 if ( observer == aObserver ) |
|
125 { |
|
126 iObservers->Delete( i ); |
|
127 break; |
|
128 } |
|
129 } |
|
130 |
|
131 // ignore result for now |
|
132 TInt result( KErrNone ); |
|
133 TRAP( result, iSession.ClearSubscriptionsL() ); |
|
134 |
|
135 CBSLOGSTRING("CBSMCNCLIENT: <<< CMcn::Unregister()"); |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CMcn::GetCellInfo |
|
140 // Retrieves the current MCN message (Cell Info, topic 050) from CBS |
|
141 // server. |
|
142 // (other items were commented in a header). |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 EXPORT_C TInt CMcn::GetCellInfo( |
|
146 TDes& aMcnMessage ) const |
|
147 { |
|
148 return iSession.GetCellInfo( aMcnMessage ); |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CMcn::RelayMessageL |
|
153 // Relays aMcnMessage and topic number to the registered observers. |
|
154 // (other items were commented in a header). |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CMcn::RelayMessage( |
|
158 TCbsMcnMessage& aMcnMessage ) |
|
159 { |
|
160 CBSLOGSTRING("CBSMCNCLIENT: >>> CMcn::RelayMessage()"); |
|
161 |
|
162 TInt count( iObservers->Count() ); |
|
163 |
|
164 CBSLOGSTRING2("CBSMCNCLIENT: CMcn::RelayMessage(): topicNumber: %d", aMcnMessage.iTopicNumber ); |
|
165 CBSLOGSTRING2("CBSMCNCLIENT: CMcn::RelayMessage(): Network mode: %d (0=GSM, 1=WCDMA, 2=Not defined)", aMcnMessage.iNetworkMode ); |
|
166 CBSLOGSTRING2("CBSMCNCLIENT: CMcn::RelayMessage(): Observer count: %d", count ); |
|
167 |
|
168 for ( TInt i = 0; i < count; ) |
|
169 { |
|
170 TInt prevCount = count; |
|
171 |
|
172 CBSLOGSTRING2("CBSMCNCLIENT: CMcn::RelayMessage(): Calling CellInfoChanged... Observer: %d", i); |
|
173 |
|
174 // Notify all registered observers |
|
175 iObservers->At( i )->CellInfoChanged( aMcnMessage ); |
|
176 CBSLOGSTRING("CBSMCNCLIENT: CMcn::RelayMessage(): CellInfoChanged call finished."); |
|
177 |
|
178 // Check if the client unregistered it's observer. If so, we don't |
|
179 // increase the loop counter. |
|
180 count = iObservers->Count(); |
|
181 if ( count == prevCount ) |
|
182 { |
|
183 i++; |
|
184 } |
|
185 } |
|
186 CBSLOGSTRING("CBSMCNCLIENT: <<< CMcn::RelayMessage()"); |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CMcn::GetInfoMessage |
|
191 // Retrieves the current info message from CBS server. |
|
192 // |
|
193 // (other items were commented in a header). |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C TInt CMcn::GetInfoMessage( |
|
197 TDes& aInfoMessage, |
|
198 TInt aTopicNumber ) const |
|
199 { |
|
200 return iSession.GetInfoMessage( aInfoMessage, aTopicNumber ); |
|
201 } |
|
202 |
|
203 // End of File |