bluetooth/btcomm/src/btcommactive.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 1997-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 #ifndef BTCOMMACTIVE_H__
       
    17 #define BTCOMMACTIVE_H__
       
    18 
       
    19 _LIT(KConnectorThreadName, "ESock Connector Thread ");
       
    20 
       
    21 NONSHARABLE_CLASS(CBTPortBuffer) : public CCirBufBase
       
    22 /** 
       
    23 	Circular buffer for received data.
       
    24 	Add and Remove of single byte as well
       
    25 	as multiple bytes.
       
    26 */
       
    27 	{
       
    28 public:
       
    29 	static CBTPortBuffer *NewL(CBTPortProxy *aParent,TInt aBufSize);
       
    30 	~CBTPortBuffer();
       
    31 	TInt Add(const TUint8* aPtr,TInt aCount);
       
    32 	TInt Remove(TUint8* aPtr,TInt aCount);
       
    33 	TInt ScanForTerminator(TReadTerminator& aTerminator);
       
    34 private:
       
    35 	CBTPortBuffer(TInt aBufSize);
       
    36 	void ConstructL(CBTPortProxy *aParent);
       
    37 	TInt ScanForTerminatorSequence(TReadTerminator& aTerminator,TText8 aChar);
       
    38 private:
       
    39 	CBTPortProxy *iPortProxy;
       
    40 	TInt iCircBufSize;
       
    41 	};
       
    42 
       
    43 //	** BT CSY ACTIVE OBJECTS **
       
    44 
       
    45 NONSHARABLE_CLASS(CBTPortLocker) : public CActive
       
    46 	{
       
    47 public:
       
    48 	static CBTPortLocker *NewL(CBTPortProxy *aParent);
       
    49 	~CBTPortLocker();
       
    50 	void RunL();
       
    51 	void LockSession();
       
    52 	void UnlockSession();
       
    53 	void DoCancel();
       
    54 	TBool IsSessionLocked();
       
    55 private:
       
    56 	CBTPortLocker();
       
    57 	void InitL(CBTPortProxy *aParent);
       
    58 private:
       
    59 	CBTPortProxy *iPortProxy;
       
    60 	TBool iLockOn; // indicates whether we already have a locked session with ESock
       
    61 	};
       
    62 
       
    63 NONSHARABLE_CLASS(CBTPortWriter) : public CActive
       
    64 	{
       
    65 public:
       
    66 	static CBTPortWriter *NewL(CBTPortProxy *aParent);
       
    67 	~CBTPortWriter();
       
    68 	void RunL();
       
    69 	void QueueWrite(const TDesC8& aData);
       
    70 	void DoCancel();
       
    71 private:
       
    72 	CBTPortWriter();
       
    73 	void InitL(CBTPortProxy *aParent);
       
    74 private:
       
    75 	CBTPortProxy *iPortProxy;
       
    76 	};
       
    77 
       
    78 NONSHARABLE_CLASS(CBTPortReader) : public CActive
       
    79 	{
       
    80 public:
       
    81 	static CBTPortReader *NewL(CBTPortProxy *aParent);
       
    82 	~CBTPortReader();
       
    83 	void RunL();
       
    84 	void QueueRead();
       
    85 	void DoCancel();
       
    86 	void StopReading();
       
    87 	void StartReading();
       
    88 	TBool IsReading();
       
    89 private:
       
    90 	CBTPortReader();
       
    91 	void InitL(CBTPortProxy *aParent);
       
    92 private:
       
    93 	TBool			iKeepReading;
       
    94 	HBufC8*			iLocalReadBuffer;
       
    95 	TPtr8			iLocalReadBufferPtr;
       
    96 	CBTPortProxy*	iPortProxy;
       
    97 	TSockXfrLength	iPlen;
       
    98 	};
       
    99 
       
   100 NONSHARABLE_CLASS(CSockServConnector) : public CActive
       
   101 	{
       
   102 public:
       
   103 	/**
       
   104 	 Standard factory function.
       
   105 	 @return a fully initialised CSockServConnector
       
   106 	 */
       
   107 	static CSockServConnector* NewL(RSocketServ& aSockServ);
       
   108 	
       
   109 	/**
       
   110 	 Destructor
       
   111 	 */
       
   112 	~CSockServConnector();
       
   113 	
       
   114 	/**
       
   115 	 Initiate connection to ESock.  To do this with no threat
       
   116 	 of deadlock a new thread is spawned which connects up
       
   117 	 the RSocketServ and shares it with this thread.  When the
       
   118 	 callers request is completed the ESock session is ready to
       
   119 	 use.
       
   120 	 @param aSockServ ESock session to connect, ready to use on 
       
   121 	 completion.
       
   122 	 @param aStatus Callers iStatus, contains result of connect on 
       
   123 	 completion.
       
   124 	 */
       
   125 	 void SockServConnect(TRequestStatus& aStatus);
       
   126 	 
       
   127 private:
       
   128 	/**
       
   129 	 Constructor
       
   130 	 */
       
   131 	CSockServConnector(RSocketServ& aSockServ);
       
   132 	
       
   133 	/**
       
   134 	 Second phase construction.
       
   135 	 */
       
   136 	void ConstructL();
       
   137 	
       
   138 	/**
       
   139 	 Implementation of RunL() function inherited from CActive.
       
   140 	 When this is called the ESock Connect() has completed, this
       
   141 	 informs user of the result and attaches the session to this
       
   142 	 thread.
       
   143 	 */
       
   144 	void RunL();
       
   145 	
       
   146 	/** 
       
   147 	 On leave from RunL notifies client of error and closes handle
       
   148 	 on connector thread.
       
   149 	 */
       
   150 	TInt RunError(TInt aError);
       
   151 	
       
   152 	/**
       
   153 	 Implementation of DoCancel() function inherited from CActive.
       
   154 	 */
       
   155 	void DoCancel();
       
   156 	
       
   157 	/** 
       
   158 	 Completes client request and closes connector thread handle.
       
   159 	 @param aError Error code used to complete client request
       
   160 	 */
       
   161 	 void NotifyAndClose(TInt aError);
       
   162 	
       
   163 private:
       
   164 	RSocketServ& iSockServ;
       
   165 	RThread	iConnectorThread;
       
   166 	TRequestStatus* iClientStatus;
       
   167 	};
       
   168 
       
   169 #endif