|
1 // nitz.cpp |
|
2 // |
|
3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <fshell/ioutils.h> |
|
14 #include <etelmm.h> |
|
15 #include <commsdattypesv1_1.h> |
|
16 #include <cdblen.h> |
|
17 |
|
18 using namespace IoUtils; |
|
19 |
|
20 class CCmdNitz : public CCommandBase |
|
21 { |
|
22 public: |
|
23 static CCommandBase* NewLC(); |
|
24 ~CCmdNitz(); |
|
25 private: |
|
26 CCmdNitz(); |
|
27 void OpenPhoneL(); |
|
28 void PrintNitzData(); |
|
29 void QueueNotification(); |
|
30 private: // From CCommandBase. |
|
31 virtual const TDesC& Name() const; |
|
32 virtual void DoRunL(); |
|
33 virtual void OptionsL(RCommandOptionList& aOptions); |
|
34 private: // From CActive. |
|
35 virtual void RunL(); |
|
36 virtual void DoCancel(); |
|
37 private: |
|
38 RTelServer iEtelServer; |
|
39 RMobilePhone iPhone; |
|
40 RMobilePhone::TMobilePhoneNITZ iNitzData; |
|
41 TBool iFollow; |
|
42 HBufC* iTsyName; |
|
43 TBool iFirstPrint; |
|
44 }; |
|
45 |
|
46 |
|
47 CCommandBase* CCmdNitz::NewLC() |
|
48 { |
|
49 CCmdNitz* self = new(ELeave) CCmdNitz(); |
|
50 CleanupStack::PushL(self); |
|
51 self->BaseConstructL(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 CCmdNitz::~CCmdNitz() |
|
56 { |
|
57 delete iTsyName; |
|
58 iPhone.Close(); |
|
59 iEtelServer.Close(); |
|
60 } |
|
61 |
|
62 CCmdNitz::CCmdNitz() : iFirstPrint(ETrue) |
|
63 { |
|
64 } |
|
65 |
|
66 const TDesC& CCmdNitz::Name() const |
|
67 { |
|
68 _LIT(KName, "nitz"); |
|
69 return KName; |
|
70 } |
|
71 |
|
72 void CCmdNitz::DoRunL() |
|
73 { |
|
74 OpenPhoneL(); |
|
75 |
|
76 TInt err = iPhone.GetNITZInfo(iNitzData); |
|
77 if (err == KErrNone) |
|
78 { |
|
79 PrintNitzData(); |
|
80 } |
|
81 else if (!iFollow) |
|
82 { |
|
83 LeaveIfErr(err, _L("Unable to get NITZ information")); |
|
84 } |
|
85 |
|
86 if (iFollow) |
|
87 { |
|
88 QueueNotification(); |
|
89 } |
|
90 } |
|
91 |
|
92 void CCmdNitz::RunL() |
|
93 { |
|
94 if (iStatus.Int() == KErrNone) |
|
95 { |
|
96 PrintNitzData(); |
|
97 QueueNotification(); |
|
98 } |
|
99 else |
|
100 { |
|
101 Complete(iStatus.Int()); |
|
102 } |
|
103 } |
|
104 |
|
105 void CCmdNitz::DoCancel() |
|
106 { |
|
107 } |
|
108 |
|
109 void CCmdNitz::OpenPhoneL() |
|
110 { |
|
111 if (iTsyName == NULL) |
|
112 { |
|
113 CommsDat::CMDBSession* db = CommsDat::CMDBSession::NewLC(KCDLatestVersion); |
|
114 CommsDat::CMDBField<TUint32>* globalSettingField = new(ELeave) CommsDat::CMDBField<TUint32>(CommsDat::KCDTIdModemPhoneServicesSMS); |
|
115 CleanupStack::PushL(globalSettingField); |
|
116 globalSettingField->SetRecordId(1); |
|
117 globalSettingField->LoadL(*db); |
|
118 TUint32 modemId = *globalSettingField; |
|
119 CommsDat::CMDBField<TDesC>* tsyField = new(ELeave) CommsDat::CMDBField<TDesC>(CommsDat::KCDTIdTsyName); |
|
120 CleanupStack::PushL(tsyField); |
|
121 tsyField->SetRecordId(modemId); |
|
122 TRAPL(tsyField->LoadL(*db), _L("Unable to read default TSY name")); |
|
123 TBuf<KCommsDbSvrMaxFieldLength> tsyName; |
|
124 tsyName = *tsyField; |
|
125 iTsyName = tsyName.AllocL(); |
|
126 CleanupStack::PopAndDestroy(3, db); // db, tsyField & globalSettingField |
|
127 } |
|
128 |
|
129 LeaveIfErr(iEtelServer.Connect(), _L("Unable to connect to the ETel server")); |
|
130 LeaveIfErr(iEtelServer.LoadPhoneModule(*iTsyName), _L("Unable to load TSY module \"%S\""), iTsyName); |
|
131 TInt numPhones = 0; |
|
132 LeaveIfErr(iEtelServer.EnumeratePhones(numPhones), _L("Couldn't enumerate phones")); |
|
133 TBool matchFound(EFalse); |
|
134 TInt phoneIndex; |
|
135 for (phoneIndex = 0; phoneIndex < numPhones; ++phoneIndex) |
|
136 { |
|
137 TName thisTsyName; |
|
138 if ((iEtelServer.GetTsyName(phoneIndex, thisTsyName) == KErrNone) && (iTsyName->CompareF(thisTsyName) == KErrNone)) |
|
139 { |
|
140 matchFound = ETrue; |
|
141 break; |
|
142 } |
|
143 } |
|
144 if (!matchFound) |
|
145 { |
|
146 LeaveIfErr(KErrNotFound, _L("Couldn't find phone using TSY \"%S\""), iTsyName); |
|
147 } |
|
148 RTelServer::TPhoneInfo phoneInfo; |
|
149 LeaveIfErr(iEtelServer.GetPhoneInfo(phoneIndex, phoneInfo), _L("Couldn't get phone info")); |
|
150 LeaveIfErr(iPhone.Open(iEtelServer, phoneInfo.iName), _L("Couldn't open phone")); |
|
151 } |
|
152 |
|
153 void CCmdNitz::PrintNitzData() |
|
154 { |
|
155 if (iFirstPrint) |
|
156 { |
|
157 iFirstPrint = EFalse; |
|
158 } |
|
159 else |
|
160 { |
|
161 Write(_L("\r\n")); |
|
162 } |
|
163 |
|
164 if (iNitzData.iNitzFieldsUsed & RMobilePhone::KCapsTimeAvailable) |
|
165 { |
|
166 Printf(_L("Universal time: %02d/%02d/%04d %02d:%02d:%02d.%d\r\n"), iNitzData.Day(), iNitzData.Month() + 1, iNitzData.Year(), iNitzData.Hour(), iNitzData.Minute(), iNitzData.Second(), iNitzData.MicroSecond()); |
|
167 } |
|
168 if (iNitzData.iNitzFieldsUsed & RMobilePhone::KCapsTimezoneAvailable) |
|
169 { |
|
170 Printf(_L("Time zone: %d (+/- 15 minute offsets from GMT)\r\n"), iNitzData.iTimeZone); |
|
171 } |
|
172 if (iNitzData.iNitzFieldsUsed & RMobilePhone::KCapsDSTAvailable) |
|
173 { |
|
174 Printf(_L("Daylight saving adjustment: %d (hours)\r\n"), iNitzData.iDST); |
|
175 } |
|
176 if (iNitzData.iNitzFieldsUsed & RMobilePhone::KCapsShortNameAvailable) |
|
177 { |
|
178 Printf(_L("Short network name: \"%S\"\r\n"), &iNitzData.iShortNetworkId); |
|
179 } |
|
180 if (iNitzData.iNitzFieldsUsed & RMobilePhone::KCapsLongNameAvailable) |
|
181 { |
|
182 Printf(_L("Long network name: \"%S\"\r\n"), &iNitzData.iLongNetworkId); |
|
183 } |
|
184 } |
|
185 |
|
186 void CCmdNitz::QueueNotification() |
|
187 { |
|
188 iPhone.NotifyNITZInfoChange(iStatus, iNitzData); |
|
189 SetActive(); |
|
190 } |
|
191 |
|
192 void CCmdNitz::OptionsL(RCommandOptionList& aOptions) |
|
193 { |
|
194 _LIT(KOptFollow, "follow"); |
|
195 aOptions.AppendBoolL(iFollow, KOptFollow); |
|
196 |
|
197 _LIT(KOptTsyName, "tsy-name"); |
|
198 aOptions.AppendStringL(iTsyName, KOptTsyName); |
|
199 } |
|
200 |
|
201 |
|
202 EXE_BOILER_PLATE(CCmdNitz) |
|
203 |