localconnectivityservice/dun/plugins/inc/usb/DunUsbPlugin.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:  DUN USB plugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CDUNUSBPLUGIN_H
       
    20 #define C_CDUNUSBPLUGIN_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <usbman.h>
       
    24 #include "DunTransporter.h"
       
    25 #include "DunUsbListen.h"
       
    26 #include "DunUsbConfig.h"
       
    27 #include "DunPlugin.h"
       
    28 
       
    29 /**
       
    30  *  DUN USB plugin's port entity
       
    31  *  This class is used to keep track of N number of USB ports and port
       
    32  *  numbers associated to them (for CDunUsbConfig's purposes).
       
    33  *
       
    34  *  @lib dunusb.lib
       
    35  *  @since S60 v3.2
       
    36  */
       
    37 NONSHARABLE_CLASS( TUsbPortEntity )
       
    38     {
       
    39 
       
    40 public:
       
    41 
       
    42     /**
       
    43      * Port number for USB local media side
       
    44      */
       
    45     TInt iPortNum;
       
    46 
       
    47     /**
       
    48      * Port for USB local media side
       
    49      */
       
    50     RComm iUsbPort;
       
    51 
       
    52     };
       
    53 
       
    54 /**
       
    55  *  DUN USB plugin's main class
       
    56  *  This class creates new transporter channel(s) when configured USB is
       
    57  *  detected by CDunUsbListen class and acts on transporter's state changes.
       
    58  *  Also acts on DUN server's requests.
       
    59  *
       
    60  *  @lib dunusb.lib
       
    61  *  @since S60 v3.2
       
    62  */
       
    63 NONSHARABLE_CLASS( CDunUsbPlugin ) : public CBase,
       
    64                                      public MDunLocalMediaPlugin,
       
    65                                      public MDunListenCallback,
       
    66                                      public MDunBufferCorrection,
       
    67                                      public MDunConnMon,
       
    68                                      public MDunUsbConfig
       
    69     {
       
    70 
       
    71 public:
       
    72 
       
    73     CDunUsbPlugin();
       
    74 
       
    75     /**
       
    76     * Destructor.
       
    77     */
       
    78     virtual ~CDunUsbPlugin();
       
    79 
       
    80 private:
       
    81 
       
    82     /**
       
    83      * State of this plugin
       
    84      *
       
    85      * @since S60 3.2
       
    86      * @return State of plugin
       
    87      */
       
    88     TDunPluginState PluginState();
       
    89 
       
    90     /**
       
    91      * Constructs a listener object for this plugin
       
    92      *
       
    93      * @since S60 3.2
       
    94      * @return None
       
    95      */
       
    96     void ConstructListenerL();
       
    97 
       
    98     /**
       
    99      * Initializes USB by loading LDD
       
   100      *
       
   101      * @since S60 3.2
       
   102      * @return None
       
   103      */
       
   104     void InitUsbL();
       
   105 
       
   106     /**
       
   107      * Initializes all usable USB ports for DUN
       
   108      *
       
   109      * @since S60 3.2
       
   110      * @return Symbian error code on error, KErrNone otherwise
       
   111      */
       
   112     TInt InitPorts();
       
   113 
       
   114     /**
       
   115      * Creates empty usable USB ports that can be used by DUN
       
   116      *
       
   117      * @since S60 3.2
       
   118      * @return Symbian error code on error, KErrNone otherwise
       
   119      */
       
   120     TInt CreateAllPorts();
       
   121 
       
   122     /**
       
   123      * Initializes one USB port for DUN
       
   124      *
       
   125      * @since S60 3.2
       
   126      * @param aEntity Pointer to port entity
       
   127      * @return Symbian error code on error, KErrNone otherwise
       
   128      */
       
   129     TInt InitOnePort( TUsbPortEntity* aEntity );
       
   130 
       
   131     /**
       
   132      * Sets channel for one USB port
       
   133      *
       
   134      * @since S60 3.2
       
   135      * @param aEntity Pointer to port entity
       
   136      * @return None
       
   137      */
       
   138     void SetChannelL( TUsbPortEntity* aEntity );
       
   139 
       
   140     /**
       
   141      * Adds skipped error code to Transporter
       
   142      * The skipped error is added to local media's read and write operations
       
   143      *
       
   144      * @since S60 3.2
       
   145      * @param aError Skipped error code to add
       
   146      * @param aComm RComm object for which to add the error code
       
   147      * @return None
       
   148      */
       
   149     void AddSkippedErrorL( TInt aError, RComm* aComm );
       
   150 
       
   151     /**
       
   152      * Sets new state
       
   153      * New state must be one more than the old state
       
   154      *
       
   155      * @since S60 3.2
       
   156      * @param aPluginState New state to set for a plugin
       
   157      * @return Symbian error code on error, KErrNone otherwise
       
   158      */
       
   159     TInt ReportStateChangeUp( TDunPluginState aPluginState );
       
   160 
       
   161     /**
       
   162      * Sets new state
       
   163      * New state must be one less than the old state
       
   164      *
       
   165      * @since S60 3.2
       
   166      * @param aPluginState New state to set for a plugin
       
   167      * @return Symbian error code on error, KErrNone otherwise
       
   168      */
       
   169     TInt ReportStateChangeDown( TDunPluginState aPluginState );
       
   170 
       
   171     /**
       
   172      * Frees existing channels
       
   173      *
       
   174      * @since S60 3.2
       
   175      * @return Symbian error code on error, KErrNone otherwise
       
   176      */
       
   177     TInt FreeChannels();
       
   178 
       
   179     /**
       
   180      * Uninitializes this plugin
       
   181      *
       
   182      * @since S60 3.2
       
   183      * @return Symbian error code on error, KErrNone otherwise
       
   184      */
       
   185     TInt Uninitialize();
       
   186 
       
   187     /**
       
   188      * Gets port's index and entity by connection ID
       
   189      *
       
   190      * @since S60 3.2
       
   191      * @param aConnId Connection ID of the connection to find
       
   192      * @param aEntity Returned port entity
       
   193      * @return KErrNotFound if entity not found, found index otherwise
       
   194      */
       
   195     TInt GetEntityByConnId( TConnId aConnId, TUsbPortEntity*& aEntity );
       
   196 
       
   197     /**
       
   198      * Gets port's entity by port number
       
   199      *
       
   200      * @since S60 3.2
       
   201      * @param aPortNum Port number of the connection to find
       
   202      * @param aEntity Returned port entity
       
   203      * @return KErrNotFound if entity not found, found index otherwise
       
   204      */
       
   205     TInt GetEntityByPortNumber( TInt aPortNum, TUsbPortEntity*& aEntity );
       
   206 
       
   207     /**
       
   208      * Gets first free port's index and entity
       
   209      *
       
   210      * @since S60 3.2
       
   211      * @param aEntity Returned port entity
       
   212      * @return KErrNotFound if entity not found, found index otherwise
       
   213      */
       
   214     TInt GetFirstFreeEntity( TUsbPortEntity*& aEntity );
       
   215 
       
   216 // from base class MDunLocalMediaPlugin
       
   217 
       
   218     void ConstructL( MDunServerCallback* aServer,
       
   219                      CDunTransporter* aTransporter );
       
   220 
       
   221     /**
       
   222      * From MDunLocalMediaPlugin.
       
   223      * Gets called when server changes a plugin's state
       
   224      *
       
   225      * @since S60 3.2
       
   226      * @param aPluginState New changed state
       
   227      * @return Symbian error code on error, KErrNone otherwise
       
   228      */
       
   229     TInt NotifyServerStateChange( TDunPluginState aPluginState );
       
   230 
       
   231     /**
       
   232      * From MDunLocalMediaPlugin.
       
   233      * Gets called when server needs to know the active connection
       
   234      * (For testing purposes only)
       
   235      *
       
   236      * @since S60 5.0
       
   237      * @return Active connection, NULL otherwise
       
   238      */
       
   239     TConnId ActiveConnection();
       
   240 
       
   241 // from base class MDunListenCallback
       
   242 
       
   243     /**
       
   244      * From MDunListenCallback.
       
   245      * Gets called when new channel must be created
       
   246      *
       
   247      * @since S60 3.2
       
   248      * @param aNoFreeChans ETrue if no free channels, EFalse otherwise
       
   249      * @return Symbian error code on error, KErrNone otherwise
       
   250      */
       
   251     TInt NotifyChannelAllocate( TBool& aNoFreeChans );
       
   252 
       
   253     /**
       
   254      * From MDunListenCallback.
       
   255      * Gets called when an existing channel must be freed
       
   256      *
       
   257      * @since S60 3.2
       
   258      * @return Symbian error code on error, KErrNone otherwise
       
   259      */
       
   260     TInt NotifyChannelFree();
       
   261 
       
   262 // from base class MDunConnMon
       
   263 
       
   264     /**
       
   265      * From MDunConnMon.
       
   266      * Gets called when line status changes or when any type of error is
       
   267      * detected
       
   268      *
       
   269      * @since S60 3.2
       
   270      * @param aConnId Connection ID for callback
       
   271      * @param aConnReason Reason for progress change
       
   272      * @return None
       
   273      */
       
   274     void NotifyProgressChangeL( TConnId aConnId,
       
   275                                 TDunConnectionReason aConnReason );
       
   276 
       
   277 // from base class MDunBufferCorrection
       
   278 
       
   279     /**
       
   280      * Gets called when request to change local media's buffer size
       
   281      *
       
   282      * @since S60 3.2
       
   283      * @param aLength Suggested buffer length that will be used if no
       
   284      *                correction done
       
   285      * @return New (corrected) buffer length
       
   286      */
       
   287     TInt NotifyBufferCorrection( TInt aLength );
       
   288 
       
   289 // from base class MDunUsbConfig
       
   290 
       
   291     /**
       
   292      * Gets called when one or more ACM configurations are added
       
   293      *
       
   294      * @since S60 3.2
       
   295      * @param aIndex Index (also port number) of added ACM configuration
       
   296      * @return Symbian error code on error, KErrNone otherwise
       
   297      */
       
   298     TInt NotifyConfigAddition( TInt aIndex );
       
   299 
       
   300     /**
       
   301      * Gets called when one or more ACM configurations are removed
       
   302      *
       
   303      * @since S60 3.2
       
   304      * @param aIndex Index (also port number) of removed ACM configuration
       
   305      * @return Symbian error code on error, KErrNone otherwise
       
   306      */
       
   307     TInt NotifyConfigRemoval( TInt aIndex );
       
   308 
       
   309 private:  // data
       
   310 
       
   311     /**
       
   312      * Callback to call when notification via MDunServerCallback to be made
       
   313      * Not own.
       
   314      */
       
   315     MDunServerCallback* iServer;
       
   316 
       
   317     /**
       
   318      * Listener for detecting attached USB cable and configured ACM
       
   319      * Notifies this class to create new channel
       
   320      * Own.
       
   321      */
       
   322     CDunUsbListen* iUsbListen;
       
   323 
       
   324     /**
       
   325      * Listener and accessor for detecting USB ACM configuration change
       
   326      * Own.
       
   327      */
       
   328     CDunUsbConfig* iUsbConfig;
       
   329 
       
   330     /**
       
   331      * Communications server used to load ECACM and open USB port(s)
       
   332      * Also used to get port information to calculate number of supported ACMs
       
   333      */
       
   334     RCommServ iCommServer;
       
   335 
       
   336     /**
       
   337      * USB server (USB manager) needed for device state notifications
       
   338      * Device states needed to create transporter channel
       
   339      */
       
   340     RUsb iUsbServer;
       
   341 
       
   342     /**
       
   343      * Array of port(s) for USB local media side
       
   344      */
       
   345     RArray<TUsbPortEntity> iUsbPorts;
       
   346 
       
   347     /**
       
   348      * Transporter to use for network side communication
       
   349      * Not own.
       
   350      */
       
   351     CDunTransporter* iTransporter;
       
   352 
       
   353     /**
       
   354      * Flag to be set on if CDunUsbPlugin is waiting for shutdown.
       
   355      * This flag is used to skip subsequent higher-level error codes after
       
   356      * driver based error occurred.
       
   357      */
       
   358     TBool iShutdown;
       
   359 
       
   360     };
       
   361 
       
   362 #endif  // C_CDUNUSBPLUGIN_H