dbgagents/trkagent/engine/TrkCommPort.h
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __TRKCOMMPORT_H__
       
    20 #define __TRKCOMMPORT_H__
       
    21 
       
    22 #include <e32base.h>
       
    23 #include "TrkConnData.h"
       
    24 
       
    25 
       
    26 //
       
    27 // Macros
       
    28 //
       
    29 // these must be defined before including msgcmd.h
       
    30 #define DS_PROTOCOL	DS_PROTOCOL_RTOS
       
    31 #define DEBUG_MSGCMD 0
       
    32 
       
    33 #include "msgcmd.h"
       
    34 
       
    35 #define SafeDelete(x) { if (x) delete x; x = NULL; }
       
    36 
       
    37 
       
    38 //
       
    39 // class CInactivityTimerDisabler
       
    40 //
       
    41 // Active object used to avoid auto-switch off
       
    42 //
       
    43 class CInactivityTimerDisabler : public CActive
       
    44 {
       
    45 public:
       
    46 
       
    47 	CInactivityTimerDisabler();
       
    48 	void ConstructL();
       
    49 	~CInactivityTimerDisabler();
       
    50 	void Activate();
       
    51 
       
    52 protected:
       
    53 
       
    54 	void RunL();
       
    55 	void DoCancel();
       
    56 
       
    57 private:
       
    58 
       
    59 	enum { KPeriod = 5 * 1000000 };
       
    60 
       
    61 	RTimer iTimer;
       
    62 };
       
    63 
       
    64 //
       
    65 //
       
    66 // CInactivityTimerDisabler implementation
       
    67 //
       
    68 //
       
    69 
       
    70 inline CInactivityTimerDisabler::CInactivityTimerDisabler()
       
    71 	: CActive(EPriorityLow)
       
    72 {
       
    73 	CActiveScheduler::Add(this);
       
    74 }
       
    75 
       
    76 inline void CInactivityTimerDisabler::ConstructL()
       
    77 {
       
    78 	User::LeaveIfError(iTimer.CreateLocal());
       
    79 }
       
    80 
       
    81 inline CInactivityTimerDisabler::~CInactivityTimerDisabler()
       
    82 {
       
    83 	Cancel();
       
    84 	iTimer.Close();
       
    85 	Deque();
       
    86 }
       
    87 
       
    88 inline void CInactivityTimerDisabler::Activate()
       
    89 {
       
    90 	iTimer.After(iStatus, KPeriod);
       
    91 	SetActive();
       
    92 }
       
    93 
       
    94 inline void CInactivityTimerDisabler::RunL()
       
    95 {
       
    96 	User::ResetInactivityTime();
       
    97 	Activate();
       
    98 }
       
    99 
       
   100 inline void CInactivityTimerDisabler::DoCancel()
       
   101 {
       
   102 	iTimer.Cancel();
       
   103 }
       
   104 
       
   105 
       
   106 //
       
   107 // Forward declarations
       
   108 class CTrkFramingLayer;
       
   109 
       
   110 
       
   111 //
       
   112 // class CTrkCommPort
       
   113 //
       
   114 // Abstract base class for communications port
       
   115 //
       
   116 class CTrkCommPort : public CActive
       
   117 {
       
   118 public:
       
   119 	
       
   120 	virtual ~CTrkCommPort();
       
   121 
       
   122 	virtual void OpenPortL() = 0;
       
   123 	virtual void ClosePort() = 0;
       
   124 	virtual void SendDataL(const TDesC8& aData) = 0;
       
   125 	virtual void Listen(CTrkFramingLayer *aFramingLayer) = 0;
       
   126 	virtual void StopListening() = 0;
       
   127 	virtual TBool IsConnectionEstablished() { return iConnectionStatus == ETrkConnected; };
       
   128 	virtual void GetConnectionInfo(TDes& aMessage) { aMessage = iConnectionMessage; };
       
   129 	virtual void GetErrorInfo(TDes& aMessage) { aMessage = iErrorMessage; };
       
   130 	virtual TTrkConnStatus GetConnectionStatus() { return iConnectionStatus; };
       
   131 
       
   132 protected:
       
   133 
       
   134 	CTrkCommPort(TInt aPriority, TTrkConnStatus aConnectionStatus);
       
   135 
       
   136 	TBuf<KMaxPath> iConnectionMessage;
       
   137 	TBuf<KMaxPath> iErrorMessage;
       
   138 	TTrkConnStatus iConnectionStatus;
       
   139 };
       
   140 
       
   141 inline CTrkCommPort::CTrkCommPort(TInt aPriority,TTrkConnStatus aConnectionStatus=ETrkConnected)
       
   142 	: CActive(aPriority),
       
   143 	iConnectionStatus(aConnectionStatus)
       
   144 {
       
   145 }
       
   146 
       
   147 inline CTrkCommPort::~CTrkCommPort()
       
   148 {
       
   149 }
       
   150 
       
   151 #endif // __TRKCOMMPORT_H__