xref: /haiku/src/servers/bluetooth/BluetoothServer.h (revision 61da62d0e3ece288dbc0e608d44a2109daa85923)
130f1d1f3SOliver Ruiz Dorantes /*
230f1d1f3SOliver Ruiz Dorantes  * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
330f1d1f3SOliver Ruiz Dorantes  * All rights reserved. Distributed under the terms of the MIT License.
430f1d1f3SOliver Ruiz Dorantes  */
530f1d1f3SOliver Ruiz Dorantes #ifndef _BLUETOOTH_SERVER_APP_H
630f1d1f3SOliver Ruiz Dorantes #define _BLUETOOTH_SERVER_APP_H
730f1d1f3SOliver Ruiz Dorantes 
830f1d1f3SOliver Ruiz Dorantes #include <stdlib.h>
930f1d1f3SOliver Ruiz Dorantes 
10c6083519SOliver Ruiz Dorantes #include <Application.h>
11c6083519SOliver Ruiz Dorantes #include <ObjectList.h>
12c6083519SOliver Ruiz Dorantes #include <OS.h>
1330f1d1f3SOliver Ruiz Dorantes 
1430f1d1f3SOliver Ruiz Dorantes #include <bluetooth/bluetooth.h>
1530f1d1f3SOliver Ruiz Dorantes #include <bluetooth/HCI/btHCI.h>
1630f1d1f3SOliver Ruiz Dorantes #include <bluetooth/HCI/btHCI_transport.h>
1730f1d1f3SOliver Ruiz Dorantes #include <bluetooth/HCI/btHCI_command.h>
1830f1d1f3SOliver Ruiz Dorantes 
19c6083519SOliver Ruiz Dorantes #include "HCIDelegate.h"
20c6083519SOliver Ruiz Dorantes #include "DeviceManager.h"
21c6083519SOliver Ruiz Dorantes #include "LocalDeviceImpl.h"
22c6083519SOliver Ruiz Dorantes 
23c6083519SOliver Ruiz Dorantes #include <PortListener.h>
2430f1d1f3SOliver Ruiz Dorantes 
2530f1d1f3SOliver Ruiz Dorantes #define BT "bluetooth_server: "
2630f1d1f3SOliver Ruiz Dorantes 
27b48fa68aSOliver Ruiz Dorantes typedef enum {
28b48fa68aSOliver Ruiz Dorantes 	BLACKBOARD_GENERAL = 0,
29b48fa68aSOliver Ruiz Dorantes 	BLACKBOARD_DEVICEMANAGER,
30b48fa68aSOliver Ruiz Dorantes 	BLACKBOARD_KIT,
31*61da62d0SOliver Ruiz Dorantes 	BLACKBOARD_SDP,
32b48fa68aSOliver Ruiz Dorantes 	// more blackboards
33b48fa68aSOliver Ruiz Dorantes 	BLACKBOARD_END
34b48fa68aSOliver Ruiz Dorantes } BluetoothServerBlackBoardIndex;
35b48fa68aSOliver Ruiz Dorantes 
36bbe09899SOliver Ruiz Dorantes #define BLACKBOARD_LD(X) (BLACKBOARD_END+X-HCI_DEVICE_INDEX_OFFSET)
3730f1d1f3SOliver Ruiz Dorantes 
3830f1d1f3SOliver Ruiz Dorantes typedef BObjectList<LocalDeviceImpl> LocalDevicesList;
39a1163de8SOliver Ruiz Dorantes typedef PortListener<struct hci_event_header,
40a1163de8SOliver Ruiz Dorantes 	HCI_MAX_EVENT_SIZE, // Event Body can hold max 255 + 2 header
41a1163de8SOliver Ruiz Dorantes 	24					// Some devices have sent chunks of 24 events(inquiry result)
42a1163de8SOliver Ruiz Dorantes 	> BluetoothPortListener;
4330f1d1f3SOliver Ruiz Dorantes 
4430f1d1f3SOliver Ruiz Dorantes class BluetoothServer : public BApplication
4530f1d1f3SOliver Ruiz Dorantes {
4630f1d1f3SOliver Ruiz Dorantes public:
4730f1d1f3SOliver Ruiz Dorantes 
4830f1d1f3SOliver Ruiz Dorantes 	BluetoothServer();
4930f1d1f3SOliver Ruiz Dorantes 
5030f1d1f3SOliver Ruiz Dorantes 	virtual bool QuitRequested(void);
5130f1d1f3SOliver Ruiz Dorantes 	virtual void ArgvReceived(int32 argc, char **argv);
5230f1d1f3SOliver Ruiz Dorantes 	virtual void ReadyToRun(void);
5330f1d1f3SOliver Ruiz Dorantes 
5430f1d1f3SOliver Ruiz Dorantes 
5530f1d1f3SOliver Ruiz Dorantes 	virtual void AppActivated(bool act);
5630f1d1f3SOliver Ruiz Dorantes 	virtual void MessageReceived(BMessage *message);
5730f1d1f3SOliver Ruiz Dorantes 
58*61da62d0SOliver Ruiz Dorantes 	static int32 SDPServerThread(void* data);
5930f1d1f3SOliver Ruiz Dorantes 
6030f1d1f3SOliver Ruiz Dorantes 	/* Messages reply */
6130f1d1f3SOliver Ruiz Dorantes 	status_t	HandleLocalDevicesCount(BMessage* message, BMessage* reply);
6230f1d1f3SOliver Ruiz Dorantes 	status_t    HandleAcquireLocalDevice(BMessage* message, BMessage* reply);
6330f1d1f3SOliver Ruiz Dorantes 
643fdaa5bfSOliver Ruiz Dorantes 	status_t    HandleGetProperty(BMessage* message, BMessage* reply);
6530f1d1f3SOliver Ruiz Dorantes 	status_t    HandleSimpleRequest(BMessage* message, BMessage* reply);
6630f1d1f3SOliver Ruiz Dorantes 
6730f1d1f3SOliver Ruiz Dorantes 
6830f1d1f3SOliver Ruiz Dorantes     LocalDeviceImpl*    LocateLocalDeviceImpl(hci_id hid);
6930f1d1f3SOliver Ruiz Dorantes 
7030f1d1f3SOliver Ruiz Dorantes private:
7130f1d1f3SOliver Ruiz Dorantes 
7230f1d1f3SOliver Ruiz Dorantes 	LocalDeviceImpl*	LocateDelegateFromMessage(BMessage* message);
7330f1d1f3SOliver Ruiz Dorantes 
7430f1d1f3SOliver Ruiz Dorantes 	void 				ShowWindow(BWindow* pWindow);
7530f1d1f3SOliver Ruiz Dorantes 
76111d9460SOliver Ruiz Dorantes 	void				_InstallDeskbarIcon();
77111d9460SOliver Ruiz Dorantes 	void				_RemoveDeskbarIcon();
78111d9460SOliver Ruiz Dorantes 
7930f1d1f3SOliver Ruiz Dorantes 	LocalDevicesList   	fLocalDevicesList;
80c6083519SOliver Ruiz Dorantes 
8130f1d1f3SOliver Ruiz Dorantes 
8230f1d1f3SOliver Ruiz Dorantes 	// Notification system
83c6083519SOliver Ruiz Dorantes 	BluetoothPortListener*	fEventListener2;
84c6083519SOliver Ruiz Dorantes 
8530f1d1f3SOliver Ruiz Dorantes 	DeviceManager*			fDeviceManager;
8630f1d1f3SOliver Ruiz Dorantes 
8730f1d1f3SOliver Ruiz Dorantes 	BPoint 					fCenter;
88*61da62d0SOliver Ruiz Dorantes 
89*61da62d0SOliver Ruiz Dorantes 	thread_id				fSDPThreadID;
90*61da62d0SOliver Ruiz Dorantes 
91*61da62d0SOliver Ruiz Dorantes 	bool					fIsShuttingDown;
9230f1d1f3SOliver Ruiz Dorantes };
9330f1d1f3SOliver Ruiz Dorantes 
9430f1d1f3SOliver Ruiz Dorantes #endif
95