localconnectivityservice/dun/plugins/inc/bt/DunBtPlugin.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 Bluetooth plugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CDUNBTPLUGIN_H
       
    20 #define C_CDUNBTPLUGIN_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <es_sock.h>
       
    24 #include "DunTransporter.h"
       
    25 #include "DunPlugin.h"
       
    26 
       
    27 /**
       
    28  *  Cleanup information for AllocateChannelL().
       
    29  *  This data is needed to clean up partially constructed data in
       
    30  *  NotifyChannelAllocate() when a leave occurs in channel creation.
       
    31  *
       
    32  *  @lib dunbt.lib
       
    33  *  @since S60 v5.0
       
    34  */
       
    35 NONSHARABLE_CLASS( TBtCleanupInfo )
       
    36     {
       
    37 
       
    38 public:
       
    39 
       
    40     /**
       
    41      * Flag to indicate whether or not a new entity was created
       
    42      */
       
    43     TBool iNewEntity;
       
    44 
       
    45     /**
       
    46      * Index to the position of the found entity
       
    47      */
       
    48     TInt iEntityIndex;
       
    49 
       
    50     };
       
    51 
       
    52 /**
       
    53  *  DUN BT plugin's port entity
       
    54  *  This class is used to keep track of N number of BT ports and RFCOMM
       
    55  *  channel numbers associated to them.
       
    56  *
       
    57  *  @lib dunbt.lib
       
    58  *  @since S60 v3.2
       
    59  */
       
    60 NONSHARABLE_CLASS( TBtPortEntity )
       
    61     {
       
    62 
       
    63 public:
       
    64 
       
    65     /**
       
    66      * RFCOMM channel number for BT local media side
       
    67      */
       
    68     TInt iChannelNum;
       
    69 
       
    70     /**
       
    71      * Port for BT local media side
       
    72      */
       
    73     RSocket iBTPort;
       
    74 
       
    75     };
       
    76 
       
    77 /**
       
    78  *  DUN Bluetooth plugin's main class
       
    79  *  This class creates new transporter channel when new data is detected by
       
    80  *  CDunBtListen class and acts on transporter's state changes. Also acts on
       
    81  *  DUN server's requests.
       
    82  *
       
    83  *  @lib dunbt.lib
       
    84  *  @since S60 v3.2
       
    85  */
       
    86 NONSHARABLE_CLASS( CDunBtPlugin ) : public CBase,
       
    87                                     public MDunLocalMediaPlugin,
       
    88                                     public MDunListenCallback,
       
    89                                     public MDunConnMon
       
    90     {
       
    91 
       
    92 public:
       
    93 
       
    94     CDunBtPlugin();
       
    95 
       
    96     /**
       
    97     * Destructor.
       
    98     */
       
    99     virtual ~CDunBtPlugin();
       
   100 
       
   101 private:
       
   102 
       
   103     /**
       
   104      * State of this plugin
       
   105      *
       
   106      * @since S60 3.2
       
   107      * @return State of plugin
       
   108      */
       
   109     TDunPluginState PluginState();
       
   110 
       
   111     /**
       
   112      * Constructs a listener object for this plugin
       
   113      *
       
   114      * @since S60 3.2
       
   115      * @return None
       
   116      */
       
   117     void ConstructListenerL();
       
   118 
       
   119     /**
       
   120      * Sets new state
       
   121      * New state must be one more than the old state
       
   122      *
       
   123      * @since S60 3.2
       
   124      * @param aPluginState New state to set for a plugin
       
   125      * @return Symbian error code on error, KErrNone otherwise
       
   126      */
       
   127     TInt ReportStateChangeUp( TDunPluginState aPluginState );
       
   128 
       
   129     /**
       
   130      * Sets new state
       
   131      * New state must be one less than the old state
       
   132      *
       
   133      * @since S60 3.2
       
   134      * @param aPluginState New state to set for a plugin
       
   135      * @return Symbian error code on error, KErrNone otherwise
       
   136      */
       
   137     TInt ReportStateChangeDown( TDunPluginState aPluginState );
       
   138 
       
   139     /**
       
   140      * Allocates a free channel
       
   141      *
       
   142      * @since S60 3.2
       
   143      * @param aNoFreeChans ETrue if no free channels, EFalse otherwise
       
   144      * @param aCleanupInfo Cleanup information
       
   145      * @return None
       
   146      */
       
   147     void AllocateChannelL( TBool& aNoFreeChans, TBtCleanupInfo& aCleanupInfo );
       
   148 
       
   149     /**
       
   150      * Frees existing channels
       
   151      *
       
   152      * @since S60 3.2
       
   153      * @return Symbian error code on error, KErrNone otherwise
       
   154      */
       
   155     TInt FreeChannels();
       
   156 
       
   157     /**
       
   158      * Uninitializes this plugin
       
   159      *
       
   160      * @since S60 3.2
       
   161      * @return Symbian error code on error, KErrNone otherwise
       
   162      */
       
   163     TInt Uninitialize();
       
   164 
       
   165     /**
       
   166      * Gets port's index and entity by connection ID
       
   167      *
       
   168      * @since S60 3.2
       
   169      * @param aConnId Connection ID of the connection to find
       
   170      * @param aEntity Returned port entity
       
   171      * @return KErrNotFound if entity not found, found index otherwise
       
   172      */
       
   173     TInt GetPortByConnId( TConnId aConnId, TBtPortEntity*& aEntity );
       
   174 
       
   175     /**
       
   176      * Gets first free port's index and entity
       
   177      *
       
   178      * @since S60 3.2
       
   179      * @param aEntity Returned port entity
       
   180      * @return KErrNotFound if entity not found, found index otherwise
       
   181      */
       
   182     TInt GetFirstFreePort( TBtPortEntity*& aEntity );
       
   183 
       
   184     /**
       
   185      * Sets modem's MSC (Modem Status Command)
       
   186      *
       
   187      * @since S60 3.2
       
   188      * @param aEntity Port entity for which to change signal
       
   189      * @param aSignal Signal to set to high or low
       
   190      * @param aSignalOn ETrue if signal wanted high, otherwise low
       
   191      * @return Symbian error code on error, KErrNone otherwise
       
   192      */
       
   193     TInt SetRFCOMMStatusCommand( TBtPortEntity& aEntity,
       
   194                                  TUint8 aSignal,
       
   195                                  TBool aSignalOn );
       
   196 
       
   197     /**
       
   198      * Manages advertiser for channel free operation
       
   199      *
       
   200      * @since S60 5.0
       
   201      * @return None
       
   202      */
       
   203     void ManageAdvertiserFreeOperationL();
       
   204 
       
   205     /**
       
   206      * Cleans partial created channel data based on TATExtCleanupInfo
       
   207      *
       
   208      * @since S60 5.0
       
   209      * @param aCleanupInfo Cleanup information
       
   210      * @return None
       
   211      */
       
   212     void CleanPartialChanneldata( TBtCleanupInfo& aCleanupInfo );
       
   213     
       
   214 // from base class MDunLocalMediaPlugin
       
   215 
       
   216     void ConstructL( MDunServerCallback* aServer,
       
   217                      CDunTransporter* aTransporter );
       
   218 
       
   219     /**
       
   220      * From MDunLocalMediaPlugin.
       
   221      * Gets called when server changes a plugin's state
       
   222      *
       
   223      * @since S60 3.2
       
   224      * @param aPluginState New changed state
       
   225      * @return Symbian error code on error, KErrNone otherwise
       
   226      */
       
   227     TInt NotifyServerStateChange( TDunPluginState aPluginState );
       
   228 
       
   229     /**
       
   230      * From MDunLocalMediaPlugin.
       
   231      * Gets called when server needs to know the active connection
       
   232      * (For testing purposes only)
       
   233      *
       
   234      * @since S60 5.0
       
   235      * @return Active connection, NULL otherwise
       
   236      */
       
   237     TConnId ActiveConnection();
       
   238 
       
   239 // from base class MDunListenCallback
       
   240 
       
   241     /**
       
   242      * From MDunListenCallback.
       
   243      * Gets called when new channel must be created
       
   244      *
       
   245      * @since S60 3.2
       
   246      * @param aNoFreeChans ETrue if no free channels, EFalse otherwise
       
   247      * @return Symbian error code on error, KErrNone otherwise
       
   248      */
       
   249     TInt NotifyChannelAllocate( TBool& aNoFreeChans );
       
   250 
       
   251     /**
       
   252      * From MDunListenCallback.
       
   253      * Gets called when an existing channel must be freed
       
   254      *
       
   255      * @since S60 3.2
       
   256      * @return Symbian error code on error, KErrNone otherwise
       
   257      */
       
   258     TInt NotifyChannelFree();
       
   259 
       
   260 // from base class MDunConnMon
       
   261 
       
   262     /**
       
   263      * From MDunConnMon.
       
   264      * Gets called when line status changes or when any type of error is
       
   265      * detected
       
   266      *
       
   267      * @since S60 3.2
       
   268      * @param aConnId Connection ID for callback
       
   269      * @param aConnReason Reason for progress change
       
   270      * @return None
       
   271      */
       
   272     void NotifyProgressChangeL( TConnId aConnId,
       
   273                                 TDunConnectionReason aConnReason );
       
   274 
       
   275 private:  // data
       
   276 
       
   277     /**
       
   278      * Callback to call when notification via MDunServerCallback to be made
       
   279      * Not own.
       
   280      */
       
   281     MDunServerCallback* iServer;
       
   282 
       
   283     /**
       
   284      * Listener for detecting new data in RFComm channel
       
   285      * Notifies this class about new data
       
   286      * Own.
       
   287      */
       
   288     CDunBtListen* iBTListen;
       
   289 
       
   290     /**
       
   291      * Data socket entity for actual data transfer
       
   292      * This will be valid after CDunBtListen reacts to new data in
       
   293      * listener socket
       
   294      */
       
   295     TBtPortEntity iEntity;
       
   296 
       
   297     /**
       
   298      * Array of RSocket port(s) entities for BT local media side
       
   299      */
       
   300     RArray<TBtPortEntity> iBTPorts;
       
   301 
       
   302     /**
       
   303      * Transporter to use for network side communication
       
   304      * Not own.
       
   305      */
       
   306     CDunTransporter* iTransporter;
       
   307 
       
   308     };
       
   309 
       
   310 #endif  // C_CDUNBTPLUGIN_H