My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
// Copyright (c) 2007-2009 Google Inc.
// Copyright (c) 2006-2007 Jaiku Ltd.
// Copyright (c) 2002-2006 Mika Raento and Renaud Petit
//
// This software is licensed at your choice under either 1 or 2 below.
//
// 1. MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// 2. Gnu General Public license 2.0
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//
// This file is part of the JaikuEngine mobile client.

// Concepts:
// !Getting the current cell-id!

#include "log_cellid.h"
#include "csd_cell.h"
#include "cellmap.h"


#include <e32base.h>
#include "stripped_etelbgsm.h"
#include "app_context.h"
#include "operatormap.h"

#ifdef __WINS__
#include "bases.h"
#endif

#ifndef __WINS__
# if defined(__S60V3__) || defined(__S60V2FP3__)
#define ETEL3RDPARTY
# else
# if defined(__S60V2__)
//#define MOBINFO
#define BASICGSM
# else
#define BASICGSM
# endif
# endif //S60V3
#endif //WINS

#ifdef ETEL3RDPARTY
#include <etel3rdparty.h>
#endif
#ifdef MOBINFO
#include <mobileinfo.h>
#endif

#include "timeout.h"

class Clog_cellidImpl: public Clog_cellid, public MTimeOut
{
public:
virtual const CBBSensorEvent& get_value();
private:
virtual void DoCancel();
virtual void CheckedRunL();
virtual TInt CheckedRunError(TInt aError);
virtual void expired(CBase*);
void ResetMissing();
private:
Clog_cellidImpl(MApp_context& Context, COperatorMap* aOpMap, CCellMap* aCellMap);
void ConstructL();
~Clog_cellidImpl();

#ifndef __WINS__

#ifdef BASICGSM
MBasicGsmPhoneNetwork::TCurrentNetworkInfo async_info;
MBasicGsmPhoneNetwork::TCurrentNetworkInfo prev_info;
#endif

#ifdef ETEL3RDPARTY
CTelephony::TNetworkInfoV1Pckg async_infop;
CTelephony::TNetworkInfoV1 async_info;
CTelephony::TNetworkInfoV1 prev_info;
enum T3rdpartyState { IDLE, GETTING_INFO, NOTIFYONCHANGE };
T3rdpartyState i3rdpartyState;
#endif

#ifdef MOBINFO
CMobileNetworkInfo* iMobInfo;
TMobileCellIdBuf async_infop;
TMobileCellId prev_info;
enum TInfoState { IDLE, GETTING_FIRST_MCC,
GETTING_FIRST_CELL, GETTING_CELL, GETTING_NEW_MCC };
TInfoState iInfoState;
TMobileNetwork iNetworkInfo;
#endif

#endif //!WINS
TInt iErrorCount;
#ifdef __WINS__
int test_data_i;
RTimer timer;
COperatorMap* iOpMap;
#endif
class CCellMap* iCellMap;
TBBCellId iCell;
CTimeOut* iTimeOut;
TBool iPostedMissing;
friend class Clog_cellid;
};

#define MISSING_TIMEOUT 90

Clog_cellid::Clog_cellid(MApp_context& Context) :
CCheckedActive(EPriorityIdle, _L("Clog_cellid")),
Mlog_base_impl(Context, KCell, KCellIdTuple, 5*24*60*60) { }

Clog_cellidImpl::Clog_cellidImpl(MApp_context& Context, COperatorMap* aOpMap, CCellMap* aCellMap) :
Clog_cellid(Context),
#if defined(ETEL3RDPARTY)
async_infop(async_info),
#endif
iCell(KCell), iCellMap(aCellMap) {
#ifdef __WINS__
iOpMap=aOpMap;
test_data_i=0;
#endif
}

EXPORT_C Clog_cellid* Clog_cellid::NewL(MApp_context& Context,
COperatorMap* aOpMap,
class CCellMap* aCellMap)
{
CALLSTACKITEM2_N(_CL("Clog_cellid"), _CL("NewL"), &Context);
auto_ptr<Clog_cellidImpl> ret(new (ELeave) Clog_cellidImpl(Context, aOpMap, aCellMap));
ret->ConstructL();
return ret.release();
}

