BluetoothSDP.h

Go to the documentation of this file.
00001 #ifndef _OASYS_BTSDP_H_
00002 #define _OASYS_BTSDP_H_
00003 
00004 #include <config.h> 
00005 #ifdef OASYS_BLUETOOTH_ENABLED
00006 
00007 #include <bluetooth/bluetooth.h>
00008 #include <bluetooth/sdp.h>
00009 #include <bluetooth/sdp_lib.h>
00010 
00011 #include "../debug/Log.h"
00012 
00013 // generated using uuidgen on Mac OS X ... a completely arbitrary number :)
00014 // maybe eventually register something with Bluetooth SIG?
00015 // the joke here: why UUID?  why not call it GUID?  Cuz the SIG knows best
00016 #define OASYS_BLUETOOTH_SDP_UUID { 0xDCA3, 0x8352, 0xBF60, 0x11DA, \
00017                                    0xA23B, 0x0003, 0x931B, 0x7960 }
00018 
00019 namespace oasys {
00020 
00021 // for reference, from <bluetooth/sdp.h>
00022 #if 0
00023 
00024 typedef struct _sdp_list sdp_list_t;
00025 struct _sdp_list {
00026     sdp_list_t *next;
00027     void *data;
00028 };
00029 
00030 #endif
00031 
00032 /* Object to manage linked list of type sdp_list_t */
00033 class SDPListHead
00034 {
00035 public:
00036     SDPListHead() :
00037         free_func_(NULL), head_(NULL), current_(NULL)
00038     {
00039     }
00040 
00041     SDPListHead(sdp_list_t *head)
00042         : free_func_(NULL), current_(NULL)
00043     {
00044         head_ = head;
00045     }
00046 
00047     ~SDPListHead()
00048     {
00049         free_list();
00050     }
00051 
00052     // is there some special way to reclaim memory for each element 
00053     // of this list?  save a pointer to that function here
00054     void set_free_func(sdp_free_func_t f) { free_func_ = f; }
00055 
00056     // get/set pointer to the head of the list
00057     sdp_list_t* head() { return head_; }
00058     void head(sdp_list_t* head) { free_list(); head_ = head; }
00059 
00060     // iterate over elements of list
00061     // fails with NULL when end of list is reached
00062     // next call (after NULL) resets to head of list
00063     sdp_list_t* next() {
00064         if (current_) {
00065             current_ = current_->next;
00066             return current_;
00067         }
00068         current_ = head_;
00069         return current_;
00070     }
00071 
00072 protected:
00073     void free_list()
00074     {
00075         // below is lifted straight from BlueZ's sdp.c, with minor mods
00076         while (head_) {
00077             // save pointer to next
00078             sdp_list_t *next = head_->next;
00079             // if there's a special way to free data, then execute
00080             if (free_func_)
00081                 free_func_(head_->data);
00082             // free this element
00083             free(head_);
00084             // increment to next
00085             head_ = next;
00086         }
00087     }
00088 
00089     sdp_free_func_t  free_func_;
00090     sdp_list_t      *head_;
00091     sdp_list_t      *current_;
00092 };
00093 
00098 class BluetoothServiceDiscoveryClient : public Logger
00099 {
00100 public:
00101     BluetoothServiceDiscoveryClient(const char* logpath = "/dtn/bt/sdp/client");
00102     ~BluetoothServiceDiscoveryClient();
00103 
00104     bool is_dtn_router(bdaddr_t addr);
00105 
00106     void set_local_addr(bdaddr_t& addr) {
00107         bacpy(&local_addr_,&addr);
00108     }
00109 
00110     void get_local_addr(bdaddr_t& addr) {
00111         bacpy(&addr,&local_addr_);
00112     }
00113 
00114 protected:
00115     /* iterator over query results */
00116     sdp_record_t* get_next_service_record();
00117 
00118     /* Manage connection to remote SDP service */
00119     bool          connect();
00120     bool          close();
00121 
00122     /* Connect to remote SDP server and return query results */
00123     sdp_list_t*   do_search();
00124 
00125     /* member data */
00126     bdaddr_t      remote_addr_;     /* physical address of device to query */
00127     bdaddr_t      local_addr_;      /* physical address of local adapter */
00128     SDPListHead   *response_list_;  /* linked list of SDP responses */
00129     sdp_session_t *session_handle_; /* handle to open search request */
00130 };
00131 
00132 class BluetoothServiceRegistration : public Logger 
00133 {
00134 public:
00135 
00136 // generated using uuidgen on Mac OS X ... a completely arbitrary number :)
00137 // maybe eventually register something with Bluetooth SIG?
00138 // the joke here: why UUID?  why not call it GUID?  Cuz the SIG knows best
00139 #define OASYS_BLUETOOTH_SDP_UUID { 0xDCA3, 0x8352, 0xBF60, 0x11DA, \
00140                                    0xA23B, 0x0003, 0x931B, 0x7960 }
00141 
00142 #define OASYS_BLUETOOTH_SDP_NAME "dtnd"
00143 #define OASYS_BLUETOOTH_SDP_DESC "Delay Tolerant Networking daemon"
00144 #define OASYS_BLUETOOTH_SDP_PROV "DTNRG"
00145 
00146     BluetoothServiceRegistration(bdaddr_t*   local   = BDADDR_ANY,
00147                                  const char* logpath = "/dtn/bt/sdp/reg");
00148     ~BluetoothServiceRegistration();
00149 
00150     bool success() {return status_;};
00151 
00152 protected:
00153     bool register_service();
00154 
00155     sdp_session_t* session_handle_;
00156     bool status_;
00157     bdaddr_t local_addr_;
00158 };
00159 
00160 } // namespace oasys
00161 
00162 #endif /* OASYS_BLUETOOTH_ENABLED */
00163 #endif /* _OASYS_BTSDP_H_ */

Generated on Fri Dec 22 14:47:57 2006 for DTN Reference Implementation by  doxygen 1.5.1