cbsref/telephonyrefplugins/atltsy/atcommand/phone/src/notifybatteryandsignal.cpp
branchRCL_3
changeset 65 630d2f34d719
equal deleted inserted replaced
61:17af172ffa5f 65:630d2f34d719
       
     1 // Copyright (c) 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 // CATGetModemStatus
       
    15 // Description:
       
    16 // CNotifyBatteryAndSignal
       
    17 
       
    18 #include "notifybatteryandsignal.h"
       
    19 #include "mslogger.h"
       
    20 #include "atgetbatteryinfo.h"
       
    21 #include "atgetsignalstrength.h"
       
    22 
       
    23 const TInt KLtsyOneSecond = 1000000;
       
    24 
       
    25 // Class CNotifyBatteryAndSignal
       
    26 // ---------------------------------------------------------------------------
       
    27 // CNotifyBatteryAndSignal::NewL
       
    28 // other items were commented in a header
       
    29 // ---------------------------------------------------------------------------
       
    30 CNotifyBatteryAndSignal* CNotifyBatteryAndSignal::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    31 	                                                   CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    32 	{
       
    33 	CNotifyBatteryAndSignal* self = new(ELeave) CNotifyBatteryAndSignal(aGloblePhone,
       
    34 			                                                            aCtsyDispatcherCallback);
       
    35 	CleanupStack::PushL(self );
       
    36 	self->ConstructL();
       
    37 	CleanupStack::Pop();
       
    38 	return self ;
       
    39 	}
       
    40 // ---------------------------------------------------------------------------
       
    41 // CNotifyBatteryAndSignal::CNotifyBatteryAndSignal
       
    42 // other items were commented in a header
       
    43 // ---------------------------------------------------------------------------
       
    44 CNotifyBatteryAndSignal::CNotifyBatteryAndSignal(CGlobalPhonemanager& aGloblePhone, 
       
    45 	                                             CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    46 		:CATCommandControlBase(aGloblePhone,aCtsyDispatcherCallback)
       
    47 	{
       
    48 	}
       
    49 // ---------------------------------------------------------------------------
       
    50 // CNotifyBatteryAndSignal::ConstructL
       
    51 // other items were commented in a header
       
    52 // ---------------------------------------------------------------------------
       
    53 void CNotifyBatteryAndSignal::ConstructL()
       
    54 	{
       
    55 	iATCommandName = EATNone;
       
    56 	iCallbackTimer = CCallbackTimer::NewL(*this);
       
    57 	iATGetBattery = CATGetBattery::NewL(iPhoneGlobals,iCtsyDispatcherCallback);
       
    58 	iATGetSignal = CATGetSignal::NewL(iPhoneGlobals,iCtsyDispatcherCallback);
       
    59 	}
       
    60 // ---------------------------------------------------------------------------
       
    61 // CNotifyBatteryAndSignal::~CNotifyBatteryAndSignal
       
    62 // other items were commented in a header
       
    63 // ---------------------------------------------------------------------------
       
    64 CNotifyBatteryAndSignal::~CNotifyBatteryAndSignal()
       
    65 	{
       
    66 	if(iATGetBattery)
       
    67 		{
       
    68 		delete iATGetBattery;
       
    69 		iATGetBattery = NULL;
       
    70 		}
       
    71 	if(iATGetSignal)
       
    72 		{
       
    73 		delete iATGetSignal;
       
    74 		iATGetSignal = NULL;
       
    75 		}
       
    76 	}
       
    77 // ---------------------------------------------------------------------------
       
    78 // CNotifyBatteryAndSignal::AtCommandExecuteComplete
       
    79 // other items were commented in a header
       
    80 // ---------------------------------------------------------------------------
       
    81 void CNotifyBatteryAndSignal::AtCommandExecuteComplete(TAtEventSource aEventSource, TInt /*aStatus*/)
       
    82 	{
       
    83 	if(aEventSource == EWriteCompletion)
       
    84 		{
       
    85 		return;
       
    86 		}
       
    87 	TInt ret = KErrNone;
       
    88 	switch(iATCommandName)
       
    89 		{
       
    90 		case EATGetBattery:
       
    91 			iATGetBattery->RemoveAtCommandObserver();
       
    92 			iPhoneGlobals.iEventSignalActive = EFalse;
       
    93 			if(aEventSource == EReadCompletion)
       
    94 				{
       
    95 				ret = iATGetBattery->GetErrorValue();
       
    96 				if(KErrNone == ret)
       
    97 					{
       
    98 					iBatteryInfo = iATGetBattery->GetBatteryinfo();
       
    99 					TRfStateInfo RfStateInfo;
       
   100 					RfStateInfo = iATGetBattery->GetRfStateInfo();
       
   101 					if(iPhoneGlobals.iPhoneStatus.iRfStateInfo!=RfStateInfo)
       
   102 						{
       
   103 						iPhoneGlobals.iPhoneStatus.iRfStateInfo = RfStateInfo;
       
   104 						iCtsyDispatcherCallback.CallbackPhoneNotifyRfStatusChangeInd(ret,RfStateInfo);
       
   105 						}
       
   106 					if(iPhoneGlobals.iPhoneStatus.iBatteryInfo.iChargeLevel != iBatteryInfo.iChargeLevel)
       
   107 						{
       
   108 						iPhoneGlobals.iPhoneStatus.iBatteryInfo.iChargeLevel = iBatteryInfo.iChargeLevel;
       
   109 						iCtsyDispatcherCallback.CallbackPhoneNotifyBatteryInfoChangeInd(ret,iBatteryInfo);
       
   110 						}
       
   111 					}
       
   112 				}
       
   113 			iATGetBattery->Complete();
       
   114 			iATCommandName = EATGetSignal;
       
   115 			break;
       
   116 		case EATGetSignal: 
       
   117 			iATGetSignal->RemoveAtCommandObserver();
       
   118 			iPhoneGlobals.iEventSignalActive = EFalse;
       
   119 			if(aEventSource == EReadCompletion)
       
   120 				{
       
   121 				ret = iATGetSignal->GetErrorValue();
       
   122 				if(KErrNone == ret)
       
   123 					{
       
   124 					iSignalInfo = iATGetSignal->getSignalInfo();
       
   125 					if(iPhoneGlobals.iPhoneStatus.iSignalInfo.iSignalStrength != iSignalInfo.iSignalStrength)
       
   126 						{
       
   127 						iCtsyDispatcherCallback.CallbackPhoneNotifySignalStrengthChangeInd(ret,
       
   128 								                iSignalInfo.iSignalStrength,
       
   129 								                iSignalInfo.iBar);
       
   130 						}
       
   131 					}
       
   132 				}
       
   133 			iATGetSignal->Complete();
       
   134 			iATCommandName = EATGetBattery;
       
   135 			break;
       
   136 		default:
       
   137 			break;
       
   138 		}
       
   139 	StartTimer(30);
       
   140 	}
       
   141 // ---------------------------------------------------------------------------
       
   142 // CNotifyBatteryAndSignal::StartRequestL
       
   143 // other items were commented in a header
       
   144 // ---------------------------------------------------------------------------
       
   145 void CNotifyBatteryAndSignal::StartRequest()
       
   146 	{
       
   147 	StartTimer(10);
       
   148 	iATCommandName = EATGetBattery;
       
   149 	}
       
   150 // ---------------------------------------------------------------------------
       
   151 // CNotifyBatteryAndSignal::TimerRun
       
   152 // other items were commented in a header
       
   153 // ---------------------------------------------------------------------------
       
   154 void CNotifyBatteryAndSignal::TimerRun(TInt aError)
       
   155     {
       
   156 	if((aError == KErrNone)&&
       
   157 	   (!iPhoneGlobals.iEventSignalActive)&&
       
   158 	   (iPhoneGlobals.iPhoneStatus.iMode==RPhone::EModeOnlineCommand))
       
   159 	    {
       
   160 		switch(iATCommandName)
       
   161 			{
       
   162 			case EATGetBattery:
       
   163 				iPhoneGlobals.iEventSignalActive = ETrue;
       
   164 				iATGetBattery->SetAtCommandObserver(this);
       
   165 				iATGetBattery->ExecuteCommand();
       
   166 				break;
       
   167 			case EATGetSignal:
       
   168 				iPhoneGlobals.iEventSignalActive = ETrue;
       
   169 				iATGetSignal->SetAtCommandObserver(this);
       
   170 				iATGetSignal->ExecuteCommand();
       
   171 				break;
       
   172 			default:
       
   173 				break;
       
   174 			}
       
   175 		}
       
   176 	else
       
   177 		{
       
   178 		StartTimer(30);
       
   179 		}
       
   180 	}
       
   181 
       
   182 /**
       
   183  * 
       
   184  * 
       
   185  */
       
   186 void CNotifyBatteryAndSignal::StartTimer(TInt aSeconds)
       
   187     {
       
   188 	iCallbackTimer->After(aSeconds*KLtsyOneSecond);
       
   189 	}
       
   190 //
       
   191 // End of file