void Clog_cellidImpl::ConstructL()
{
CALLSTACKITEM_N(_CL("Clog_cellidImpl"), _CL("ConstructL"));

Mlog_base_impl::ConstructL();

CActiveScheduler::Add(this); // add to scheduler
iTimeOut=CTimeOut::NewL(*this);
#ifndef __WINS__

#ifdef BASICGSM
TInt err=Phone().GetCurrentNetworkInfo(async_info);
TRequestStatus *s=&iStatus;
User::RequestComplete(s, err);
#endif

#ifdef ETEL3RDPARTY
Telephony().GetCurrentNetworkInfo(iStatus, async_infop);
i3rdpartyState=GETTING_INFO;
#endif

#ifdef MOBINFO
iMobInfo=CMobileNetworkInfo::NewL();
iInfoState=GETTING_FIRST_MCC;
iMobInfo->GetCurrentNetwork(iNetworkInfo, iStatus);
//iMobInfo->GetCellId(async_infop, iStatus);
#endif

SetActive();

#else
iOpMap->AddRef();
timer.CreateLocal();
//TTimeIntervalMicroSeconds32 w(5*1000*1000);
TTimeIntervalMicroSeconds32 w(1*1000*1000);
timer.After(iStatus, w);
SetActive();
#endif

#ifdef BASICGSM
//post_new_value(get_value());
#endif
}

Clog_cellidImpl::~Clog_cellidImpl()
{
CALLSTACKITEM_N(_CL("Clog_cellidImpl"), _CL("~Clog_cellidImpl"));
Cancel();

#ifdef MOBINFO
delete iMobInfo;
#endif

delete iTimeOut;
#ifdef __WINS__
if (iOpMap) iOpMap->Release();
timer.Close();
#endif
}

void Clog_cellidImpl::expired(CBase*)
{
iPostedMissing=ETrue;
post_new_value(&iCell);
}

void Clog_cellidImpl::ResetMissing()
{
iTimeOut->Reset();
iPostedMissing=EFalse;
}

void Clog_cellidImpl::DoCancel()
{
CALLSTACKITEM_N(_CL("Clog_cellidImpl"), _CL("DoCancel"));

#ifndef __WINS__

# ifdef BASICGSM
# ifndef __S60V2__
Phone().NotifyChangeOfCurrentNetworkCancel();
# else
// The Cancel hangs on v2 :-(
//Phone().NotifyChangeOfCurrentNetworkCancelNS();
TRequestStatus* s=&iStatus;
User::RequestComplete(s, KErrCancel);
# endif
# endif

#ifdef ETEL3RDPARTY
if (i3rdpartyState==NOTIFYONCHANGE)
Telephony().CancelAsync(CTelephony::ECurrentNetworkInfoChangeCancel);
else
Telephony().CancelAsync(CTelephony::EGetCurrentNetworkInfoCancel);
#endif

#ifdef MOBINFO
switch(iInfoState) {
case GETTING_CELL:
iMobInfo->CancelCellIdChangeNotification();
break;
case GETTING_FIRST_CELL:
iMobInfo->CancelGetCellId();
break;
case GETTING_FIRST_MCC:
case GETTING_NEW_MCC:
iMobInfo->CancelGetCurrentNetwork();
break;
};
#endif
#else
timer.Cancel();
#endif
}

TInt Clog_cellidImpl::CheckedRunError(TInt aError)
{
CALLSTACKITEM_N(_CL("Clog_cellidImpl"), _CL("CheckedRunError"));
if (iErrorCount >= 10) return aError;

TBuf<40> msg;
msg.Format(_L("Clog_cellidImpl::CheckedRunError %d"), aError);

post_error(msg, aError, GetTime());

#ifndef __WINS__
Cancel();

# ifdef BASICGSM
# ifndef __S60V2__
Phone().NotifyChangeOfCurrentNetwork(iStatus, async_info);
# else
Phone().NotifyChangeOfCurrentNetworkNS(iStatus, async_info);
# endif
# endif

# ifdef ETEL3RDPARTY
Telephony().NotifyChange(iStatus, CTelephony::ECurrentNetworkInfoChange, async_infop);
i3rdpartyState=NOTIFYONCHANGE;
# endif

# ifdef MOBINFO

if (iInfoState==GETTING_FIRST_MCC || iInfoState==GETTING_NEW_MCC) {
iMobInfo->GetCurrentNetwork(iNetworkInfo, iStatus);
} else {
iMobInfo->NotifyCellIdChange(async_infop, iStatus);
}
# endif

SetActive();
return KErrNone;
#else // __WINS__
return aError;
#endif
}

