localconnectivityservice/dun/utils/inc/DunDataPusher.h
branchRCL_3
changeset 20 4a793f564d72
parent 19 0aa8cc770c8a
child 21 74aa6861c87d
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
     1 /*
       
     2 * Copyright (c) 2008-2010 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:  Pushes data to existing stream from outside
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CDUNDATAPUSHER_H
       
    20 #define C_CDUNDATAPUSHER_H
       
    21 
       
    22 #include "DunTransporter.h"
       
    23 
       
    24 class MDunCompletionReporter;
       
    25 
       
    26 /**
       
    27  *  Class used for storing data related to data push
       
    28  *  (data coming from MDunStreamManipulator::NotifyDataPushRequest())
       
    29  *
       
    30  *  @lib dunutils.lib
       
    31  *  @since S60 v3.2
       
    32  */
       
    33 NONSHARABLE_CLASS( TDunDataPush )
       
    34     {
       
    35 
       
    36 public:
       
    37 
       
    38     /**
       
    39      * Data to push to the stream (not copied)
       
    40      */
       
    41     const TDesC8* iDataToPush;
       
    42 
       
    43     /**
       
    44      * Callback to call when data is processed by the stream
       
    45      * If this is NULL then no callback will be made
       
    46      */
       
    47     MDunCompletionReporter* iCallback;
       
    48 
       
    49     };
       
    50 
       
    51 /**
       
    52  *  Class for notifications of stream manipulator's completion events
       
    53  *
       
    54  *  @lib dunutils.lib
       
    55  *  @since S60 v3.2
       
    56  */
       
    57 NONSHARABLE_CLASS( MDunCompletionReporter )
       
    58     {
       
    59 
       
    60 public:
       
    61 
       
    62     /**
       
    63      * Gets called when data from
       
    64      * MDunStreamManipulator::NotifyDataPushRequest() has been processed and
       
    65      * CDunDownstream is ready to process more data.
       
    66      *
       
    67      * @since S60 5.0
       
    68      * @param aAllPushed ETrue if all in the queue were pushed, EFalse otherwise
       
    69      * @return None
       
    70      */
       
    71     virtual void NotifyDataPushComplete( TBool aAllPushed ) = 0;
       
    72 
       
    73     };
       
    74 
       
    75 /**
       
    76  *  Class for pushing data to existing CDunDownstream stream from outside
       
    77  *
       
    78  *  @lib dunutils.lib
       
    79  *  @since S60 v3.2
       
    80  */
       
    81 NONSHARABLE_CLASS( CDunDataPusher ) : public CActive
       
    82     {
       
    83 
       
    84 public:
       
    85 
       
    86     /**
       
    87      * Two-phased constructor.
       
    88      * @param aParent Parent class owning this friend class (CDunDownstream)
       
    89      * @param aStreamCallback Callback to call when events processed
       
    90      * @return Instance of self
       
    91      */
       
    92 	static CDunDataPusher* NewL( CDunDownstream& aParent,
       
    93 	                             MDunCompletionReporter* aStreamCallback );
       
    94 
       
    95     /**
       
    96     * Destructor.
       
    97     */
       
    98     virtual ~CDunDataPusher();
       
    99 
       
   100     /**
       
   101      * Resets data to initial values
       
   102      *
       
   103      * @since S60 3.2
       
   104      * @return None
       
   105      */
       
   106     void ResetData();
       
   107 
       
   108     /**
       
   109      * Sets media to be used for this endpoint
       
   110      *
       
   111      * @since S60 3.2
       
   112      * @param aComm RComm pointer to use as the endpoint
       
   113      * @return Symbian error code on error, KErrNone otherwise
       
   114      */
       
   115     TInt SetMedia( RComm* aComm );
       
   116 
       
   117     /**
       
   118      * Sets media to be used for this endpoint
       
   119      *
       
   120      * @since S60 3.2
       
   121      * @param aSocket RSocket pointer to use as the endpoint
       
   122      * @return Symbian error code on error, KErrNone otherwise
       
   123      */
       
   124     TInt SetMedia( RSocket* aSocket );
       
   125 
       
   126     /**
       
   127      * Adds event notification to queue
       
   128      *
       
   129      * @since S60 3.2
       
   130      * @param aDataToPush Data to push to the stream (not copied)
       
   131      * @param aCallback Callback to call when data is processed by the stream
       
   132      * @return Symbian error code on error, KErrNone otherwise
       
   133      */
       
   134     TInt AddToEventQueue( const TDesC8* aDataToPush,
       
   135                           MDunCompletionReporter* aCallback );
       
   136 
       
   137     /**
       
   138      * Finds an event from queue
       
   139      *
       
   140      * @since S60 5.0
       
   141      * @param aDataToPush Data to push to the stream (not copied)
       
   142      * @return Index of found event, Symbian error code otherwise
       
   143      */
       
   144     TInt FindEventFromQueue( const TDesC8* aDataToPush );
       
   145 
       
   146     /**
       
   147      * Stops one event in the event queue
       
   148      *
       
   149      * @since S60 5.0
       
   150      * @param aDataToPush Data to push to the stream (not copied)
       
   151      * @return Symbian error code on error, KErrNone otherwise
       
   152      */
       
   153     TInt StopOneEvent( const TDesC8* aDataToPush );
       
   154 
       
   155     /**
       
   156      * Sends queued data in round robin
       
   157      *
       
   158      * @since S60 3.2
       
   159      * @return ETrue if sending started, EFalse if nothing to do
       
   160      */
       
   161     TBool SendQueuedData();
       
   162 
       
   163     /**
       
   164      * Stops sending for write endpoint
       
   165      *
       
   166      * @since S60 3.2
       
   167      * @return Symbian error code on error, KErrNone otherwise
       
   168      */
       
   169     TInt Stop();
       
   170 
       
   171     /**
       
   172      * Stops sending for write endpoint and clears event queue
       
   173      *
       
   174      * @since S60 3.2
       
   175      * @return Symbian error code on error, KErrNone otherwise
       
   176      */
       
   177     TInt StopAndClearQueue();
       
   178 
       
   179     /**
       
   180      * Signals completion status in round robin and clears event queue
       
   181      *
       
   182      * @return Symbian error code on error, KErrNone otherwise
       
   183      * @return None
       
   184      */
       
   185     TInt SignalCompletionAndClearQueue();
       
   186 
       
   187 private:
       
   188 
       
   189     CDunDataPusher( CDunDownstream& aParent,
       
   190                     MDunCompletionReporter* aStreamCallback );
       
   191 
       
   192     void ConstructL();
       
   193 
       
   194     /**
       
   195      * Initializes this class
       
   196      *
       
   197      * @since S60 3.2
       
   198      * @return None
       
   199      */
       
   200     void Initialize();
       
   201 
       
   202     /**
       
   203      * Manages one event's data push
       
   204      *
       
   205      * @since S60 3.2
       
   206      * @return None
       
   207      */
       
   208     TInt ManageOneEvent();
       
   209 
       
   210     /**
       
   211      * Check whether an error code is severe error or not
       
   212      *
       
   213      * @since S60 3.2
       
   214      * @param aError Error code to check for severity
       
   215      * @param aIsError ETrue if error code is error, EFalse if not error
       
   216      * @return ETrue if severe error detected, EFalse if not severe error
       
   217      */
       
   218     TBool ProcessErrorCondition( TInt aError, TBool& aIsError );
       
   219 
       
   220 // from base class CActive
       
   221 
       
   222     /**
       
   223      * From CActive.
       
   224      * Gets called when endpoint data write complete
       
   225      *
       
   226      * @since S60 3.2
       
   227      * @return None
       
   228      */
       
   229     void RunL();
       
   230 
       
   231     /**
       
   232      * From CActive.
       
   233      * Gets called on cancel
       
   234      *
       
   235      * @since S60 3.2
       
   236      * @return None
       
   237      */
       
   238     void DoCancel();
       
   239 
       
   240 private:  // data
       
   241 
       
   242     /**
       
   243      * Parent class owning this friend class (CDunDownstream)
       
   244      */
       
   245     CDunDownstream& iParent;
       
   246 
       
   247     /**
       
   248      * Callback to call when notification via MDunCompletionReporter to be made
       
   249      * Not own.
       
   250      */
       
   251     MDunCompletionReporter* iStreamCallback;
       
   252 
       
   253     /**
       
   254      * Event queue for pushed data requests
       
   255      */
       
   256     RArray<TDunDataPush> iEventQueue;
       
   257 
       
   258     /**
       
   259      * Current state of data push: active or inactive
       
   260      */
       
   261     TDunState iPushState;
       
   262 
       
   263     /**
       
   264      * Index of current event to serve
       
   265      */
       
   266     TInt iEventIndex;
       
   267 
       
   268     /**
       
   269      * RSocket object of local media side
       
   270      * If this is set then iComm is not used
       
   271      * Not own.
       
   272      */
       
   273     RSocket* iSocket;
       
   274 
       
   275     /**
       
   276      * RComm object of local media or network side
       
   277      * If this is set then iSocket is not used
       
   278      * Not own.
       
   279      */
       
   280     RComm* iComm;
       
   281 
       
   282     };
       
   283 
       
   284 #endif  // C_DUNDATAPUSHER_H