telephonyprotocols/psdagt/src/psdlogger.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     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 // PSD-specific logging class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file PsdLogger.cpp
       
    20 */
       
    21 
       
    22 #include "psdlogger.h"
       
    23 #include "psdagt.h"
       
    24 #include <comms-infras/cagentsmbase.h>
       
    25 #include <logengevents.h>
       
    26 
       
    27 CDataLogger* CDataLogger::NewL(MPsdEnv* aPsdSM,MAgentNotify* aObserver)
       
    28 /**
       
    29 Constructing an object of class CDataLogger, pushing it into the clean up stack and popping it.
       
    30 
       
    31 @return a pointer to class CDataLogger.
       
    32 */
       
    33 	{
       
    34 	CDataLogger* log = new (ELeave) CDataLogger(aPsdSM,aObserver);
       
    35 	CleanupStack::PushL(log);
       
    36 	log->ConstructL();
       
    37 	CleanupStack::Pop();
       
    38 	return log;
       
    39 	}
       
    40 
       
    41 CDataLogger::CDataLogger(MPsdEnv* aPsdSM,MAgentNotify* aObserver)
       
    42 : iSM(aPsdSM), iSMObserver(aObserver)
       
    43 /**
       
    44 Constructor
       
    45 */
       
    46 	{
       
    47 	}
       
    48 
       
    49 void CDataLogger::ConstructL()
       
    50 	{
       
    51 	iRegularUpdater = CPeriodic::NewL(EPriorityLow);
       
    52 	}
       
    53 
       
    54 CDataLogger::~CDataLogger()
       
    55 	{
       
    56 	delete iRegularUpdater;
       
    57 	}
       
    58 
       
    59 void CDataLogger::Start()
       
    60 /**
       
    61 This must not log anything immediately because the asynchronous log start will probably
       
    62 still be outstanding (started by the Open state) we must therefore wait for this start to complete
       
    63 we will therefore wait for the time KRegularUpdateInterval before commencing logging otherwise
       
    64 the log will not be open once we begin writing to it.
       
    65 
       
    66 Assumption: log start takes less time than KRegularUpdateInterval.
       
    67 We use the Active-Objectness of CDataLogger to cope with the asynchronous logging of
       
    68 data transferred, with the same assumption as above.
       
    69 */
       
    70 	{
       
    71 	__ASSERT_DEBUG(iSM,User::Invariant());
       
    72 
       
    73 	TCallBack callbackfn(CDataLogger::Update, this);
       
    74 	iRegularUpdater->Start(KRegularUpdateInterval,KRegularUpdateInterval,callbackfn);
       
    75 	}
       
    76 
       
    77 void CDataLogger::StopL()
       
    78 /**
       
    79 No longer an active object
       
    80 LogDataUpdateEvent will put the request in a queue
       
    81 and process when available
       
    82 */
       
    83   	{
       
    84 		iRegularUpdater->Cancel();
       
    85 	
       
    86 		TInt ret=KErrNone;
       
    87 		if(iSM->Config().TsySupportsDataTransferInfoL(iSM->PacketNetwork()))
       
    88 			{
       
    89 			ret = iSM->Context().GetDataVolumeTransferred(iVolumeTransferred);
       
    90 			}
       
    91 		else	// retrieve last values from PPP
       
    92 			{
       
    93 			TPckg<RPacketContext::TDataVolume> dataPackage(iVolumeTransferred);
       
    94 			ret = iSMObserver->Notification(EAgentToNifEventTypeGetDataTransfer,&dataPackage);
       
    95 			}
       
    96 		if (ret==KErrNone)
       
    97 			LogData();
       
    98 	}	
       
    99 
       
   100 TInt CDataLogger::Update(TAny* aContext)
       
   101 /**
       
   102 This function is called every minute
       
   103 */
       
   104 	{
       
   105 	CDataLogger* datalogger = REINTERPRET_CAST(CDataLogger*,aContext);
       
   106 	TRAPD(ret,datalogger->RegularUpdateL());
       
   107 	return ret;
       
   108 	}
       
   109 
       
   110 void CDataLogger::RegularUpdateL()
       
   111 /**
       
   112 Only logs if there has been change.
       
   113 */
       
   114 	{
       
   115 
       
   116 	__ASSERT_DEBUG(iSM,User::Invariant());
       
   117 	__ASSERT_DEBUG(iSMObserver,User::Invariant());
       
   118 
       
   119 	RPacketContext::TDataVolume newVolume;
       
   120 	if(iSM->Config().TsySupportsDataTransferInfoL(iSM->PacketNetwork()))
       
   121 		// does the phone support counting the data volume transfer?
       
   122 		{
       
   123 		User::LeaveIfError(iSM->Context().GetDataVolumeTransferred(newVolume));
       
   124 		}
       
   125 	else	// if not request values from PPP instead
       
   126 		{
       
   127 		TPckg<RPacketContext::TDataVolume> dataPackage(newVolume);
       
   128 		User::LeaveIfError(iSMObserver->Notification(EAgentToNifEventTypeGetDataTransfer,&dataPackage));
       
   129 		}
       
   130 	
       
   131 	if (IsVolumeChanged(newVolume))
       
   132 		{
       
   133 		iVolumeTransferred = newVolume;
       
   134 		LogData();
       
   135 		}
       
   136 	}
       
   137 
       
   138 void CDataLogger::LogData() 
       
   139 	{
       
   140 	TInt64 sent = MAKE_TINT64(iVolumeTransferred.iOverflowCounterSent,iVolumeTransferred.iBytesSent);
       
   141 	TInt64 recvd = MAKE_TINT64(iVolumeTransferred.iOverflowCounterReceived,iVolumeTransferred.iBytesReceived);
       
   142 	iSM->Logger()->LogDataUpdateEvent(CEventLogger::KConnectionStatusIdNotAvailable, KLogPacketDataEventTypeUid, sent,recvd);
       
   143 	}
       
   144 
       
   145 TBool CDataLogger::IsVolumeChanged(RPacketContext::TDataVolume& aNewVolume) const
       
   146 	{
       
   147 	return (aNewVolume.iBytesReceived!=iVolumeTransferred.iBytesReceived ||
       
   148 				aNewVolume.iBytesSent!=iVolumeTransferred.iBytesSent);
       
   149 	}
       
   150