datacommsserver/esockserver/ssock/ss_datamon_apiext.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2006-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
       
    18  @internalTechnology
       
    19 */
       
    20 
       
    21 #include "ss_datamon_apiext.h"
       
    22 #include <comms-infras/datamonmessagesecom.h>
       
    23 #include <elements/responsemsg.h>
       
    24 
       
    25 
       
    26 #ifdef _DEBUG
       
    27 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    28 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    29 _LIT(KSpecAssert_ESockSSocksdtmnp, "ESockSSocksdtmnp");
       
    30 #endif
       
    31 
       
    32 using namespace ESock;
       
    33 using namespace Elements;
       
    34 
       
    35 EXPORT_C void CDataMonitoringResponder::DataTransferred(CDataMonitoringResponder*& aThis, TUint32 aReceivedBytes, TUint32 aSentBytes)
       
    36 	{
       
    37 	if (aThis==NULL)
       
    38 		return;
       
    39 
       
    40 	aThis->DoDataTransferred(aReceivedBytes, aSentBytes);
       
    41 	delete aThis;
       
    42 	aThis = NULL;
       
    43 	}
       
    44 	
       
    45 EXPORT_C void CDataMonitoringResponder::DataSentNotification(CDataMonitoringResponder*& aThis, TUint32 aSentBytes)
       
    46 	{
       
    47 	if (aThis==NULL)
       
    48 		return;
       
    49 
       
    50 	aThis->DoDataSentNotification(aSentBytes);
       
    51 	delete aThis;
       
    52 	aThis = NULL;
       
    53 	}
       
    54 	
       
    55 EXPORT_C void CDataMonitoringResponder::DataReceivedNotification(CDataMonitoringResponder*& aThis, TUint32 aReceivedBytes)
       
    56 	{
       
    57 	if (aThis==NULL)
       
    58 		return;
       
    59 
       
    60 	aThis->DoDataReceivedNotification(aReceivedBytes);
       
    61 	delete aThis;
       
    62 	aThis = NULL;
       
    63 	}
       
    64 
       
    65 EXPORT_C void CDataMonitoringResponder::CancelRequest(CDataMonitoringResponder*& aThis)
       
    66 	{
       
    67 	if (aThis==NULL)
       
    68 		return;
       
    69 
       
    70 	aThis->DoCancelRequest();
       
    71 	delete aThis;
       
    72 	aThis = NULL;
       
    73 	}
       
    74 
       
    75 EXPORT_C void CDataMonitoringResponder::Error(CDataMonitoringResponder*& aThis, TInt aError)
       
    76 	{
       
    77 	if (aThis==NULL)
       
    78 		return;
       
    79 
       
    80 	aThis->DoComplete(aError);
       
    81 	delete aThis;
       
    82 	aThis = NULL;
       
    83 	}
       
    84 
       
    85 /**
       
    86 	Completes the client's request for the amount of data transferred.
       
    87 	
       
    88 	@param aReceivedBytes The number of bytes received for communication to the client.	
       
    89 	@param aSentBytes The number of bytes sent for communication to the client.
       
    90 */
       
    91 void CDataMonitoringResponder::DoDataTransferred(TUint32 aReceivedBytes, TUint32 aSentBytes)
       
    92 	{
       
    93 	__ASSERT_DEBUG(iMsg == NULL, User::Panic(KSpecAssert_ESockSSocksdtmnp, 1));
       
    94 	TRAP_IGNORE(iMsg = CDataTransferred::NewL());
       
    95 
       
    96 	if(iMsg == NULL)
       
    97 		{
       
    98 		iResponseMsg.Complete(KErrNoMemory);
       
    99 		return;
       
   100 		}
       
   101 
       
   102 	CDataTransferred& msg = static_cast<CDataTransferred&>(*iMsg);	
       
   103 	
       
   104 	msg.SetReceivedBytes(aReceivedBytes);
       
   105 	msg.SetSentBytes(aSentBytes);
       
   106 
       
   107 	iResponseMsg.Complete(msg);
       
   108 	}
       
   109 	
       
   110 /**
       
   111 	Completes the client's notification request for a data sent threshold.
       
   112 	
       
   113 	@param aSentBytes The number of bytes sent for communication to the client.
       
   114 */
       
   115 void CDataMonitoringResponder::DoDataSentNotification(TUint32 aSentBytes)
       
   116 	{	
       
   117 	__ASSERT_DEBUG(iMsg == NULL, User::Panic(KSpecAssert_ESockSSocksdtmnp, 2));
       
   118 	TRAP_IGNORE(iMsg = CDataSent::NewL());
       
   119 
       
   120 	if(iMsg == NULL)
       
   121 		{
       
   122 		iResponseMsg.Complete(KErrNoMemory);
       
   123 		return;
       
   124 		}
       
   125 
       
   126 	CDataSent& msg = static_cast<CDataSent&>(*iMsg);
       
   127 	msg.SetSentBytes(aSentBytes);
       
   128 
       
   129 	iResponseMsg.Complete(msg);
       
   130 	}
       
   131 
       
   132 /**
       
   133 	Completes the client's notification request for a data received threshold.
       
   134 	
       
   135 	@param aReceivedBytes The number of bytes received for communication to the client.
       
   136 */
       
   137 void CDataMonitoringResponder::DoDataReceivedNotification(TUint32 aReceivedBytes)
       
   138 	{
       
   139 	__ASSERT_DEBUG(iMsg == NULL, User::Panic(KSpecAssert_ESockSSocksdtmnp, 3));
       
   140 	TRAP_IGNORE(iMsg = CDataReceived::NewL());
       
   141 
       
   142 	if(iMsg == NULL)
       
   143 		{
       
   144 		iResponseMsg.Complete(KErrNoMemory);
       
   145 		return;
       
   146 		}
       
   147 				
       
   148 	CDataReceived& msg = static_cast<CDataReceived&>(*iMsg);
       
   149 	msg.SetReceivedBytes(aReceivedBytes);
       
   150 
       
   151 	iResponseMsg.Complete(msg);
       
   152 	}
       
   153 
       
   154 /**
       
   155 	Cancels the outstanding response request.
       
   156 */
       
   157 void CDataMonitoringResponder::DoCancelRequest()
       
   158 	{
       
   159 	iResponseMsg.Complete(KErrCancel);
       
   160 	}
       
   161 
       
   162 EXPORT_C CDataMonitoringResponder* CDataMonitoringResponder::NewL(Elements::RResponseMsg& aResponseMsg)
       
   163 	{
       
   164 	return new(ELeave) CDataMonitoringResponder(aResponseMsg);
       
   165 	}
       
   166 
       
   167 CDataMonitoringResponder::CDataMonitoringResponder(Elements::RResponseMsg& aResponseMsg)
       
   168 	: CCommsApiExtIpcResponder(aResponseMsg)
       
   169 	{
       
   170 	}
       
   171 
       
   172 CDataMonitoringResponder::~CDataMonitoringResponder()
       
   173 	{
       
   174 	delete iMsg;
       
   175 	}
       
   176 
       
   177