bluetoothengine/bthid/bthidserver/inc/socketwriter.h
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Declares main application class.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __SOCKETSWRITER_H__
       
    20 #define __SOCKETSWRITER_H__
       
    21 
       
    22 #include <es_sock.h>
       
    23 #include "timeoutnotifier.h"
       
    24 
       
    25 class CTimeOutTimer;
       
    26 class MSocketObserver;
       
    27 
       
    28 /*!
       
    29  This class handles writing data to a socket.
       
    30  */
       
    31 class CSocketWriter : public CActive, public MTimeOutNotifier
       
    32     {
       
    33 public:
       
    34     /*!
       
    35      Create a CSocketWriter object
       
    36      @param aSocketID ID given to the socket. Used when reporting back.
       
    37      @param aObserver an observer for status reporting
       
    38      @result A pointer to the created instance of CSocketWriter
       
    39      */
       
    40     static CSocketWriter* NewL(TUint aSocketID, MSocketObserver& aObserver);
       
    41 
       
    42     /*!
       
    43      Create a CSocketWriter object
       
    44      @param aSocketID ID given to the socket. Used when reporting back.
       
    45      @param aObserver an observer for status reporting
       
    46      @result A pointer to the created instance of CSocketWriter
       
    47      */
       
    48     static CSocketWriter* NewLC(TUint aSocketID, MSocketObserver& aObserver);
       
    49 
       
    50     /*!
       
    51      Destroy the object and release all memory objects
       
    52      */
       
    53     ~CSocketWriter();
       
    54 
       
    55     /*!
       
    56      Write the data to the socket
       
    57      @param aData the data to be written
       
    58      */
       
    59     void IssueWriteL(const TDesC8& aData);
       
    60 
       
    61     /*!
       
    62      Initialise the writer with a socket
       
    63      @param aSocket socket to write to.
       
    64      */
       
    65     void Initialise(RSocket* aSocket);
       
    66 
       
    67 public:
       
    68     // From MTimeOutNotifier
       
    69 
       
    70     void TimerExpired();
       
    71 
       
    72 protected:
       
    73     // from CActive
       
    74     /*!
       
    75      Cancel any outstanding operation
       
    76      */
       
    77     void DoCancel();
       
    78 
       
    79     /*!
       
    80      Called when operation complete
       
    81      */
       
    82     void RunL();
       
    83 
       
    84 private:
       
    85     /*!
       
    86      Perform the first phase of two phase construction 
       
    87      @param aSocketID ID given to the socket. Used when reporting back.
       
    88      @param aObserver an observer for status reporting
       
    89      */
       
    90     CSocketWriter(TUint aSocketID, MSocketObserver& aObserver);
       
    91 
       
    92     /*!
       
    93      Perform the second phase construction of a CSocketWriter 
       
    94      */
       
    95     void ConstructL();
       
    96 
       
    97     /**
       
    98      *  Write the data from the current buffer to the socket.
       
    99      */
       
   100     void DoWrite();
       
   101     /**
       
   102      *  Store data to be written in the specified buffer.
       
   103      *  @param aData Data to be written.
       
   104      *  @param aBuffer Which buffer to use.
       
   105      */
       
   106     void StoreDataL(const TDesC8& aData, TInt aBuffer);
       
   107 
       
   108 private:
       
   109     // Member variables
       
   110 
       
   111     /*! The maximum time allowed for a write to complete */
       
   112     static const TInt KTimeOut;
       
   113 
       
   114     /*! The ID of the RSocket we are working on */
       
   115     TUint iSocketID;
       
   116 
       
   117     /*! An observer for status reporting */
       
   118     MSocketObserver& iObserver;
       
   119 
       
   120     /*! The socket to write to */
       
   121     RSocket* iSocket;
       
   122 
       
   123     /*! Timer used to cancel a write after a predefined timeout */
       
   124     CTimeOutTimer* iTimer;
       
   125 
       
   126     /** Buffers to hold the data being written */
       
   127     HBufC8* iWriteBuffer[2];
       
   128 
       
   129     /** The buffer whose contents are currently being written */
       
   130     TInt iCurrentBuffer;
       
   131     };
       
   132 
       
   133 #endif // __SOCKETSWRITER_H__