localconnectivityservice/dun/utils/inc/DunTransUtils.h
branchRCL_3
changeset 39 4096754ee773
parent 38 3dcb815346df
child 40 52a167391590
equal deleted inserted replaced
38:3dcb815346df 39:4096754ee773
     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:  Utility class for other CDunTransporter classes
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CDUNTRANSUTILS_H
       
    20 #define C_CDUNTRANSUTILS_H
       
    21 
       
    22 #include "DunTransporter.h"
       
    23 
       
    24 /**
       
    25  *  Notification interface class for managing channel's activity
       
    26  *  This class is needed to update KPSUidDialupConnStatus pub&sub key
       
    27  *
       
    28  *  @lib dunutils.lib
       
    29  *  @since S60 v3.2
       
    30  */
       
    31 NONSHARABLE_CLASS( MDunActivityManager )
       
    32     {
       
    33 
       
    34 public:
       
    35 
       
    36     /**
       
    37      * CDunTransporter callback: gets called when activity is detected on a
       
    38      * channel
       
    39      *
       
    40      * @since S60 3.2
       
    41      * @return Symbian error code on error, KErrNone otherwise
       
    42      */
       
    43     virtual TInt NotifyChannelActivity() = 0;
       
    44 
       
    45     /**
       
    46      * CDunTransporter callback: gets called when inactivity is detected on a
       
    47      * channel
       
    48      *
       
    49      * @since S60 3.2
       
    50      * @return KErrGeneral if mismatch in channel activity, KErrNone otherwise
       
    51      */
       
    52     virtual TInt NotifyChannelInactivity() = 0;
       
    53 
       
    54     };
       
    55 
       
    56 /**
       
    57  *  Utility accessor class for CDunTransporter class itself
       
    58  *  Shares basic functionality of CDunTransporter by simplifying it
       
    59  *
       
    60  *  @lib dunutils.lib
       
    61  *  @since S60 v3.2
       
    62  */
       
    63 NONSHARABLE_CLASS( MDunTransporterUtility )
       
    64     {
       
    65 
       
    66 public:
       
    67 
       
    68     /**
       
    69      * Initializes first free channel
       
    70      *
       
    71      * @since S60 3.2
       
    72      * @param aLocalIdNew Identifier of the new local endpoint
       
    73      * @return Symbian error code on error, found index otherwise
       
    74      */
       
    75     virtual TInt InitializeFirstFreeChannel( TConnId aLocalIdNew ) = 0;
       
    76 
       
    77     /**
       
    78      * Allocates a channel by creating and setting local media independent
       
    79      * objects
       
    80      * This is a common method used by exported local media dependent methods
       
    81      *
       
    82      * @since S60 3.2
       
    83      * @param aBufferLength Buffer length selected for this channel
       
    84      * @param aFirstFree Index to first free channel data
       
    85      * @param aCorrection Pointer to object implementing buffer correction
       
    86      * @return Symbian error code on error, KErrNone otherwise
       
    87      */
       
    88     virtual void DoAllocateChannelL(
       
    89         RComm* aComm,
       
    90         TInt& aBufferLength,
       
    91         TInt aFirstFree,
       
    92         MDunBufferCorrection* aCorrection ) = 0;
       
    93 
       
    94     /**
       
    95      * Adds connection monitor callback for either local media or network side
       
    96      * by connection ID
       
    97      * Error will be added to aIndex:th endpoint
       
    98      *
       
    99      * @since S60 3.2
       
   100      * @param aIndex Index where to add new connection monitor callback
       
   101      * @param aCallback Pointer to object whose callbacks will be called
       
   102      * @param aDirection Direction of operation to monitor for read/write error
       
   103      * @param aSignal Receive also signal change if ETrue
       
   104      * @return Symbian error code on error, KErrNone otherwise
       
   105      */
       
   106     virtual TInt DoAddConnMonCallback( TInt aIndex,
       
   107                                        MDunConnMon* aCallback,
       
   108                                        TDunDirection aDirection,
       
   109                                        TBool aSignal ) = 0;
       
   110 
       
   111     /**
       
   112      * Adds error to consider as no error condition when doing any of the four
       
   113      * endpoint's read/writer operation
       
   114      * Error will be added to aIndex:th endpoint
       
   115      *
       
   116      * @since S60 3.2
       
   117      * @param aIndex Index where to add new "no error" code
       
   118      * @param aError Error code to consider as "no error"
       
   119      * @param aDirection One of four data transfer endpoints where to add a
       
   120      *                   skipped error code
       
   121      * @return Symbian error code on error, KErrNone otherwise
       
   122      */
       
   123     virtual TInt DoAddSkippedError( TInt aIndex,
       
   124                                     TInt aError,
       
   125                                     TDunDirection aDirection ) = 0;
       
   126 
       
   127     /**
       
   128      * Issues transfers requests for aIndex:th transfer objects
       
   129      *
       
   130      * @since S60 3.2
       
   131      * @param aIndex Index to transfer objects that will be activated
       
   132      * @return Symbian error code on error, KErrNone otherwise
       
   133      */
       
   134     virtual TInt DoIssueTransferRequests( TInt aIndex ) = 0;
       
   135 
       
   136     /**
       
   137      * Stops transfers for aIndex:th transfer objects
       
   138      *
       
   139      * @since S60 3.2
       
   140      * @param aIndex Index to transfer objects that will be stopped
       
   141      * @return Symbian error code on error, KErrNone otherwise
       
   142      */
       
   143     virtual TInt DoStopTransfers( TInt aIndex ) = 0;
       
   144 
       
   145     /**
       
   146      * Free aIndex:th channel's objects
       
   147      *
       
   148      * @since S60 3.2
       
   149      * @param aIndex Index of channel to free
       
   150      * @return Symbian error code on error, KErrNone otherwise
       
   151      */
       
   152     virtual TInt DoFreeChannel( TInt aIndex ) = 0;
       
   153 
       
   154     };
       
   155 
       
   156 /**
       
   157  *  Utility accessor class for other than CDunTransporter classes
       
   158  *  Basically a collection of miscellaneous helper methods
       
   159  *
       
   160  *  @lib dunutils.lib
       
   161  *  @since S60 v3.2
       
   162  */
       
   163 NONSHARABLE_CLASS( MDunTransporterUtilityAux )
       
   164     {
       
   165 
       
   166 public:
       
   167 
       
   168     /**
       
   169      * Gets local ID counterpart of a network ID
       
   170      *
       
   171      * @since S60 3.2
       
   172      * @param aComm Network ID to search for
       
   173      * @return Null if ID not found, otherwise found ID
       
   174      */
       
   175     virtual TConnId GetLocalId( RComm* aComm ) = 0;
       
   176 
       
   177     /**
       
   178      * Notifies when serious read/write error is detected on a connection
       
   179      *
       
   180      * @since S60 3.2
       
   181      * @param aComm Non-null if error on RComm
       
   182      * @param aSocket Non-null if error on RSocket
       
   183      * @param aConnReason Reason of connection error
       
   184      * @param aCallbacks Callbacks to notify on connections error
       
   185      * @return Symbian error code on error, KErrNone otherwise
       
   186      */
       
   187     virtual TInt DoNotifyConnectionNotOk(
       
   188         RComm* aComm,
       
   189         RSocket* aSocket,
       
   190         TDunConnectionReason& aConnReason,
       
   191         RPointerArray<MDunConnMon>& aCallbacks) = 0;
       
   192 
       
   193     };
       
   194 
       
   195 /**
       
   196  *  Utility class for other CDunTransporter classes
       
   197  *  This class implements basic functionality that is shared by different
       
   198  *  CDunTransporter classes, also for simplifying CDunTransporter itself
       
   199  *
       
   200  *  @lib dunutils.lib
       
   201  *  @since S60 v3.2
       
   202  */
       
   203 NONSHARABLE_CLASS( CDunTransUtils ) : public CBase,
       
   204                                       public MDunActivityManager,
       
   205                                       public MDunTransporterUtility,
       
   206                                       public MDunTransporterUtilityAux
       
   207     {
       
   208 
       
   209 public:
       
   210 
       
   211     /**
       
   212      * Two-phased constructor.
       
   213      * @param aParent Parent class owning this friend class (CDunTransporter)
       
   214      * @param aPluginManager Callback to call when notification via
       
   215      *                       MDunPluginManager to be made
       
   216      * @return Instance of self
       
   217      */
       
   218 	static CDunTransUtils* NewL( CDunTransporter& aParent,
       
   219 	                             MDunPluginManager* aPluginManager );
       
   220 
       
   221     /**
       
   222     * Destructor.
       
   223     */
       
   224     virtual ~CDunTransUtils();
       
   225 
       
   226 private:
       
   227 
       
   228     CDunTransUtils( CDunTransporter& aParent,
       
   229                     MDunPluginManager* aPluginManager );
       
   230 
       
   231     void ConstructL();
       
   232 
       
   233     /**
       
   234      * Manages service advertisement status changes
       
   235      *
       
   236      * @since S60 5.0
       
   237      * @param aAdvertise New advertisement status
       
   238      * @param aCreation ETrue if channel creation
       
   239      *                  EFalse if channel free
       
   240      * @return None
       
   241      */
       
   242     void ManageAdvertisementStatusChange( TBool aAdvertise,
       
   243                                           TBool aCreation=EFalse );
       
   244 
       
   245     /**
       
   246      * Creates empty channel data
       
   247      *
       
   248      * @since S60 3.2
       
   249      * @param aChannel Channel data to set empty
       
   250      * @return None
       
   251      */
       
   252     void CreateEmptyChannelData( TDunChannelData& aChannel );
       
   253 
       
   254     /**
       
   255      * Creates new buffer if source buffer defined, otherwise already existing
       
   256      * buffer will be used
       
   257      *
       
   258      * @since S60 3.2
       
   259      * @param aSrcBuffer Source buffer
       
   260      * @param aSrcPtr Pointer to source buffer
       
   261      * @param aDstBuffer Destination buffer
       
   262      * @param aDstPtr Pointer to destination buffer
       
   263      * @param aItemsInCs Items in cleanup stack, will be incremented if
       
   264      *                   necessary
       
   265      * @return None
       
   266      */
       
   267     void DoCreateBufferLC( TUint8* aSrcBuffer,
       
   268                            TPtr8* aSrcPtr,
       
   269                            TUint8*& aDstBuffer,
       
   270                            TPtr8*& aDstPtr,
       
   271                            TInt aBufferLength,
       
   272                            TInt& aItemsInCs );
       
   273 
       
   274     /**
       
   275      * Creates new signal copy object if source defined, otherwise
       
   276      * already existing will be used
       
   277      *
       
   278      * @since S60 3.2
       
   279      * @param aSrcSignalCopy Source signal copy object
       
   280      * @param aDstSignalCopy Destination signal copy object
       
   281      * @param aItemsInCs Items in cleanup stack, will be incremented if
       
   282      *                   necessary
       
   283      * @return None
       
   284      */
       
   285     void DoCreateSignalCopyLC( CDunSignalCopy* aSrcSignalCopy,
       
   286                                CDunSignalCopy*& aDstSignalCopy,
       
   287                                TInt& aItemsInCs );
       
   288 
       
   289     /**
       
   290      * Creates new signal notify object if source defined, otherwise
       
   291      * already existing will be used
       
   292      *
       
   293      * @since S60 3.2
       
   294      * @param aSrcSignalNotify Source signal notify object
       
   295      * @param aDstSignalNotify Destination signal notify object
       
   296      * @param aItemsInCs Items in cleanup stack, will be incremented if
       
   297      *                   necessary
       
   298      * @return None
       
   299      */
       
   300     void DoCreateSignalNotifyLC( CDunSignalNotify* aSrcSignalNotify,
       
   301                                  CDunSignalNotify*& aDstSignalNotify,
       
   302                                  TInt& aItemsInCs );
       
   303 
       
   304     /**
       
   305      * Creates transfer objects for reader and writer if sources defined,
       
   306      * otherwise already existing ones will be used
       
   307      *
       
   308      * @since S60 3.2
       
   309      * @param aSrcReader Source reader object
       
   310      * @param aDstReader Destination reader object
       
   311      * @param aItemsInCs Items in cleanup stack, will be incremented if
       
   312      *                   necessary
       
   313      * @return None
       
   314      */
       
   315     void DoCreateUpTransferObjectL( CDunUpstream* aSrcReader,
       
   316                                     CDunUpstream*& aDstReader,
       
   317                                     TInt& aItemsInCs );
       
   318 
       
   319     /**
       
   320      * Creates transfer objects for reader and writer if sources defined,
       
   321      * otherwise already existing ones will be used
       
   322      *
       
   323      * @since S60 3.2
       
   324      * @param aSrcReader Source reader object
       
   325      * @param aDstReader Destination reader object
       
   326      * @param aItemsInCs Items in cleanup stack, will be incremented if
       
   327      *                   necessary
       
   328      * @return None
       
   329      */
       
   330     void DoCreateDownTransferObjectL( CDunDownstream* aSrcReader,
       
   331                                       CDunDownstream*& aDstReader,
       
   332                                       TInt& aItemsInCs );
       
   333 
       
   334     /**
       
   335      * Resets/frees network data of aIndex:th channel
       
   336      *
       
   337      * @since S60 3.2
       
   338      * @param aIndex Index of channel to reset/free
       
   339      * @return Symbian error code on error, KErrNone otherwise
       
   340      */
       
   341     TInt DeleteOneNetworkData( TInt aIndex );
       
   342 
       
   343     /**
       
   344      * Deletes local data of aIndex:th channel
       
   345      *
       
   346      * @since S60 3.2
       
   347      * @param aIndex Index of channel to delete
       
   348      * @return Symbian error code on error, KErrNone otherwise
       
   349      */
       
   350     TInt DeleteOneLocalData( TInt aIndex );
       
   351 
       
   352     /**
       
   353      * Deletes buffering objects of aIndex:th channel
       
   354      *
       
   355      * @since S60 3.2
       
   356      * @param aIndex Index of channel to delete
       
   357      * @return Symbian error code on error, KErrNone otherwise
       
   358      */
       
   359     TInt DeleteBuffering( TInt aIndex );
       
   360 
       
   361 // from base class MDunTransporterUtility
       
   362 
       
   363     /**
       
   364      * From MDunTransporterUtility.
       
   365      * Initializes first free channel
       
   366      *
       
   367      * @since S60 3.2
       
   368      * @param aLocalIdNew Identifier of the new local endpoint
       
   369      * @return Symbian error code on error, found index otherwise
       
   370      */
       
   371     TInt InitializeFirstFreeChannel( TConnId aLocalIdNew );
       
   372 
       
   373     /**
       
   374      * From MDunTransporterUtility.
       
   375      * Allocates a channel by creating and setting local media independent
       
   376      * objects
       
   377      * This is a common method used by exported local media dependent methods
       
   378      *
       
   379      * @since S60 3.2
       
   380      * @param aBufferLength Buffer length selected for this channel
       
   381      * @param aFirstFree Index to first free channel data
       
   382      * @param aCorrection Pointer to object implementing buffer correction
       
   383      * @return Symbian error code on error, KErrNone otherwise
       
   384      */
       
   385     void DoAllocateChannelL( RComm* aComm,
       
   386                              TInt& aBufferLength,
       
   387                              TInt aFirstFree,
       
   388                              MDunBufferCorrection* aCorrection );
       
   389 
       
   390     /**
       
   391      * From MDunTransporterUtility.
       
   392      * Adds connection monitor callback for either local media or network side
       
   393      * by connection ID
       
   394      * Connection monitor will be added to aIndex:th endpoint
       
   395      *
       
   396      * @since S60 3.2
       
   397      * @param aIndex Index where to add new connection monitor callback
       
   398      * @param aCallback Pointer to object whose callbacks will be called
       
   399      * @param aDirection Direction of operation to monitor for read/write error
       
   400      * @param aSignal Receive also signal change if ETrue
       
   401      * @return Symbian error code on error, KErrNone otherwise
       
   402      */
       
   403     TInt DoAddConnMonCallback( TInt aIndex,
       
   404                                MDunConnMon* aCallback,
       
   405                                TDunDirection aDirection,
       
   406                                TBool aSignal );
       
   407 
       
   408     /**
       
   409      * From MDunTransporterUtility.
       
   410      * Adds error to consider as no error condition when doing any of the four
       
   411      * endpoint's read/writer operation
       
   412      * Error will be added to aIndex:th endpoint
       
   413      *
       
   414      * @since S60 3.2
       
   415      * @param aIndex Index where to add new "no error" code
       
   416      * @param aError Error code to consider as "no error"
       
   417      * @param aDirection One of four data transfer endpoints where to add a
       
   418      *                   skipped error code
       
   419      * @return Symbian error code on error, KErrNone otherwise
       
   420      */
       
   421     TInt DoAddSkippedError( TInt aIndex,
       
   422                             TInt aError,
       
   423                             TDunDirection aDirection );
       
   424 
       
   425     /**
       
   426      * From MDunTransporterUtility.
       
   427      * Issues transfers requests for aIndex:th transfer objects
       
   428      *
       
   429      * @since S60 3.2
       
   430      * @param aIndex Index to transfer objects that will be activated
       
   431      * @return Symbian error code on error, KErrNone otherwise
       
   432      */
       
   433     TInt DoIssueTransferRequests( TInt aIndex );
       
   434 
       
   435     /**
       
   436      * From MDunTransporterUtility.
       
   437      * Stops transfers for aIndex:th transfer objects
       
   438      *
       
   439      * @since S60 3.2
       
   440      * @param aIndex Index to transfer objects that will be stopped
       
   441      * @return Symbian error code on error, KErrNone otherwise
       
   442      */
       
   443     TInt DoStopTransfers( TInt aIndex );
       
   444 
       
   445     /**
       
   446      * From MDunTransporterUtility.
       
   447      * Free aIndex:th channel's objects
       
   448      *
       
   449      * @since S60 3.2
       
   450      * @param aIndex Index of channel to free
       
   451      * @return Symbian error code on error, KErrNone otherwise
       
   452      */
       
   453     TInt DoFreeChannel( TInt aIndex );
       
   454 
       
   455 // from base class MDunTransporterUtilityAux
       
   456 
       
   457     /**
       
   458      * From MDunTransporterUtilityAux.
       
   459      * Gets local ID counterpart of a network ID
       
   460      *
       
   461      * @since S60 3.2
       
   462      * @param aComm Network ID to search for
       
   463      * @return Null if ID not found, otherwise found ID
       
   464      */
       
   465     TConnId GetLocalId( RComm* aComm );
       
   466 
       
   467     /**
       
   468      * From MDunTransporterUtilityAux.
       
   469      * Notifies when serious read/write error is detected on a connection
       
   470      *
       
   471      * @since S60 3.2
       
   472      * @param aComm Non-null if error on RComm
       
   473      * @param aSocket Non-null if error on RSocket
       
   474      * @param aConnReason Reason of connection error
       
   475      * @param aCallbacks Callbacks to notify on connections error
       
   476      * @return Symbian error code on error, KErrNone otherwise
       
   477      */
       
   478     TInt DoNotifyConnectionNotOk(
       
   479         RComm* aComm,
       
   480         RSocket* aSocket,
       
   481         TDunConnectionReason& aConnReason,
       
   482         RPointerArray<MDunConnMon>& aCallbacks);
       
   483 
       
   484 // from base class MDunActivityManager
       
   485 
       
   486     /**
       
   487      * From MDunActivityManager.
       
   488      * Notifies about activity on a channel
       
   489      *
       
   490      * @since S60 3.2
       
   491      * @return Symbian error code on error, KErrNone otherwise
       
   492      */
       
   493     TInt NotifyChannelActivity();
       
   494 
       
   495     /**
       
   496      * From MDunActivityManager.
       
   497      * Notifies about inactivity on a channel
       
   498      *
       
   499      * @since S60 3.2
       
   500      * @return Symbian error code on error, KErrNone otherwise
       
   501      */
       
   502     TInt NotifyChannelInactivity();
       
   503 
       
   504 private:  // data
       
   505 
       
   506     /**
       
   507      * Parent class owning this friend class (CDunTransporter)
       
   508      */
       
   509     CDunTransporter& iParent;
       
   510 
       
   511     /**
       
   512      * Array of abstractions of each "channel" (from parent iParent)
       
   513      * One TDunChannelData entry contains objects needed for one channel
       
   514      */
       
   515     RArray<TDunChannelData>& iChannelData;
       
   516 
       
   517     /**
       
   518      * Array of service advertisement data for each plugin (from parent iParent)
       
   519      * One TDunServAdvData entry contains objects needed for one plugin
       
   520      */
       
   521     RArray<TDunServAdvData>& iServAdvData;
       
   522 
       
   523     /**
       
   524      * Callback to call when notification via MDunPluginManager to be made
       
   525      * Not own.
       
   526      */
       
   527     MDunPluginManager* iPluginManager;
       
   528 
       
   529     };
       
   530 
       
   531 #endif  // C_CDUNTRANSUTILS_H