#ifndef S60QBLUETOOTHPRIVATE_H #define S60QBLUETOOTHPRIVATE_H #include #include // INCLUDES #include #include #include #include #include #include #include #include "Common.h" #include "DeviceDiscoverer.h" #include "ServiceDiscoverer.h" #include "Listener.h" #include "Connector.h" // maximum number of bluetooth device connections const TInt KMaxConnectedDevices=7; // length of label message buffer const TInt KMsgLength = 384; //avoiding magic numbers ;) const TInt KThirty = 30; const TInt KTwenty = 20; const TInt KEighty = 80; const TInt KTwelve = 12; const TInt KForty = 40; //the text displayed for devices with no name _LIT(KDeviceWithNoName,"*John Doe*"); _LIT(KNoServiceFound,"No services found!\n"); _LIT(KNewLine,"\n"); _LIT(KServiceFound,"Found service on:\n"); _LIT(KNoDevFound,"\nNo devices found!"); _LIT(KDevices," devices."); _LIT(KFoundTxt,"Found "); _LIT(KSecTxt," s."); _LIT(KTimeTxt,"time "); _LIT(KFormatStr,"< %S: %S\n"); _LIT(KDisconMsg,"Disconnected!\nSlave stopped.\n"); _LIT(KConnMsg,"Connected!\n"); _LIT(KFormatStr1,"< %S\n"); _LIT(KFormatStr2,"> %S: %S\n"); _LIT(KFormatStr3,"> %S\n"); _LIT(KMessage,"message"); _LIT(KNoConns,"No connections!"); _LIT(KConnDevicesTxt,"Connected devices:\n"); _LIT(KConnectingTxt, "Connecting...\n"); _LIT(KSlaveInitCompTxt,"\nSlave init complete!\nWaiting for connection."); _LIT(KListeningTxt,"\nListening channel %d"); _LIT(KSlaveInitTxt,"Slave init.."); _LIT(KDiscServicesTxt,"Discovering services,\nplease wait...\n"); _LIT(KDiscDevicesTxt,"Discovering devices,\nplease wait...\n"); _LIT(KServiceDiscoveryError, "Serv disco error:"); _LIT(KTurningOn, "Turning bt on"); // FORWARD DECLARATIONS class CDeviceDiscoverer; class CServiceAdvertiser; class CServiceDiscoverer; class CListener; class CConnector; class S60QBluetoothPrivate : public CBase, public MListenerObserver, public MConnectorObserver, public MDeviceDiscoObserver, public MServiceDiscoObserver, public MBluetoothPhysicalLinkMetricsObserver, public MBluetoothSocketNotifier { public: /*! * NewL() * * discussion Create new S60QBluetoothPrivate object * return a pointer to the created instance of S60QBluetoothPrivate */ static S60QBluetoothPrivate* NewL(S60QBluetooth* /* aAppUi */); /*! * NewLC() * */ static S60QBluetoothPrivate* NewLC(S60QBluetooth* /* aAppUi */); /*! * ~CBluetoothPMPExampleContainer() * * discussion Destroy the object and release all memory objects */ ~S60QBluetoothPrivate(); public: // New functions /*! * DiscoverDevicesL() * * discussion Discovers bluetooth devices within range. the discovered * devices will be displayed to user. */ void DiscoverDevicesL(); /*! * StartServiceDiscovery() * * discussion Starts service discovery for services on remote devices. */ void DiscoverServicesL(); /*! * StartSlaveL() * * discussion Starts the application in slave more. the application will open * listening socket to listen to incoming connection request, and advertise * its services. */ void StartSlaveL(); /*! * SendMessageL() * * discussion Send a message to all connected slaves. the user will be * prompted to enter the message text he/she wishes to send. */ void SendMessageL(QString message); /*! * ConnectDevicesL() * * discussion Connects to the remote devices that were discovered to offer * the service we require. */ void ConnectDevicesL(); /*! * DisconnectDevices() * * discussion Disconnects from connected remote devices. */ void DisconnectDevices(); /*! * ShowConnectedDevicesL() * * discussion Displays the connected remote devices. */ void ShowConnectedDevicesL(); /*! * HandleListenerDataReceivedL() * * discussion Handles the data slave received from a master. * * param aData the data received. */ void HandleListenerDataReceivedL(const TDesC& aData); void HandleListenerDataSendedL(); /*! * HandleConnectedDataReceivedL() * * discussion Handles the data a master received from a slave. * * param aName the name of the slave that sent the data. * param aData the data received. */ void HandleConnectorDataReceivedL(THostName aName, const TDesC& aData); /*! * HandleListenerConnectedL() * * discussion Handles the event of slave connection (slave was connected to * by master). user will be notified of connection. */ void HandleListenerConnectedL(); /*! * HandleListenerDisconnectedL() * * discussion Handles the event of slave disconnection, the master connection * to slave was terminated. user will be notitied of disconnection. */ void HandleListenerDisconnectedL(); /*! * HandleDeviceDiscoveryCompleteL() * * discussion Handles the event of device discovery completion. the * discovered devices will be displayed to user. */ void HandleDeviceDiscoveryCompleteL(); /* * From MDeviceDiscoObserver */ void DeviceDiscoveredL(const TDeviceData &aDevice); /*! * HandleServiceDiscoveryCompleteL() * * discussion Handles the event of service discovery completion. the * discovered services will be displayed to user. */ void HandleServiceDiscoveryCompleteL(); /*! * ReportServiceDiscoveryErrorL() * * discussion An error has occured during service discovery */ void ReportServiceDiscoveryErrorL(TInt aError); /*! * HasConnection() * * discussion Returns true if master has any slave connections. */ TBool HasConnections(); /* * TurnBtOnL() * * discussion * Uses the Notifier API to ask the user to turn on Bluetooth * if it's not on already. * HasConnection() * * */ void TurnBtOnL(); private: // in-class methods /*! * ShowMessageL() * * discussion Displays application messages for user on a label * * param aMsg text to be displayed * param aDrawLine if true draws a line */ void ShowMessageL(const TDesC& /* aMsg */, TBool /* aDrawLine=EFalse */); private: // Basic two-phase EPOC constructors /*! * ConstructL() * */ void ConstructL(); /*! * CBluetoothPMPExampleContainer() * * discussion Perform the first phase of two phase construction */ S60QBluetoothPrivate(S60QBluetooth* /* aAppUi */); private: // MBluetoothSocketNotifier void HandleAcceptCompleteL(TInt); //Notification of an accept complete event. void HandleActivateBasebandEventNotifierCompleteL(TInt,TBTBasebandEventNotification &); //Notification of a baseband event. void HandleConnectCompleteL(TInt); //Notification of a connection complete event. void HandleIoctlCompleteL(TInt); //Notification of a ioctl complete event. void HandleReceiveCompleteL(TInt); //Notification of a receive complete event. void HandleSendCompleteL(TInt); //Notification of a send complete event. void HandleShutdownCompleteL(TInt); //Notification of a shutdown complete event. void MBSN_ExtensionInterfaceL(TUid,void *&); //Returns a null aObject if the extension is not implemented, or a pointer to anot... private: // MBluetoothPhysicalLinkMetricsObserver void MbplmoError(TInt); // Notification that an error has occured. When this is called, the current subscri... TAny* MbplmoExtensionInterfaceL(TUid); // Returns a null aObject if the extension is not implemented, or a pointer to anot... void MbplmoFailedContactCounterChanged(TUint16); // Notification for the initial failed contact counter value, and whenever the fail... void MbplmoLinkQualityChanged(TUint8); // Notification for the initial Link Quality value and whenever the Link Quality ch... void MbplmoRssiChanged(TInt8); // Notification for the initial RSSI (received signal strengh indication) value and... void MbplmoTransmitPowerLevelChanged(TInt8); public: // data members // listener CListener* iListener; // device discoverer CDeviceDiscoverer* iDeviceDiscoverer; // service advertiser CServiceAdvertiser* iServiceAdvertiser; // service discoverer CServiceDiscoverer* iServiceDiscoverer; // true if the application is acting as a slave TBool iIsSlave; private: // data members CBluetoothPhysicalLinkMetrics* metrics; // application UI object reference S60QBluetooth* iAppUi; // socket server RSocketServ iSocketServ; // array holding the connectors TFixedArray iConnectedDevices; // device data list reference TDeviceDataList iDevDataList; // number of slave connections master has TInt iConnectedDeviceCount; //for timing device disco: TTime iStartTime; TTime iEndTime; }; #endif // S60QBLUETOOTHPRIVATE_H