localconnectivityservice/dun/plugins/inc/bt/DunBtListen.h
branchRCL_3
changeset 20 4a793f564d72
parent 19 0aa8cc770c8a
child 21 74aa6861c87d
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
     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's listener
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CDUNBTLISTEN_H
       
    20 #define C_CDUNBTLISTEN_H
       
    21 
       
    22 #include <btengdiscovery.h>
       
    23 #include "DunPlugin.h"
       
    24 #include "DunTransporter.h"
       
    25 
       
    26 class TBtPortEntity;
       
    27 
       
    28 enum TBtListenState
       
    29     {
       
    30     EBtListenStateIdle,
       
    31     EBtListenStateListening
       
    32     };
       
    33 
       
    34 /**
       
    35  *  DUN Bluetooth plugin's listener class
       
    36  *  This class starts listening on a created BT RFComm channel and notifies
       
    37  *  parent (CDunBtPlugin) when new connection is detected. Also registers and
       
    38  *  unregisters DUN SDP record.
       
    39  *
       
    40  *  @lib dunbt.lib
       
    41  *  @since S60 v3.2
       
    42  */
       
    43 NONSHARABLE_CLASS( CDunBtListen ) : public CActive,
       
    44                                     public MDunServAdvMon
       
    45     {
       
    46 
       
    47 public:
       
    48 
       
    49     /**
       
    50      * Two-phased constructor.
       
    51      * @param aServer Server
       
    52      * @param aParent Callback interface to parent
       
    53      * @param aTransporter Transporter
       
    54      * @param aEntity Data socket entity
       
    55      * @return Instance of self
       
    56      */
       
    57     static CDunBtListen* NewL( MDunServerCallback* aServer,
       
    58                                MDunListenCallback* aParent,
       
    59                                CDunTransporter* aTransporter,
       
    60                                TBtPortEntity& aEntity );
       
    61 
       
    62     /**
       
    63     * Destructor.
       
    64     */
       
    65     virtual ~CDunBtListen();
       
    66 
       
    67     /**
       
    68      * Resets data to initial values
       
    69      *
       
    70      * @since S60 3.2
       
    71      * @return None
       
    72      */
       
    73     void ResetData();
       
    74 
       
    75     /**
       
    76      * Registers DUN and starts to listen.
       
    77      * Registers itself to SDP and BT manager, opens a socket
       
    78      * and starts to listen it.
       
    79      *
       
    80      * @since S60 3.2
       
    81      * @return None
       
    82      */
       
    83     void IssueRequestL();
       
    84 
       
    85     /**
       
    86      * Stops listening
       
    87      *
       
    88      * @since S60 3.2
       
    89      * @return Symbian error code on error, KErrNone otherwise
       
    90      */
       
    91     TInt Stop();
       
    92 
       
    93 private:
       
    94 
       
    95     CDunBtListen( MDunServerCallback* aServer,
       
    96                   MDunListenCallback* aParent,
       
    97                   CDunTransporter* aTransporter,
       
    98                   TBtPortEntity& aEntity );
       
    99 
       
   100     void ConstructL();
       
   101 
       
   102     /**
       
   103      * Initializes this class
       
   104      *
       
   105      * @since S60 3.2
       
   106      * @return None
       
   107      */
       
   108     void Initialize();
       
   109 
       
   110     /**
       
   111      * Starts dialup service advertisement
       
   112      *
       
   113      * @since S60 3.2
       
   114      * @param aInUse ETrue is returned if all RFCOMM channels in use.
       
   115      * @return Symbian error code on error, KErrNone otherwise
       
   116      */
       
   117     TInt StartServiceAdvertisement( TBool& aInUse );
       
   118 
       
   119     /**
       
   120      * Stops dialup service advertisement
       
   121      *
       
   122      * @since S60 3.2
       
   123      * @return Symbian error code on error, KErrNone otherwise
       
   124      */
       
   125     TInt StopServiceAdvertisement();
       
   126 
       
   127     /**
       
   128      * Method which reserves local RFCOMM channel (from possible channels 1-30)
       
   129      * and returns it to client.
       
   130      *
       
   131      * @since S60 3.2
       
   132      * @param aSocketServer Handle to connected socket server.
       
   133      * @param aListenSocket Socket which is initiated for listening.
       
   134      * @param aChannelNum RFCOMM channel which is reserved for listening.
       
   135      * @param aInUse ETrue is returned if all RFCOMM channels in use.
       
   136      * @return KErrNone if OK, else value indicating error situation.
       
   137      */
       
   138     TInt ReserveLocalChannel( RSocketServ& aSocketServ,
       
   139                               RSocket& aListenSocket,
       
   140                               TUint& aChannelNum,
       
   141                               TBool& aInUse );
       
   142 
       
   143     /**
       
   144      * Tries to bind to a fixed port and if that fails with
       
   145      * KRfcommPassiveAutoBind. This is for spec breaking solutions like the
       
   146      * OSX Leopard.
       
   147      *
       
   148      * @since S60 5.0
       
   149      * @param aListenSocket Listen socket for Bind()
       
   150      * @param aSockAddr Address for the socket
       
   151      *                 (must be set for KRfcommPassiveAutoBind)
       
   152      * @return Symbian error code on error, KErrNone otherwise
       
   153      */
       
   154     TInt DoExtendedBind( RSocket& aListenSocket, TRfcommSockAddr& aSockAddr );
       
   155 
       
   156 // from base class CActive
       
   157 
       
   158     /**
       
   159      * From CActive.
       
   160      * Called when a service is requested via BT.
       
   161      *
       
   162      * @since S60 3.2
       
   163      * @return None
       
   164      */
       
   165     void RunL();
       
   166 
       
   167     /**
       
   168      * From CActive.
       
   169      * Cancel current activity.
       
   170      *
       
   171      * @since S60 3.2
       
   172      * @return None
       
   173      */
       
   174     void DoCancel();
       
   175 
       
   176 // from base class MDunServAdvMon
       
   177 
       
   178     /**
       
   179      * From MDunServAdvMon.
       
   180      * Gets called when advertisement status changes to start
       
   181      *
       
   182      * @since S60 5.0
       
   183      * @param aCreation ETrue if channel creation
       
   184      *                  EFalse if channel free
       
   185      * @return None
       
   186      */
       
   187     void NotifyAdvertisementStart( TBool aCreation );
       
   188 
       
   189     /**
       
   190      * From MDunServAdvMon.
       
   191      * Gets called when advertisement status changes to end
       
   192      *
       
   193      * @since S60 5.0
       
   194      * @return None
       
   195      */
       
   196     void NotifyAdvertisementEnd();
       
   197 
       
   198 private:  // data
       
   199 
       
   200     /**
       
   201      * Callback to call when notification via MDunServerCallback to be made
       
   202      * Not own.
       
   203      */
       
   204     MDunServerCallback* iServer;
       
   205 
       
   206     /**
       
   207      * Callback to call when notification via MDunListenCallback to be made
       
   208      * Not own.
       
   209      */
       
   210     MDunListenCallback* iParent;
       
   211 
       
   212     /**
       
   213      * Transporter to use for network side communication
       
   214      * Not own.
       
   215      */
       
   216     CDunTransporter* iTransporter;
       
   217 
       
   218     /**
       
   219      * Data socket entity for actual data transfer
       
   220      * This will be valid after CDunBtListen reacts to new data in
       
   221      * listener socket
       
   222      */
       
   223     TBtPortEntity& iEntity;
       
   224 
       
   225     /**
       
   226      * Current state of listening: active or inactive
       
   227      */
       
   228     TBtListenState iListenState;
       
   229 
       
   230     /**
       
   231      * Listener socket that will listen for activity in RFComm channel
       
   232      */
       
   233     RSocket iListenSocket;
       
   234 
       
   235     /**
       
   236      * Socket server used to reserve RFComm channel and creating data socket
       
   237      */
       
   238     RSocketServ iSockServer;
       
   239 
       
   240     /**
       
   241      * BT engine's Bluetooth discovery functionality
       
   242      * Used for registering/unregistering SDP record
       
   243      * Own.
       
   244      */
       
   245     CBTEngDiscovery* iDiscovery;
       
   246 
       
   247     /**
       
   248      * Local BT channel number
       
   249      * Set to reserved RFComm channel and used to register SDP record
       
   250      */
       
   251     TUint iChannelNum;
       
   252 
       
   253     /**
       
   254      * Handle to the reserver SDP channel
       
   255      * Set when SDP record registered
       
   256      */
       
   257     TSdpServRecordHandle iSDPHandleDun;
       
   258 
       
   259     };
       
   260 
       
   261 #endif  // C_CDUNBTLISTEN_H