connectivitylayer/isce/p2prouter_dll/inc/p2puserchannel.h
changeset 0 63b37f68c1ce
child 9 8486d82aef45
equal deleted inserted replaced
-1:000000000000 0:63b37f68c1ce
       
     1 /*
       
     2 * Copyright (c) 2009 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 the License "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 
       
    20 #ifndef __DP2PUSERCHANNEL_H__
       
    21 #define __DP2PUSERCHANNEL_H__
       
    22 
       
    23 // Includes
       
    24 #include <kernel.h>                 // For DLogicalChannel
       
    25 #include "p2prouterchannelifs.h"    // For MP2PRouterChIf
       
    26 #include "p2pinternaldefs.h"        // For TP2PAsyncRequest
       
    27 
       
    28 // Class declaration
       
    29 class DMsgQueue;
       
    30 class DP2PReqQueue;
       
    31 
       
    32 /**
       
    33 * Provides channel for user side P2P API
       
    34 */
       
    35 NONSHARABLE_CLASS( DP2PUserChannel ) : public DLogicalChannel, public MP2PRouterChIf
       
    36     {
       
    37 
       
    38     public: 
       
    39 
       
    40         /**
       
    41         * C++ default constructor.
       
    42         */
       
    43         DP2PUserChannel();
       
    44 
       
    45         /**
       
    46         * Destructor.
       
    47         */
       
    48         ~DP2PUserChannel();
       
    49 
       
    50         ///// Functions from base class DLogicalChannel start
       
    51 
       
    52         /**
       
    53         * Second phase constructor. Run in user thread context.
       
    54         * Thread in CS and can not be pre-empted.
       
    55         * See other comments from DLogicalChannel.
       
    56         * @param aUnit, Not used at the moment possible to have over 32 channel.
       
    57         * @param anInfo, contains the protocol id
       
    58         * @param aVer, Not used at the moment.
       
    59         */
       
    60         virtual TInt DoCreate( TInt aUnit, const TDesC8* anInfo, const TVersion& aVer );
       
    61 
       
    62         /**
       
    63         * Kernel message que function. Run in kernel thread context.
       
    64         * See other comments from DLogicalChannel.
       
    65         * @param aMsg, message from Request function.
       
    66         */
       
    67         virtual void HandleMsg( TMessageBase* aMsg );
       
    68 
       
    69         /**
       
    70         * Overwritten so that accepts only calls with DoControl.
       
    71         * See other comments from DLogicalChannel.
       
    72         */
       
    73         TInt Request( TInt aReqNo, TAny* a1, TAny* a2 );
       
    74 
       
    75         ///// Functions from base class DLogicalChannel end
       
    76 
       
    77         ///// Functions from MP2PRouterChIf start
       
    78         /*
       
    79         * See comments from MP2PRouterChIf.
       
    80         */
       
    81         void ConnectionLost();
       
    82 
       
    83         /**
       
    84         * See other comments from MP2PRouterChIf.
       
    85         */
       
    86         void EnqueChannelRequestCompleteDfc( TInt aRequest, TInt aStatusToComplete );
       
    87 
       
    88         /*
       
    89         * Called when message to this channel is to be received.
       
    90         * @param aDataMessage, data message.
       
    91         * @return void
       
    92         */
       
    93         void ReceiveMsg( const TDesC8& aMessage );
       
    94 
       
    95         ///// Functions from MP2PRouterChIf end
       
    96 
       
    97     private:
       
    98 
       
    99         /*
       
   100         * Closes the channel toward router.
       
   101         * Modifies member variable iShP2PProtocolId.
       
   102         * Called in P2P extension kernel thead context.
       
   103         * @param aP2PProtocolId, protocol id of the channel to be closed.
       
   104         */
       
   105         void Close( const TUint8 aP2PProtocolId );
       
   106 
       
   107         /*
       
   108         * Handles actions related to closing the channel.
       
   109         */
       
   110         void Closing();
       
   111 
       
   112         /**
       
   113         * DFC function that completes channel requests to user thread.
       
   114         * Run always in P2P user channel kernel thread context.
       
   115         * @param aPtr, pointer to self
       
   116         * @return None
       
   117         */
       
   118         static void CompleteChReqDfc( TAny* aPtr );
       
   119 
       
   120         /*
       
   121         * Handling of asynchronous requests.
       
   122         * @param aFunction, request id
       
   123         * @param a1, pointer to parameters.
       
   124         * @return void
       
   125         */
       
   126         void HandleAsyncRequest( TInt aFunction, TAny* a1 );
       
   127 
       
   128         /*
       
   129         * Handling of cancellation of asynchronous requests.
       
   130         * @param aFunction, request id
       
   131         * @param a1, pointer to parameters.
       
   132         * @return void
       
   133         */
       
   134         TInt HandleCancelRequest( TInt aFunction, TAny* a1 );
       
   135 
       
   136         /*
       
   137         * Handling of all requests.
       
   138         * @param aFunction, request id
       
   139         * @param a1, pointer to parameters.
       
   140         * @param a2, not used
       
   141         * @return void
       
   142         */
       
   143         TInt HandleRequest( TInt aFunction, TAny* a1, TAny* a2 );
       
   144 
       
   145         /*
       
   146         * Handling of synchronous requests.
       
   147         * @param aFunction, request id
       
   148         * @param a1, pointer to parameters.
       
   149         * @return void
       
   150         */
       
   151         TInt HandleSyncRequest( TInt aFunction, TAny* a1 );
       
   152 
       
   153         /**
       
   154         * DFC function that empties message receive queue to user thread.
       
   155         * @param aPtr, pointer to self
       
   156         * @return None
       
   157         */
       
   158         static void EmptyRxQueueDfc( TAny* aPtr );
       
   159 
       
   160         /**
       
   161         * Resets channel data message and message queues.
       
   162         * @return None
       
   163         */
       
   164         void ResetQueues();
       
   165 
       
   166         /**
       
   167         * Do the cancellation of request.
       
   168         * @param aRequest,
       
   169         * @param aMask
       
   170         * @return None
       
   171         */
       
   172         void DoCancel( TInt aRequest, TInt aMask );
       
   173 
       
   174     // Internal Classes
       
   175 
       
   176     /*
       
   177     * 
       
   178     */
       
   179     NONSHARABLE_CLASS( TP2PReq )
       
   180         {
       
   181 
       
   182         public:
       
   183 
       
   184            TP2PReq();
       
   185 
       
   186            TP2PReq( TP2PAsyncRequest aReq, TInt aStat );
       
   187 
       
   188            // Data
       
   189            TP2PAsyncRequest    iRequest;
       
   190            TInt                iCompleteStatus;
       
   191 
       
   192         };
       
   193 
       
   194     /*
       
   195     * Handles requests in a ring buffer manner.
       
   196     * Syncronization protection by NFastMutex.
       
   197     */
       
   198     NONSHARABLE_CLASS( DP2PReqQueue ) : public DBase
       
   199         {
       
   200 
       
   201         public:
       
   202 
       
   203             /*
       
   204             * Default constructor
       
   205             */
       
   206             DP2PReqQueue();
       
   207 
       
   208             /*
       
   209             * Destructor
       
   210             */
       
   211             ~DP2PReqQueue();
       
   212 
       
   213             /* 
       
   214             * In case of queue overflow throw kern::fault
       
   215             * Adds the message in the end of the ringbuffer queue.
       
   216             * @param aReq
       
   217             */
       
   218             TBool Add( TP2PReq aReq );
       
   219 
       
   220             /*
       
   221             *Returns ETrue if empty.
       
   222             */
       
   223             TBool Empty();
       
   224 
       
   225             /*
       
   226             *Returns first request.
       
   227             */
       
   228             TP2PReq Get();
       
   229 
       
   230             /*
       
   231             * Set req active / deactive. Default deactive.
       
   232             */
       
   233             void SetReq( TP2PAsyncRequest aReqToSet, TRequestStatus* aStatus = NULL );
       
   234 
       
   235             /*
       
   236             * Get req. If NULL, request not pending.
       
   237             */
       
   238             TRequestStatus* GetReq( TP2PAsyncRequest aReqToGet );
       
   239 
       
   240       private:
       
   241 
       
   242             // Index where to add next message pointer.
       
   243             TUint8          iShInputIndex;
       
   244             // Index where to get next message pointer.
       
   245             TUint8          iShOutputIndex;
       
   246             // Count of items in the array.
       
   247             TUint8          iShCount;
       
   248             // Size of the ring buffer. Write only in constructor.
       
   249             TUint8          iSize;
       
   250             // Guards internal states of this class.
       
   251             NFastMutex*     iQueueMutex;
       
   252             // Ring buffer must be as big as we have request. TODO: is there a danger to get more request..?
       
   253             TP2PReq         iShReqRingBuffer[ EP2PLastAsyncRequest ];
       
   254             // Active / Deactive requests are kept in list to make finding easier.
       
   255             TRequestStatus* iShReqList[ EP2PLastAsyncRequest ];
       
   256 
       
   257         };
       
   258 
       
   259     private:
       
   260 
       
   261         // Added convention:
       
   262         // Prefix "iSh" means shared member variable
       
   263         // Prefix "gSh" means shared global variable
       
   264 
       
   265         // Data members
       
   266         // Channel number of this channel.
       
   267         TUint8              iShP2PProtocolId;
       
   268         // Mutex guarding iShP2PProtocolId, not owned
       
   269         DMutex*             iShP2PProtocolIdMutex;
       
   270         // Pointers to client message buffer, not owned
       
   271         TAny*               iReceiveBufPtr;
       
   272         // Owned, synchronized internally with fastmutexes no need to guard
       
   273         DMsgQueue*          iRx;
       
   274         // Owned, no need to sync don internally
       
   275         TDfc*               iEmptyRxQueueDfc;
       
   276         // Owned, no need to sync don internally
       
   277         TDfc*               iCompleteChannelRequestDfc;
       
   278         // Owned, synchronized internally with fastmutexes.
       
   279         DP2PReqQueue*       iP2PReqQueue;
       
   280         // Not owned, no need to guard open/close in one thread in construction and desctruction.
       
   281         DThread*            iThread;
       
   282         // Not owned, no need to guard only written in one thread in construction and desctruction.
       
   283         MP2PChRouterIf*     iRouterIf;
       
   284 
       
   285     };
       
   286 
       
   287 #endif      // __DP2PUSERCHANNEL_H__
       
   288             
       
   289 // End of File