datasourcemodules/bluetoothgpspositioningmodule/btgpspsy/inc/Connecting/BTGPSConnectManager.h
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef BTGPSCONNECTMANAGER_H
       
    22 #define BTGPSCONNECTMANAGER_H
       
    23 
       
    24 //  INCLUDES
       
    25 
       
    26 #include <e32base.h> 
       
    27 #include <es_sock.h>
       
    28 #include "BTGPSMessageListener.h"
       
    29 #include "BTGPSConnectManagerExt.h"
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // MACROS
       
    34 
       
    35 // DATA TYPES
       
    36 /**
       
    37 * Structure of handler item.
       
    38 */
       
    39 struct THandlerProcessItem
       
    40     {
       
    41     TInt iHandlerId;        ///The id of this handler
       
    42     TInt iSuccessNodeIndex; ///If handler succeed, the index of next node
       
    43     TInt iFailedNodeIndex;  ///if  handler failed, the index of next node
       
    44     };
       
    45         
       
    46 
       
    47 // FUNCTION  PROTOTYPES
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 class CBTGPSSettingManager;
       
    51 class MBTGPSMessageListener;
       
    52 class CBTGPSDeviceManager;
       
    53 class CBTDevice;
       
    54 class MBTGPSConnectStatusObserver;
       
    55 class CBTGPSMessageSender;
       
    56 class CBTGPSMessageReceiver;
       
    57 class CBTGPSDeviceListManager;
       
    58 
       
    59 // CLASS DECLARATION
       
    60 
       
    61 /**
       
    62 * Manager class that manage all operation related to Bluetooth connection. This
       
    63 * class provide interface for other object to connect and disconnect to bluetooth 
       
    64 * device. It also provide observer interface to other object to get device 
       
    65 * connection status change. This class also provides observer interface for other
       
    66 * object get messages from connected BT device. 
       
    67 * The class defines connection process that defines how  
       
    68 * to connect to bluetooth device. Each process contains handlers that handle 
       
    69 * BT connection activities. 
       
    70 *
       
    71 */
       
    72 class CBTGPSConnectManager: public CBase, private MBTGPSConnectManagerExt
       
    73     {
       
    74     public: 
       
    75 
       
    76         /**
       
    77         * Two-phase construction.
       
    78         */
       
    79         static CBTGPSConnectManager * NewL(
       
    80             CBTGPSSettingManager& aSettingManager,
       
    81             CBTGPSDeviceManager& aDeviceManager,
       
    82             CBTGPSConstantsManager& aConstantsManager,
       
    83             CBTGPSDeviceListManager& aDeviceListManager);
       
    84 
       
    85         /**
       
    86         * Destructor
       
    87         */
       
    88         virtual ~CBTGPSConnectManager();
       
    89 
       
    90     public:
       
    91         /**
       
    92         * Start connecting to BT device.
       
    93         * @return KErrCoundNotConnect if the device is in Error status
       
    94         */
       
    95         TInt Connecting();
       
    96         
       
    97         /**
       
    98         * Reconnecting to GPS. This function will reconnect to GPS device
       
    99         * even the GPS device is in error state.
       
   100         */
       
   101         void Reconnecting();
       
   102         
       
   103         /**
       
   104         * Cancel connecting. This function will also terminate current
       
   105 		* connection.
       
   106         */
       
   107         void CancelConnecting();
       
   108 
       
   109         /**
       
   110         * Add message listener.
       
   111 		* @param aListener Reference to message listener.
       
   112         */
       
   113         void AddMessageListenerL(MBTGPSMessageListener& aListener);
       
   114 
       
   115         /**
       
   116         * Remove message listener;
       
   117 		* @param aListener Reference to message listener.
       
   118         */
       
   119         void RemoveMessageListener(MBTGPSMessageListener& aListener);
       
   120         
       
   121         /**
       
   122         * Send message to connected BT device. This function will leave if
       
   123 		* the message can't be send, for example, the device is not connected, or
       
   124 		* out of memory.
       
   125 		* @param aMsg The message to be sent.
       
   126         */
       
   127         void SendMessageL(const TDesC8& aMsg);
       
   128         
       
   129         /**
       
   130         * Non-leave function to send message. 
       
   131 		* @param aMsg The message to be sent.
       
   132 		* @return KErrNone if the message is sent. Otherwise, system wide error code
       
   133 		*         will be returned.
       
   134         */
       
   135         TInt SendMessage(const TDesC8& aMsg);
       
   136     
       
   137     private:
       
   138         /**
       
   139         * From MBTGPSConnectManagerExt
       
   140         */
       
   141         virtual CBTGPSDeviceManager& DeviceManager() const;
       
   142 
       
   143         /**
       
   144         * From MBTGPSConnectManagerExt
       
   145         */
       
   146         virtual CBTGPSConstantsManager& ConstantsManager() const;
       
   147 
       
   148         /**
       
   149         * From MBTGPSConnectManagerExt
       
   150         */
       
   151         virtual CBTGPSSettingManager& SettingManager() const;
       
   152 
       
   153         /**
       
   154         * From MBTGPSConnectManagerExt
       
   155         */
       
   156         virtual void GetSocket(
       
   157             RSocketServ*& aSocketServ,
       
   158             RSocket*& aSocket);
       
   159 
       
   160         /**
       
   161         * From MBTGPSConnectManagerExt
       
   162         */
       
   163         void DisconnectBtDevice();
       
   164 
       
   165 
       
   166         /**
       
   167         * From MBTGPSConnectManagerExt
       
   168         */ 
       
   169         virtual void HandlerComplete(TInt aId, TInt aErr);
       
   170 
       
   171         /**
       
   172 		* From MBTGPSConnectManagerExt
       
   173 		*/ 
       
   174         virtual CBTGPSDeviceListManager& DeviceListManager() const;
       
   175         
       
   176     private:
       
   177         /**
       
   178         * Start to connect to BT device
       
   179         */
       
   180         void StartConnectDevice();
       
   181     
       
   182         /**
       
   183         * Start connecting process
       
   184         */
       
   185         void StartConnectingProcessL(const THandlerProcessItem* aProcess);
       
   186         
       
   187         /**
       
   188         * Connect process completed
       
   189         */
       
   190         void ConnectComplete(TInt aErr = KErrNone);
       
   191         
       
   192         /**
       
   193         * Idle callback to start connect process
       
   194         * If process failed, device will be set to connect error status
       
   195         */
       
   196         void StartConnectIdle();
       
   197         
       
   198         /**
       
   199         * Idle callback to start connect process
       
   200         */
       
   201         void StartConnectIdleL();
       
   202         
       
   203         /**
       
   204         * Idle callback to start handler
       
   205         */
       
   206         void StartNextHandler();
       
   207         
       
   208         /**
       
   209         * Static idle callback
       
   210         */
       
   211         static TInt StaticIdleCallback(TAny* aAny);
       
   212         
       
   213         /**
       
   214         * Second phase of the construction
       
   215         */
       
   216         void ConstructL();
       
   217 
       
   218         /**
       
   219         * Private constructor
       
   220         */
       
   221         CBTGPSConnectManager(
       
   222             CBTGPSSettingManager& aSettingManager,
       
   223             CBTGPSDeviceManager& aDeviceManager,
       
   224             CBTGPSConstantsManager& aConstantsManager,
       
   225             CBTGPSDeviceListManager& aDeviceListManager);
       
   226         
       
   227     private:
       
   228         //Setting Manager
       
   229         CBTGPSSettingManager& iSettingManager;
       
   230 
       
   231         //BT Device Manager
       
   232         CBTGPSDeviceManager& iDeviceManager;
       
   233         
       
   234         //Constants Manager
       
   235         CBTGPSConstantsManager& iConstantsManager;
       
   236         
       
   237         //Device List Manager
       
   238         CBTGPSDeviceListManager& iDeviceListManager;
       
   239 
       
   240         //Active Process;
       
   241         const THandlerProcessItem* iActiveProcess;
       
   242 
       
   243         //active handler
       
   244         CBase* iActiveHandler;
       
   245         
       
   246         //Current node index
       
   247         TInt iCurrentNode;
       
   248         
       
   249         //Last error code
       
   250         TInt iLastError;
       
   251         
       
   252         //Socket server
       
   253         RSocketServ iSocketServ;
       
   254         
       
   255         //Socket
       
   256         RSocket iSocket;
       
   257         
       
   258         //Message sender
       
   259         CBTGPSMessageSender* iMessageSender;
       
   260         
       
   261         //Message receiver
       
   262         CBTGPSMessageReceiver* iMessageReceiver;
       
   263         
       
   264         //Idle handler for start connecting process
       
   265         CIdle* iIdle;
       
   266 
       
   267     };
       
   268 #endif
       
   269 // End of File
       
   270