1 /* 2 * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3 * 4 * All rights reserved. Distributed under the terms of the MIT License. 5 * 6 */ 7 8 #ifndef _BLUETOOTH_SERVER_APP_H 9 #define _BLUETOOTH_SERVER_APP_H 10 11 #include <stdlib.h> 12 #include <Application.h> 13 #include <OS.h> 14 #include <ObjectList.h> 15 16 #include "BPortNot.h" 17 #include "HCIDelegate.h" 18 #include "DeviceManager.h" 19 #include "LocalDeviceImpl.h" 20 21 #include <bluetooth/bluetooth.h> 22 #include <bluetooth/HCI/btHCI.h> 23 #include <bluetooth/HCI/btHCI_transport.h> 24 #include <bluetooth/HCI/btHCI_command.h> 25 26 27 #define BT "bluetooth_server: " 28 29 typedef enum { 30 BLACKBOARD_GENERAL = 0, 31 BLACKBOARD_DEVICEMANAGER, 32 BLACKBOARD_EVENTS, 33 BLACKBOARD_KIT, 34 // more blackboards 35 BLACKBOARD_END 36 } BluetoothServerBlackBoardIndex; 37 38 #define BLACKBOARD_LD(X) (BLACKBOARD_END+X-HCI_DEVICE_INDEX_OFFSET) 39 40 typedef BObjectList<LocalDeviceImpl> LocalDevicesList; 41 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 58 static int32 notification_Thread(void* data); 59 static int32 sdp_server_Thread(void* data); 60 61 /* Messages reply */ 62 status_t HandleLocalDevicesCount(BMessage* message, BMessage* reply); 63 status_t HandleAcquireLocalDevice(BMessage* message, BMessage* reply); 64 status_t HandleGetFriendlyName(BMessage* message, BMessage* reply); 65 status_t HandleGetAddress(BMessage* message, BMessage* reply); 66 67 status_t HandleSimpleRequest(BMessage* message, BMessage* reply); 68 69 70 LocalDeviceImpl* LocateLocalDeviceImpl(hci_id hid); 71 72 private: 73 74 LocalDeviceImpl* LocateDelegateFromMessage(BMessage* message); 75 76 void ShowWindow(BWindow* pWindow); 77 78 LocalDevicesList fLocalDevicesList; 79 // UI 80 81 // Notification system 82 thread_id fEventListener; 83 DeviceManager* fDeviceManager; 84 85 BPoint fCenter; 86 }; 87 88 #endif 89