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 BLACKBOARD_SDP, 32 // more blackboards 33 BLACKBOARD_END 34 } BluetoothServerBlackBoardIndex; 35 36 #define BLACKBOARD_LD(X) (BLACKBOARD_END+X-HCI_DEVICE_INDEX_OFFSET) 37 38 typedef BObjectList<LocalDeviceImpl> LocalDevicesList; 39 typedef PortListener<struct hci_event_header, 40 HCI_MAX_EVENT_SIZE, // Event Body can hold max 255 + 2 header 41 24 // Some devices have sent chunks of 24 events(inquiry result) 42 > BluetoothPortListener; 43 44 class BluetoothServer : public BApplication 45 { 46 public: 47 48 BluetoothServer(); 49 50 virtual bool QuitRequested(void); 51 virtual void ArgvReceived(int32 argc, char **argv); 52 virtual void ReadyToRun(void); 53 54 55 virtual void AppActivated(bool act); 56 virtual void MessageReceived(BMessage *message); 57 58 static int32 SDPServerThread(void* data); 59 60 /* Messages reply */ 61 status_t HandleLocalDevicesCount(BMessage* message, BMessage* reply); 62 status_t HandleAcquireLocalDevice(BMessage* message, BMessage* reply); 63 64 status_t HandleGetProperty(BMessage* message, BMessage* reply); 65 status_t HandleSimpleRequest(BMessage* message, BMessage* reply); 66 67 68 LocalDeviceImpl* LocateLocalDeviceImpl(hci_id hid); 69 70 private: 71 72 LocalDeviceImpl* LocateDelegateFromMessage(BMessage* message); 73 74 void ShowWindow(BWindow* pWindow); 75 76 void _InstallDeskbarIcon(); 77 void _RemoveDeskbarIcon(); 78 79 LocalDevicesList fLocalDevicesList; 80 81 82 // Notification system 83 BluetoothPortListener* fEventListener2; 84 85 DeviceManager* fDeviceManager; 86 87 BPoint fCenter; 88 89 thread_id fSDPThreadID; 90 91 bool fIsShuttingDown; 92 }; 93 94 #endif 95