xref: /haiku/src/servers/bluetooth/BluetoothServer.h (revision a1163de83ea633463a79de234b8742ee106531b2)
1 /*
2  * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef _BLUETOOTH_SERVER_APP_H
6 #define _BLUETOOTH_SERVER_APP_H
7 
8 #include <stdlib.h>
9 
10 #include <Application.h>
11 #include <ObjectList.h>
12 #include <OS.h>
13 
14 #include <bluetooth/bluetooth.h>
15 #include <bluetooth/HCI/btHCI.h>
16 #include <bluetooth/HCI/btHCI_transport.h>
17 #include <bluetooth/HCI/btHCI_command.h>
18 
19 #include "HCIDelegate.h"
20 #include "DeviceManager.h"
21 #include "LocalDeviceImpl.h"
22 
23 #include <PortListener.h>
24 
25 #define BT "bluetooth_server: "
26 
27 typedef enum {
28 	BLACKBOARD_GENERAL = 0,
29 	BLACKBOARD_DEVICEMANAGER,
30 	BLACKBOARD_KIT,
31 	// more blackboards
32 	BLACKBOARD_END
33 } BluetoothServerBlackBoardIndex;
34 
35 #define BLACKBOARD_LD(X) (BLACKBOARD_END+X-HCI_DEVICE_INDEX_OFFSET)
36 
37 typedef BObjectList<LocalDeviceImpl> LocalDevicesList;
38 typedef PortListener<struct hci_event_header,
39 	HCI_MAX_EVENT_SIZE, // Event Body can hold max 255 + 2 header
40 	24					// Some devices have sent chunks of 24 events(inquiry result)
41 	> BluetoothPortListener;
42 
43 class BluetoothServer : public BApplication
44 {
45 public:
46 
47 	BluetoothServer();
48 
49 	virtual bool QuitRequested(void);
50 	virtual void ArgvReceived(int32 argc, char **argv);
51 	virtual void ReadyToRun(void);
52 
53 
54 	virtual void AppActivated(bool act);
55 	virtual void MessageReceived(BMessage *message);
56 
57 	static int32 sdp_server_Thread(void* data);
58 
59 	/* Messages reply */
60 	status_t	HandleLocalDevicesCount(BMessage* message, BMessage* reply);
61 	status_t    HandleAcquireLocalDevice(BMessage* message, BMessage* reply);
62 
63 	status_t    HandleGetProperty(BMessage* message, BMessage* reply);
64 	status_t    HandleSimpleRequest(BMessage* message, BMessage* reply);
65 
66 
67     LocalDeviceImpl*    LocateLocalDeviceImpl(hci_id hid);
68 
69 private:
70 
71 	LocalDeviceImpl*	LocateDelegateFromMessage(BMessage* message);
72 
73 	void 				ShowWindow(BWindow* pWindow);
74 
75 	LocalDevicesList   	fLocalDevicesList;
76 
77 
78 	// Notification system
79 	BluetoothPortListener*	fEventListener2;
80 
81 	DeviceManager*			fDeviceManager;
82 
83 	BPoint 					fCenter;
84 };
85 
86 #endif
87