void Clog_cellidImpl::CheckedRunL()
{
CALLSTACKITEM_N(_CL("Clog_cellidImpl"), _CL("CheckedRunL"));

#ifdef __WINS__
TTimeIntervalMicroSeconds32 wait_time;
#endif
if (iStatus!=KErrNone) {
TBuf<40> msg;
msg.Format(_L("NotifyChangeOfCurrentNetwork %d"), iStatus.Int());
post_error(msg, iStatus.Int(), GetTime());
if (iErrorCount++ >= 10) {
User::Leave(-1005);
}
} else {
iErrorCount=0;
#ifndef __WINS__
# ifdef BASICGSM
if (async_info.iNetworkInfo.iShortName.CompareF(_L("elisa"))==0) {
async_info.iNetworkInfo.iShortName=_L("RADIOLINJA");
}
iCell.iMCC()=async_info.iNetworkInfo.iId.iMCC;
iCell.iMNC()=async_info.iNetworkInfo.iId.iMNC;
iCell.iShortName=async_info.iNetworkInfo.iShortName;
iCell.iLocationAreaCode()=async_info.iLocationAreaCode;
iCell.iCellId()=async_info.iCellId;
iCell.iMappedId()=iCellMap->GetId(iCell);
# endif
# ifdef ETEL3RDPARTY
iCell.iMCC.FromStringL(async_info.iCountryCode);
iCell.iMNC.FromStringL(async_info.iNetworkId);
iCell.iShortName=async_info.iShortName;
iCell.iLocationAreaCode()=async_info.iLocationAreaCode;
iCell.iCellId()=async_info.iCellId;
iCell.iMappedId()=iCellMap->GetId(iCell);
# endif
# ifdef MOBINFO
//TBuf<100> msg=_L("cell mcc ");

if (iInfoState==GETTING_FIRST_MCC || iInfoState==GETTING_NEW_MCC) {
iCell.iMCC.FromStringL(iNetworkInfo.iNetworkCountryCode);
}
if (iInfoState==GETTING_FIRST_MCC) {
//post_error(msg, KErrGeneral);
iInfoState=GETTING_FIRST_CELL;
iMobInfo->GetCellId(async_infop, iStatus);
SetActive();
return;
}
/*
msg.Append(iNetworkInfo.iNetworkCountryCode);
if (iInfoState==GETTING_CELL) {
msg.Append(async_infop().iCountryCode);
msg.Append(_L(" mnc "));
msg.Append(async_infop().iNetworkIdentity);
msg.Append(_L(" lac "));
msg.AppendNum(async_infop().iLocationAreaCode);
msg.Append(_L(" cellid "));
msg.AppendNum(async_infop().iCellId);
}
post_error(msg, KErrGeneral);
return;
*/

iCell.iMNC.FromStringL(async_infop().iNetworkIdentity);
iCell.iShortName()=iNetworkInfo.iNetworkShortName;
iCell.iLocationAreaCode()=async_infop().iLocationAreaCode;
iCell.iCellId()=async_infop().iCellId;
iCell.iMappedId()=iCellMap->GetId(iCell);

if ( (iInfoState==GETTING_CELL) &&
(iCell.iMNC() != prev_info.iLocationAreaCode)) {
iInfoState=GETTING_NEW_MCC;
iMobInfo->GetCellId(async_infop, iStatus);
SetActive();
return;
}
async_infop().iCountryCode=iNetworkInfo.iNetworkCountryCode;
iInfoState=GETTING_CELL;
# endif

if ( iCell.iLocationAreaCode()==0 && iCell.iCellId()==0) {
if (!iPostedMissing ) {
iTimeOut->WaitMax(MISSING_TIMEOUT);
}
} else {
ResetMissing();
post_new_value(&iCell);
}

# ifndef MOBINFO
prev_info=async_info;
# else
prev_info=async_infop();
# endif
}
#ifdef BASICGSM
# ifndef __S60V2__
Phone().NotifyChangeOfCurrentNetwork(iStatus, async_info);
# else
Phone().NotifyChangeOfCurrentNetworkNS(iStatus, async_info);
# endif
#endif //BASICGSM

#ifdef ETEL3RDPARTY
Telephony().NotifyChange(iStatus, CTelephony::ECurrentNetworkInfoChange, async_infop);
i3rdpartyState=NOTIFYONCHANGE;
#endif

#ifdef MOBINFO
post_error(_L("NotifyCellIdChange"), KErrGeneral);
iMobInfo->NotifyCellIdChange(async_infop, iStatus);
#endif
SetActive();
#else //WINS
TTime this_time;
TBuf<40> val=bases::test_data[test_data_i][1];
while (! val.Compare(_L("SWITCH"))) {
val=bases::test_data[++test_data_i][1];
}
TPtrC dtd(bases::test_data[test_data_i][0]);
_LIT(KTime, "t");
TBBTime t(KTime);
t.FromStringL(dtd);
CCellMap::Parse(val, iCell.iCellId(), iCell.iLocationAreaCode(), iCell.iShortName());
iOpMap->NameToMccMnc(iCell.iShortName(), iCell.iMCC(), iCell.iMNC());
++test_data_i;
if (test_data_i == 322) {
TInt x=0;
}
iCell.iMappedId()=iCellMap->GetId(iCell);
post_new_value(&iCell, t());
this_time=t();
TTime next_time;
{
val=bases::test_data[test_data_i][1];
while (! val.Compare(_L("SWITCH"))) {
val=bases::test_data[++test_data_i][1];
}
TPtrC dtd(bases::test_data[test_data_i][0]);
t.FromStringL(dtd);
next_time=t();
}
TTimeIntervalMicroSeconds w=next_time.MicroSecondsFrom(this_time);
TInt64 ms=w.Int64();
//ms/=(60*5);
wait_time=I64LOW(ms);
}
//TTimeIntervalMicroSeconds32 w(120*1000*1000);
//TTimeIntervalMicroSeconds32 w(100*1000);
timer.After(iStatus, wait_time);
SetActive();
//iErrorCount=10; User::Leave(1);
//User::Panic(_L("test panic"), 10);
//RThread me;
//me.Open(me.Id());
//me.RaiseException(EExcAccessViolation);
#endif

}

