96 // |
109 // |
97 // |
110 // |
98 |
111 |
99 EXPORT_C void CWatcherBase::SuspendFor(TInt aTimeInSeconds) |
112 EXPORT_C void CWatcherBase::SuspendFor(TInt aTimeInSeconds) |
100 { |
113 { |
101 LOGCOMMON1("WatcherBase : Pausing after error"); |
114 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_SUSPENDFOR_1, "WatcherBase : Pausing after error"); |
102 TTimeIntervalMicroSeconds32 timeToSuspendFor = aTimeInSeconds * KOneSecond; |
115 TTimeIntervalMicroSeconds32 timeToSuspendFor = aTimeInSeconds * KOneSecond; |
103 iTimer.After(iStatus, timeToSuspendFor); |
116 iTimer.After(iStatus, timeToSuspendFor); |
104 State() = EBaseStateSuspending; |
117 State() = EBaseStateSuspending; |
105 SetActive(); |
118 SetActive(); |
106 } |
119 } |
107 |
120 |
108 EXPORT_C void CWatcherBase::SetDisabled(const TDesC& aLogEntry, TInt aError) |
121 EXPORT_C void CWatcherBase::SetDisabled(const TDesC& TCOM_ARG(aLogEntry), TInt TCOM_ARG(aError)) |
109 { |
122 { |
110 #ifdef _WATCHER_LOGGING_ENABLED |
123 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_SETDISABLED_1, "Log Entry \"%S\" error %d", aLogEntry, aError); |
111 TBuf8<256> tmpBuf; |
124 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_SETDISABLED_2, "WatcherBase : Watcher is now disabled"); |
112 tmpBuf.Copy(aLogEntry); |
|
113 LOGCOMMON3("Log Entry \"%S\" error %d", &tmpBuf, aError); |
|
114 #else |
|
115 (void) aLogEntry; |
|
116 (void) aError; |
|
117 #endif |
|
118 LOGCOMMON1("WatcherBase : Watcher is now disabled"); |
|
119 State() = EBaseStateDisabled; |
125 State() = EBaseStateDisabled; |
120 } |
126 } |
121 |
127 |
122 EXPORT_C void CWatcherBase::RequestNextState() |
128 EXPORT_C void CWatcherBase::RequestNextState() |
123 { |
129 { |
124 LOGCOMMON1("WatcherBase : Requesting State Change"); |
130 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_REQUESTNEXTSTATE_1, "WatcherBase : Requesting State Change"); |
125 |
131 |
126 if (State() != EBaseStateDisabled) |
132 if (State() != EBaseStateDisabled) |
127 { |
133 { |
128 TRequestStatus* status = &iStatus; |
134 TRequestStatus* status = &iStatus; |
129 User::RequestComplete(status, KErrNone); |
135 User::RequestComplete(status, KErrNone); |
155 User::LeaveIfError(iPhonePowerProperty.Get(val)); |
161 User::LeaveIfError(iPhonePowerProperty.Get(val)); |
156 |
162 |
157 if (val != ESAPhoneOff) |
163 if (val != ESAPhoneOff) |
158 {//-- phone is already ON, complete request so that we go to RunL without waiting |
164 {//-- phone is already ON, complete request so that we go to RunL without waiting |
159 iPhonePowerProperty.Cancel(); |
165 iPhonePowerProperty.Cancel(); |
160 LOGCOMMON1("CTelWatcherBase::WaitForPhoneToPowerUpL ??? phone is already turned ON"); |
166 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_WAITFORPHONETOPOWERUPL_2, "CTelWatcherBase::WaitForPhoneToPowerUpL ??? phone is already turned ON"); |
161 } |
167 } |
162 } |
168 } |
163 |
169 |
164 // |
170 // |
165 // |
171 // |
166 // |
172 // |
167 |
173 |
168 EXPORT_C void CWatcherBase::RunL() |
174 EXPORT_C void CWatcherBase::RunL() |
169 { |
175 { |
170 LOGCOMMON2("WatcherBase : RunL(%d)", iStatus.Int()); |
176 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_RUNL_1, "WatcherBase : RunL(%d)", iStatus.Int()); |
171 |
177 |
172 switch(State()) |
178 switch(State()) |
173 { |
179 { |
174 case EBaseStateConnectingToPropertyNotifier: |
180 case EBaseStateConnectingToPropertyNotifier: |
175 LOGCOMMON1("WatcherBase : Attaching to Property"); |
181 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_RUNL_2, "WatcherBase : Attaching to Property"); |
176 |
182 |
177 // Virtual function call back, for any subclasses that need to implement |
183 // Virtual function call back, for any subclasses that need to implement |
178 // any special stuff. |
184 // any special stuff. |
179 HandleConnectionToChangeNotifierEstablishedL(); |
185 HandleConnectionToChangeNotifierEstablishedL(); |
180 |
186 |
184 break; |
190 break; |
185 |
191 |
186 case EBaseStateWaitingForPhoneToPowerUp: |
192 case EBaseStateWaitingForPhoneToPowerUp: |
187 // We were waiting for the phone to become available again. We now must restart |
193 // We were waiting for the phone to become available again. We now must restart |
188 // this watcher from scratch. |
194 // this watcher from scratch. |
189 LOGCOMMON1("WatcherBase : Phone available again. Restarting watcher framework"); |
195 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_RUNL_3, "WatcherBase : Phone available again. Restarting watcher framework"); |
190 |
196 |
191 //-- phone power state has changed (it must be turned ON) |
197 //-- phone power state has changed (it must be turned ON) |
192 //-- retrieve its state and check. |
198 //-- retrieve its state and check. |
193 TInt val; |
199 TInt val; |
194 |
200 |
195 User::LeaveIfError(iPhonePowerProperty.Get(val)); |
201 User::LeaveIfError(iPhonePowerProperty.Get(val)); |
196 |
202 |
197 if (val == ESAPhoneOn) |
203 if (val == ESAPhoneOn) |
198 { //-- everything OK, the phone has been turned ON, restart this watcher from scratch. |
204 { //-- everything OK, the phone has been turned ON, restart this watcher from scratch. |
199 LOGCOMMON1("CTelWatcherBase : Phone has been turned ON. Restarting watcher framework"); |
205 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_RUNL_4, "CTelWatcherBase : Phone has been turned ON. Restarting watcher framework"); |
200 State() = EBaseStateConnectingToPropertyNotifier; |
206 State() = EBaseStateConnectingToPropertyNotifier; |
201 RequestNextState(); |
207 RequestNextState(); |
202 } |
208 } |
203 else |
209 else |
204 { //-- strange situation, we were waiting for phone On and it now Off, try to wait again |
210 { //-- strange situation, we were waiting for phone On and it now Off, try to wait again |
205 LOGCOMMON1("CTelWatcherBase : ??? Phone has been turned OFF. Continue waiting..."); |
211 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_RUNL_5, "CTelWatcherBase : ??? Phone has been turned OFF. Continue waiting..."); |
206 WaitForPhoneToPowerUpL(); |
212 WaitForPhoneToPowerUpL(); |
207 } |
213 } |
208 break; |
214 break; |
209 |
215 |
210 case EBaseStateSuspending: |
216 case EBaseStateSuspending: |
211 LOGCOMMON1("WatcherBase : Completed suspension. Resuming passive state"); |
217 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_RUNL_6, "WatcherBase : Completed suspension. Resuming passive state"); |
212 |
218 |
213 State() = EBaseStatePassive; // Fall through |
219 State() = EBaseStatePassive; // Fall through |
214 |
220 |
215 case EBaseStatePassive: // In passive mode, so just call framework function |
221 case EBaseStatePassive: // In passive mode, so just call framework function |
216 HandleStateEventL(iStatus.Int()); |
222 HandleStateEventL(iStatus.Int()); |
217 break; |
223 break; |
218 |
224 |
219 default: |
225 default: |
220 case EBaseStateDisabled: |
226 case EBaseStateDisabled: |
221 LOGCOMMON1("WatcherBase : RunL called in Disabled state. Ooops"); |
227 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CWATCHERBASE_RUNL_7, "WatcherBase : RunL called in Disabled state. Ooops"); |
222 __ASSERT_DEBUG(0, WatcherBasePanic(EUnexpectedState)); |
228 __ASSERT_DEBUG(0, WatcherBasePanic(EUnexpectedState)); |
223 } |
229 } |
224 } |
230 } |
225 |
231 |
226 EXPORT_C void CWatcherBase::DoCancel() |
232 EXPORT_C void CWatcherBase::DoCancel() |
405 // |
407 // |
406 // |
408 // |
407 |
409 |
408 TInt CPhoneWatcher::RetrieveTSYName() |
410 TInt CPhoneWatcher::RetrieveTSYName() |
409 { |
411 { |
410 LOGCOMMON1("PhoneWatcher : RetrieveTSYName()"); |
412 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_RETRIEVETSYNAME_1, "PhoneWatcher : RetrieveTSYName()"); |
411 TRAPD(error, DoRetrieveTSYNameL()); |
413 TRAPD(error, DoRetrieveTSYNameL()); |
412 return error; |
414 return error; |
413 } |
415 } |
414 |
416 |
415 TInt CPhoneWatcher::ConnectToETelServer() |
417 TInt CPhoneWatcher::ConnectToETelServer() |
416 { |
418 { |
417 LOGCOMMON1("PhoneWatcher : ConnectToETelServer()"); |
419 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_CONNECTTOETELSERVER_1, "PhoneWatcher : ConnectToETelServer()"); |
418 return ETel().Connect(); |
420 return ETel().Connect(); |
419 } |
421 } |
420 |
422 |
421 TInt CPhoneWatcher::LoadPhoneModule() |
423 TInt CPhoneWatcher::LoadPhoneModule() |
422 { |
424 { |
423 #ifdef _WATCHER_LOGGING_ENABLED |
425 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_LOADPHONEMODULE_1, "PhoneWatcher : LoadPhoneModule()"); |
424 TBuf8<256> tmpBuf; |
426 OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_LOADPHONEMODULE_2, "TSY Name to load is %S",iTSYName); |
425 tmpBuf.Copy(iTSYName); |
|
426 LOGCOMMON1("PhoneWatcher : LoadPhoneModule()"); |
|
427 LOGCOMMON2("TSY Name to load is %S",&tmpBuf); |
|
428 #endif |
|
429 |
427 |
430 return ETel().LoadPhoneModule(iTSYName); |
428 return ETel().LoadPhoneModule(iTSYName); |
431 } |
429 } |
432 |
430 |
433 TInt CPhoneWatcher::ConnectToPhone() |
431 TInt CPhoneWatcher::ConnectToPhone() |
434 { |
432 { |
435 LOGCOMMON1("PhoneWatcher : ConnectToPhone()"); |
433 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_CONNECTTOPHONE_1, "PhoneWatcher : ConnectToPhone()"); |
436 TInt error; |
434 TInt error; |
437 |
435 |
438 RTelServer::TPhoneInfo phoneInfo; |
436 RTelServer::TPhoneInfo phoneInfo; |
439 |
437 |
440 // Get the number of phones |
438 // Get the number of phones |
441 TInt phoneCount = 0; |
439 TInt phoneCount = 0; |
442 error = ETel().EnumeratePhones(phoneCount); |
440 error = ETel().EnumeratePhones(phoneCount); |
443 if (error < KErrNone) |
441 if (error < KErrNone) |
444 { |
442 { |
445 LOGCOMMON2("PhoneWatcher : Failed to enumerate phones (%d)", error); |
443 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_CONNECTTOPHONE_2, "PhoneWatcher : Failed to enumerate phones (%d)", error); |
446 return error; |
444 return error; |
447 } |
445 } |
448 |
446 |
449 LOGCOMMON2("PhoneWatcher : Counted %d 'phones'", phoneCount); |
447 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_CONNECTTOPHONE_3, "PhoneWatcher : Counted %d 'phones'", phoneCount); |
450 |
448 |
451 // Iterate through all the phones |
449 // Iterate through all the phones |
452 for(TInt i=0; i<phoneCount; i++) |
450 for(TInt i=0; i<phoneCount; i++) |
453 { |
451 { |
454 // Get the TSY name for the phone |
452 // Get the TSY name for the phone |
455 TName matchTsyName; |
453 TName matchTsyName; |
456 |
454 |
457 error = ETel().GetTsyName(i, matchTsyName); |
455 error = ETel().GetTsyName(i, matchTsyName); |
458 if (error < KErrNone) |
456 if (error < KErrNone) |
459 { |
457 { |
460 LOGCOMMON2("PhoneWatcher : Getting TSY name failed (%d)", error); |
458 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_CONNECTTOPHONE_4, "PhoneWatcher : Getting TSY name failed (%d)", error); |
461 return error; |
459 return error; |
462 } |
460 } |
463 |
461 |
464 #ifdef _WATCHER_LOGGING_ENABLED |
462 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_CONNECTTOPHONE_5, "PhoneWatcher : TSY for phone %d is '%S'", i, matchTsyName); |
465 TBuf8<256> tmpMatchTsyName; |
463 |
466 tmpMatchTsyName.Copy(matchTsyName); |
|
467 LOGCOMMON3("PhoneWatcher : TSY for phone %d is '%S'", i, &tmpMatchTsyName); |
|
468 #endif |
|
469 |
464 |
470 // See if the phone belongs to the TSY |
465 // See if the phone belongs to the TSY |
471 if (matchTsyName.CompareF(iTSYName) == 0) |
466 if (matchTsyName.CompareF(iTSYName) == 0) |
472 { |
467 { |
473 #ifdef _WATCHER_LOGGING_ENABLED |
468 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_CONNECTTOPHONE_6, "PhoneWatcher : %S is a match for CommDb TSY: %S", matchTsyName, iTSYName); |
474 TBuf8<256> tsyNameBuf; |
|
475 tsyNameBuf.Copy(iTSYName); |
|
476 LOGCOMMON3("PhoneWatcher : %S is a match for CommDb TSY: %S", &tmpMatchTsyName, &tsyNameBuf); |
|
477 #endif |
|
478 |
469 |
479 error = ETel().GetPhoneInfo(i, phoneInfo); |
470 error = ETel().GetPhoneInfo(i, phoneInfo); |
480 if (error < KErrNone) |
471 if (error < KErrNone) |
481 { |
472 { |
482 LOGCOMMON2("PhoneWatcher : Getting phone info failed (%d)", error); |
473 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_CONNECTTOPHONE_7, "PhoneWatcher : Getting phone info failed (%d)", error); |
483 return error; |
474 return error; |
484 } |
475 } |
485 break; |
476 break; |
486 } |
477 } |
487 } |
478 } |
488 |
479 |
489 // Connect to the specified phone |
480 // Connect to the specified phone |
490 error = Phone().Open(ETel(), phoneInfo.iName); |
481 error = Phone().Open(ETel(), phoneInfo.iName); |
491 if (error < KErrNone) |
482 if (error < KErrNone) |
492 { |
483 { |
493 #ifdef _WATCHER_LOGGING_ENABLED |
484 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_CONNECTTOPHONE_8, "PhoneWatcher : Open phone %S failed (%d)", phoneInfo.iName, error); |
494 TBuf8<256> tmpBuf; |
|
495 tmpBuf.Copy(phoneInfo.iName); |
|
496 LOGCOMMON3("PhoneWatcher : Open phone %S failed (%d)", &tmpBuf, error); |
|
497 #endif |
|
498 return error; |
485 return error; |
499 } |
486 } |
500 |
487 OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPHONEWATCHER_CONNECTTOPHONE_9, "PhoneWatcher : Opened 'phone' %S", phoneInfo.iName); |
501 #ifdef _WATCHER_LOGGING_ENABLED |
488 |
502 TBuf8<256> tmpBuf; |
|
503 tmpBuf.Copy(phoneInfo.iName); |
|
504 LOGCOMMON2("PhoneWatcher : Opened 'phone' %S", &tmpBuf); |
|
505 #endif |
|
506 |
489 |
507 // Indicate we're connected and to move to next state. |
490 // Indicate we're connected and to move to next state. |
508 return error; |
491 return error; |
509 } |
492 } |
510 |
493 |