localconnectivityservice/dun/utils/inc/DunChanMan.h
branchRCL_3
changeset 19 0aa8cc770c8a
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
       
     1 /*
       
     2 * Copyright (c) 2006-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:  RComm channel management related functionality (waiter)
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CDUNCHANMAN_H
       
    20 #define C_CDUNCHANMAN_H
       
    21 
       
    22 #include "DunTransUtils.h"
       
    23 #include "DunTransporter.h"
       
    24 
       
    25 class CDunSignalWaiter;
       
    26 class CDunDataWaiter;
       
    27 
       
    28 /**
       
    29  *  Class for CDunDataWaiter's and CDunSignalWaiter's connection monitoring
       
    30  *  support
       
    31  *  When CDunDataWaiter or CDunSignalWaiter detects activity, data in this
       
    32  *  class is used as helper data to create subsequent calls to
       
    33  *  CDunTransporter::AddConnMonCallbackL
       
    34  *
       
    35  *  @lib dunutils.lib
       
    36  *  @since S60 v3.2
       
    37  */
       
    38 NONSHARABLE_CLASS( TDunConnMonCallback )
       
    39     {
       
    40 
       
    41 public:
       
    42 
       
    43     /**
       
    44      * Callback to call when notification via MDunConnMon to be made
       
    45      * (CDunTransporter::AddConnMonCallbackL, aCallback parameter)
       
    46      * Not own.
       
    47      */
       
    48     MDunConnMon* iCallback;
       
    49 
       
    50     /**
       
    51      * Direction where to add connection monitor
       
    52      * (CDunTransporter::AddConnMonCallbackL, aDirection parameter)
       
    53      */
       
    54     TDunDirection iDirection;
       
    55 
       
    56     };
       
    57 
       
    58 /**
       
    59  *  Class for CDunDataWaiter's and CDunSignalWaiter's connection monitoring
       
    60  *  support
       
    61  *  When CDunConnWaiter or CDunSignalWaiter detects activity, data in this
       
    62  *  class is used as helper data to create subsequent calls to
       
    63  *  CDunTransporter::AddSkippedErrorL
       
    64  *
       
    65  *  @lib dunutils.lib
       
    66  *  @since S60 v3.2
       
    67  */
       
    68 NONSHARABLE_CLASS( TDunSkippedError )
       
    69     {
       
    70 
       
    71 public:
       
    72 
       
    73     /**
       
    74      * Error code of read/write condition that should be skipped
       
    75      * (CDunTransporter::AddSkippedErrorL, aError parameter)
       
    76      */
       
    77     TInt iError;
       
    78 
       
    79     /**
       
    80      * Direction of read/write error condition
       
    81      * (CDunTransporter::AddSkippedErrorL, aDirection parameter)
       
    82      */
       
    83     TDunDirection iDirection;
       
    84 
       
    85     };
       
    86 
       
    87 /**
       
    88  *  Class for CDunDataWaiter's or CDunSignalWaiter's connection monitoring
       
    89  *  support
       
    90  *  When CDunDataWaiter or CDunSignalWaiter detects activity, data in this
       
    91  *  class is used as helper
       
    92  *  data to create subsequent calls to the following APIs
       
    93  *  CDunTransporter::AddConnMonCallbackL
       
    94  *  CDunTransporter::AddSkippedErrorL
       
    95  *
       
    96  *  @lib dunutils.lib
       
    97  *  @since S60 v3.2
       
    98  */
       
    99 NONSHARABLE_CLASS( TDunWaiterData )
       
   100     {
       
   101 
       
   102 public:
       
   103 
       
   104     /**
       
   105      * RComm object of local media side
       
   106      * Not own.
       
   107      */
       
   108     RComm* iComm;
       
   109 
       
   110     /**
       
   111      * Name for the channel
       
   112      */
       
   113     HBufC8* iChannelName;
       
   114 
       
   115     /**
       
   116      * Signal waiter object for a channel
       
   117      * Not own.
       
   118      */
       
   119     CDunSignalWaiter* iSignalWaiter;
       
   120 
       
   121     /**
       
   122      * Data waiter object for a channel
       
   123      * Not own.
       
   124      */
       
   125     CDunDataWaiter* iDataWaiter;
       
   126 
       
   127     /**
       
   128      * Pointer to object implementing buffer correction
       
   129      * Not own.
       
   130      */
       
   131     MDunBufferCorrection* iCorrection;
       
   132 
       
   133     /**
       
   134      * Connection monitor raw data that will be added to TDunChannelData array
       
   135      * after activity detected by iDataWaiter or iSignalWaiter
       
   136      */
       
   137     RArray<TDunConnMonCallback> iConnMons;
       
   138 
       
   139     /**
       
   140      * Skipped error raw data that will be added to TDunChannelData array
       
   141      * after activity detected by iDataWaiter or iSignalWaiter
       
   142      */
       
   143     RArray<TDunSkippedError> iOkErrors;
       
   144 
       
   145     /**
       
   146      * Flag to indicate whether enqueued channel allocation required.
       
   147      * Second option is to use service advertisement API.
       
   148      */
       
   149     TBool iEnqueuedFail;
       
   150 
       
   151     /**
       
   152      * UID of plugin that allocated this channel
       
   153      * Used for making notification via MDunPluginManager callback
       
   154      * Added to TDunChannelData array after activity detected by iDataWaiter
       
   155      */
       
   156     TUid iOwnerUid;
       
   157 
       
   158     };
       
   159 
       
   160 /**
       
   161  *  Notification interface class for creating new channel
       
   162  *  Used by CDunDataWaiter ro CDunSignalWaiter to create new channel when
       
   163  *  activity is detected
       
   164  *
       
   165  *  @lib dunutils.lib
       
   166  *  @since S60 v3.2
       
   167  */
       
   168 NONSHARABLE_CLASS( MDunChannelAllocator )
       
   169     {
       
   170 
       
   171 public:
       
   172 
       
   173     /**
       
   174      * CDunTransporter callback: gets called when waiter wants new channel
       
   175      *
       
   176      * @since S60 3.2
       
   177      * @param aComm Connection where new data exists
       
   178      * @return Symbian error code on error, KErrNone otherwise
       
   179      */
       
   180     virtual TInt NotifyNewChannelRequest( RComm* aComm ) = 0;
       
   181 
       
   182     };
       
   183 
       
   184 /**
       
   185  *  Class for RComm channel management related functionality (waiter)
       
   186  *  activity is detected by CDunDataWaiter or CDunSignalWaiter objects
       
   187  *  Also takes care of waiter object creation.
       
   188  *
       
   189  *  @lib dunutils.lib
       
   190  *  @since S60 v3.2
       
   191  */
       
   192 NONSHARABLE_CLASS( CDunChanMan ) : public CBase,
       
   193                                    public MDunChannelAllocator
       
   194     {
       
   195 
       
   196 public:
       
   197 
       
   198     /**
       
   199      * Two-phased constructor.
       
   200      * @param aParent Parent class owning this friend class (CDunTransporter)
       
   201      * @param aUtility Pointer to common utility class
       
   202      * @param aUtilityAux Pointer to other than CDunTransporter utility class
       
   203      * @param aPluginManager Callback to call when notification via
       
   204      *                       MDunPluginManager to be made
       
   205      * @return Instance of self
       
   206      */
       
   207 	static CDunChanMan* NewL( CDunTransporter& aParent,
       
   208 	                          MDunTransporterUtility* aUtility,
       
   209 	                          MDunTransporterUtilityAux* aUtilityAux,
       
   210 	                          MDunPluginManager* aPluginManager );
       
   211 
       
   212     /**
       
   213     * Destructor.
       
   214     */
       
   215     virtual ~CDunChanMan();
       
   216 
       
   217     /**
       
   218      * Resets data to initial values
       
   219      *
       
   220      * @since S60 3.2
       
   221      * @return None
       
   222      */
       
   223     void ResetData();
       
   224 
       
   225     /**
       
   226      * Number of waiters
       
   227      *
       
   228      * @since S60 3.2
       
   229      * @return Number of waiters
       
   230      */
       
   231     TInt NumberOfWaiters();
       
   232 
       
   233     /**
       
   234      * Gets number of waiters by owner UID
       
   235      *
       
   236      * @since S60 5.0
       
   237      * @param aOwnerUid UID of the channel owner
       
   238      * @return Number of waiters
       
   239      */
       
   240     TInt GetNumberOfWaitersByUid( TUid aOwnerUid );
       
   241 
       
   242     /**
       
   243      * Adds new connection waiter to connection waiter array
       
   244      *
       
   245      * @since S60 3.2
       
   246      * @param aComm Pointer to opened local media RComm ID object
       
   247      * @param aOwnerUid UID of the channel owner
       
   248      * @param aName Name for the channel
       
   249      * @param aEnqueuedFail ETrue if enqueued failure, EFalse otherwise
       
   250      * @param aCorrection Pointer to object implementing buffer correction
       
   251      * @return None
       
   252      */
       
   253     void AddConnWaiterL( RComm* aComm,
       
   254                          TUid aOwnerUid,
       
   255                          const TDesC8& aName,
       
   256                          TBool aEnqueuedFail,
       
   257                          MDunBufferCorrection* aCorrection );
       
   258 
       
   259     /**
       
   260      * Removes existing waiter from connection waiter array
       
   261      *
       
   262      * @since S60 3.2
       
   263      * @param aComm Pointer to opened local media RComm ID object
       
   264      * @return KErrNotFound if waiter not found, KErrNone if removed
       
   265      */
       
   266     TInt RemoveConnWaiter( RComm* aComm );
       
   267 
       
   268     /**
       
   269      * Makes CDunDataWaiter and CDunSignalWaiter ready to detect activity
       
   270      *
       
   271      * @since S60 3.2
       
   272      * @param aComm Pointer to opened local media RComm ID object
       
   273      * @return KErrNotFound if waiter not found, KErrNone if request issued
       
   274      */
       
   275     TInt IssueConnWaiterRequest( RComm* aComm );
       
   276 
       
   277     /**
       
   278      * Stops CDunDataWaiter and CDunSignalWaiter to detect new data
       
   279      *
       
   280      * @since S60 3.2
       
   281      * @param aComm Pointer to opened local media RComm ID object
       
   282      * @return KErrNotFound if waiter not found, KErrNone if stopped
       
   283      */
       
   284     TInt StopConnWaiter( RComm* aComm );
       
   285 
       
   286     /**
       
   287      * Saves waiter's connection monitor callback data
       
   288      *
       
   289      * @since S60 3.2
       
   290      * @param aComm Pointer to opened local media RComm ID object
       
   291      * @param aCallback Pointer to object whose callbacks will be called
       
   292      * @param aDirection Direction of operation to monitor for read/write
       
   293      *                   error
       
   294      * @return Symbian error code on error, KErrNone otherwise
       
   295      */
       
   296     TInt SaveWaiterConnMonCallbackL( RComm* aComm,
       
   297                                      MDunConnMon* aCallback,
       
   298                                      TDunDirection aDirection );
       
   299 
       
   300     /**
       
   301      * Saves waiter's skipped error data
       
   302      *
       
   303      * @since S60 3.2
       
   304      * @param aError Error code to consider as "no error"
       
   305      * @param aComm Pointer to opened local media RComm ID object
       
   306      * @param aDirection One of four data transfer endpoints where to add a
       
   307      *                   skipped error code
       
   308      * @return Symbian error code on error, KErrNone otherwise
       
   309      */
       
   310     TInt SaveWaiterSkippedErrorL( TInt aError,
       
   311                                   RComm* aComm,
       
   312                                   TDunDirection aDirection );
       
   313 
       
   314 private:
       
   315 
       
   316     CDunChanMan( CDunTransporter& aParent,
       
   317                  MDunTransporterUtility* aUtility,
       
   318                  MDunTransporterUtilityAux* aUtilityAux,
       
   319                  MDunPluginManager* aPluginManager );
       
   320 
       
   321     void ConstructL();
       
   322 
       
   323     /**
       
   324      * Initializes this class
       
   325      *
       
   326      * @since S60 3.2
       
   327      * @return None
       
   328      */
       
   329     void Initialize();
       
   330 
       
   331      /**
       
   332       * Fills data for channel created by waiter
       
   333       *
       
   334       * @since S60 3.2
       
   335       * @param aComm Pointer to opened local media RComm ID object
       
   336       * @param aFirstFree Index to first free channel
       
   337       * @return Symbian error code on error, KErrNone otherwise
       
   338       */
       
   339     TInt FillNewWaiterChannelData(RComm* aComm, TInt aFirstFree);
       
   340 
       
   341     /**
       
   342      * Restores saved waiter data to connection data
       
   343      *
       
   344      * @since S60 3.2
       
   345      * @param aWaiterIndex Index to waiter data
       
   346      * @param aChannelIndex Index to connection data
       
   347      * @return Symbian error code on error, KErrNone otherwise
       
   348      */
       
   349     TInt RestoreWaiterData( TInt aWaiterIndex, TInt aChannelIndex );
       
   350 
       
   351     /**
       
   352      * Deletes waiter objects of aIndex:th waiters
       
   353      *
       
   354      * @since S60 3.2
       
   355      * @param aIndex Index of waiters to delete
       
   356      * @param aNewOwnership ETrue if ownership transferred, EFalse otherwise
       
   357      * @return Symbian error code on error, KErrNone otherwise
       
   358      */
       
   359     TInt DeleteWaiters( TInt aIndex, TBool aNewOwnership=EFalse );
       
   360 
       
   361 // from base class MDunChannelAllocator
       
   362 
       
   363     /**
       
   364      * From MDunChannelAllocator.
       
   365      * Notifies when new channel is wanted
       
   366      *
       
   367      * @since S60 3.2
       
   368      * @param aComm Connection where new data exists
       
   369      * @return KErrNone
       
   370      */
       
   371     TInt NotifyNewChannelRequest( RComm* aComm );
       
   372 
       
   373 private:  // data
       
   374 
       
   375     /**
       
   376      * Parent class owning this friend class (CDunTransporter)
       
   377      */
       
   378     CDunTransporter& iParent;
       
   379 
       
   380     /**
       
   381      * Pointer to common utility class
       
   382      * Not own.
       
   383      */
       
   384     MDunTransporterUtility* iUtility;
       
   385 
       
   386     /**
       
   387      * Pointer to other than CDunTransporter utility class
       
   388      * Not own.
       
   389      */
       
   390     MDunTransporterUtilityAux* iUtilityAux;
       
   391 
       
   392     /**
       
   393      * Callback to call when notification via MDunPluginManager to be made
       
   394      * Not own.
       
   395      */
       
   396     MDunPluginManager* iPluginManager;
       
   397 
       
   398     /**
       
   399      * Waiter's data that will be added to iChannelData when waiter detects
       
   400      * read activity. After copying to iChannelData the data will be removed
       
   401      * from this array.
       
   402      */
       
   403     RArray<TDunWaiterData> iWaiterData;
       
   404 
       
   405     };
       
   406 
       
   407 #endif  // C_CDUNCHANMAN_H