const CBBSensorEvent& Clog_cellidImpl::get_value()
{
CALLSTACKITEM_N(_CL("Clog_cellidImpl"), _CL("get_value"));

#ifndef __WINS__

# ifdef BASICGSM
MBasicGsmPhoneNetwork::TCurrentNetworkInfo ni;
ni.iLocationAreaCode=ni.iCellId=0;
// get network info

User::LeaveIfError( Phone().GetCurrentNetworkInfo( ni ) );
if (ni.iNetworkInfo.iShortName.CompareF(_L("elisa"))==0) {
ni.iNetworkInfo.iShortName=_L("RADIOLINJA");
}
prev_info=ni;

iCell.iMCC()=ni.iNetworkInfo.iId.iMCC;
iCell.iMNC()=ni.iNetworkInfo.iId.iMNC;
iCell.iShortName=ni.iNetworkInfo.iShortName;
iCell.iLocationAreaCode()=ni.iLocationAreaCode;
iCell.iCellId()=ni.iCellId;

iCell.iMappedId()=iCellMap->GetId(iCell);
iEvent.iData.SetOwnsValue(EFalse);
iEvent.iData.SetValue(&iCell);
iEvent.iStamp()=GetTime();
# endif

#endif
return iEvent;
}

Change log

r18 by mika.raento on Sep 22, 2009   Diff
added Symbian programming concepts
Go to: 
Project members, sign in to write a code review

Older revisions

r2 by mika.raento on Mar 11, 2009   Diff
initial import
All revisions of this file

File info

Size: 13455 bytes, 516 lines
Powered by Google Project Hosting