|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file SIGSTRGTH.CPP |
|
18 */ |
|
19 |
|
20 #include "sigstrgth.h" |
|
21 |
|
22 CAgentSignalStrengthWatcher* CAgentSignalStrengthWatcher::NewL(RMobilePhone& aPhone) |
|
23 /** |
|
24 Allocates memory to class CAgentSignalStrengthWatcher |
|
25 |
|
26 @param aPhone,encapsulates access to a mobile phone. |
|
27 @return a pointer to class CAgentSignalStrengthWatcher. |
|
28 @exception if memory allocation fails. |
|
29 */ |
|
30 { |
|
31 CAgentSignalStrengthWatcher* self = new(ELeave)CAgentSignalStrengthWatcher(aPhone); |
|
32 CleanupStack::PushL(self); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop(self); |
|
35 return self; |
|
36 } |
|
37 |
|
38 CAgentSignalStrengthWatcher::~CAgentSignalStrengthWatcher() |
|
39 /** |
|
40 Destructor |
|
41 */ |
|
42 { |
|
43 Cancel(); |
|
44 } |
|
45 |
|
46 TInt CAgentSignalStrengthWatcher::CurrentSignalStrength(TInt32& aSigStrength) |
|
47 /** |
|
48 Retrieve signal strength of the current Agent. |
|
49 |
|
50 @param aSigStrength, denotes the signal strength. |
|
51 @return KErrUnknown if the signal strength has not yet been retrieved else KErrNone |
|
52 */ |
|
53 { |
|
54 if(iState == EInitialising) |
|
55 { |
|
56 // The signal strength has not yet been retrieved |
|
57 return KErrUnknown; |
|
58 } |
|
59 aSigStrength=iSigStrengthInDBm; |
|
60 return KErrNone; |
|
61 } |
|
62 |
|
63 CAgentSignalStrengthWatcher::CAgentSignalStrengthWatcher(RMobilePhone& aPhone) |
|
64 : CActive(EPriorityStandard), iPhone(aPhone), iState(EInitialising) |
|
65 { |
|
66 CActiveScheduler::Add(this); |
|
67 } |
|
68 |
|
69 void CAgentSignalStrengthWatcher::ConstructL() |
|
70 { |
|
71 // Start watching for signal strength |
|
72 iPhone.GetSignalStrength(iStatus,iSigStrengthInDBm,iSigStrengthInBars); |
|
73 SetActive(); |
|
74 } |
|
75 |
|
76 void CAgentSignalStrengthWatcher::RunL() |
|
77 { |
|
78 if(iStatus == KErrNone) |
|
79 { |
|
80 if(iSigStrengthInDBm != 0) |
|
81 { |
|
82 // The sig strength will be zero if not supported by the TSY |
|
83 if(iState == EInitialising) |
|
84 { |
|
85 iState = EUpdating; |
|
86 } |
|
87 // Renew request |
|
88 iPhone.NotifySignalStrengthChange(iStatus,iSigStrengthInDBm,iSigStrengthInBars); |
|
89 SetActive(); |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 void CAgentSignalStrengthWatcher::DoCancel() |
|
95 { |
|
96 if(iState == EInitialising) |
|
97 { |
|
98 iPhone.CancelAsyncRequest(EMobilePhoneGetSignalStrength); |
|
99 } |
|
100 else |
|
101 { |
|
102 // Must be EUpdating |
|
103 iPhone.CancelAsyncRequest(EMobilePhoneNotifySignalStrengthChange); |
|
104 } |
|
105 } |
|
106 |