aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-07-10 09:23:49 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-07-10 09:23:49 +0200
commitd945dee5b039e9e2d51b36852ef58a812acab302 (patch)
tree3f7a977b67d2d51726b349088075b23da73592ad
parent441cd0b11186d66493798551e1102eb246f1af9f (diff)
downloadble-toys-d945dee5b039e9e2d51b36852ef58a812acab302.tar.gz
ble-toys-d945dee5b039e9e2d51b36852ef58a812acab302.tar.bz2
ble-toys-d945dee5b039e9e2d51b36852ef58a812acab302.tar.xz
ble-toys-d945dee5b039e9e2d51b36852ef58a812acab302.zip
o Some iOS experiments. Very WiP.ios
-rw-r--r--apps/CMakeLists.txt1
-rw-r--r--ble/CMakeLists.txt37
-rw-r--r--ble/OsxBluetooth.mm41
-rw-r--r--ble/OsxBluetoothImpl.h41
4 files changed, 110 insertions, 10 deletions
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index a7defa2..81cfaec 100644
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -76,6 +76,7 @@ target_link_libraries(launcher ${BLUEZ_LIBRARIES})
target_link_libraries(launcher ${PQXX_LIBRARIES})
target_link_libraries(launcher ${LOG4CPLUS_LIBRARIES})
target_link_libraries(launcher ${CMAKE_THREAD_LIBS_INIT})
+#target_link_libraries(launcher PUBLIC Foundation)
target_compile_options(launcher PRIVATE -Wno-deprecated-register ${COMPILE_OPTIONS})
foreach(app ${APPS})
diff --git a/ble/CMakeLists.txt b/ble/CMakeLists.txt
index 5f20a21..fef06c5 100644
--- a/ble/CMakeLists.txt
+++ b/ble/CMakeLists.txt
@@ -10,12 +10,43 @@ if(IS_LINUX)
list(APPEND SOURCE_FILES LinuxBluetooth.cpp LinuxBluetooth.h)
list(APPEND COMPILE_OPTIONS -DIS_LINUX)
elseif(IS_APPLE)
- list(APPEND SOURCE_FILES OsxBluetooth.mm OsxBluetooth.h)
+ list(APPEND SOURCE_FILES OsxBluetooth.mm OsxBluetooth.h OsxBluetoothImpl.h)
list(APPEND COMPILE_OPTIONS -DIS_APPLE)
+
+ find_library(CORE_BLUETOOTH_LIBRARY CoreBluetooth)
+ if (NOT CORE_BLUETOOTH_LIBRARY)
+ message(FATAL_ERROR "CoreBluetooth not found")
+ endif()
+ message(STATUS "CORE_BLUETOOTH_LIBRARY=${CORE_BLUETOOTH_LIBRARY}")
+# list(APPEND INCLUDE_DIRECTORIES ${CORE_BLUETOOTH_LIBRARY}/Headers)
+# list(APPEND LIBRARIES_LIST ${CORE_BLUETOOTH_LIBRARY}/CoreBluetooth)
+ list(APPEND LIBRARIES_LIST ${CORE_BLUETOOTH_LIBRARY})
+
+ find_library(IOBLUETOOTH_LIBRARY IOBluetooth)
+ if (NOT IOBLUETOOTH_LIBRARY)
+ message(FATAL_ERROR "IOBluetooth not found")
+ endif()
+ message(STATUS "IOBLUETOOTH_LIBRARY=${IOBLUETOOTH_LIBRARY}")
+# list(APPEND INCLUDE_DIRECTORIES ${IOBLUETOOTH_LIBRARY}/Headers)
+# list(APPEND LIBRARIES_LIST ${IOBLUETOOTH_LIBRARY}/IOBluetooth)
+ list(APPEND LIBRARIES_LIST ${IOBLUETOOTH_LIBRARY})
+
+ find_library(FOUNDATION_LIBRARY Foundation)
+ if (NOT FOUNDATION_LIBRARY)
+ message(FATAL_ERROR "Foundation not found")
+ endif()
+ message(STATUS "FOUNDATION_LIBRARY=${FOUNDATION_LIBRARY}")
+# list(APPEND INCLUDE_DIRECTORIES ${FOUNDATION_LIBRARY}/Headers)
+# list(APPEND LIBRARIES_LIST ${FOUNDATION_LIBRARY}/Foundation)
+ list(APPEND LIBRARIES_LIST ${FOUNDATION_LIBRARY})
endif()
+list(APPEND INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/include")
+
find_package(Boost COMPONENTS regex system program_options REQUIRED)
+list(APPEND INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}")
+
add_library(ble ${SOURCE_FILES})
-target_include_directories(ble PUBLIC "${PROJECT_SOURCE_DIR}/include")
-target_include_directories(ble PUBLIC "${Boost_INCLUDE_DIRS}")
+target_include_directories(ble PUBLIC "${Boost_INCLUDE_DIRS}" ${INCLUDE_DIRECTORIES})
target_compile_options(ble PRIVATE -Wno-deprecated-register ${COMPILE_OPTIONS})
+target_link_libraries(ble PUBLIC ${LIBRARIES_LIST})
diff --git a/ble/OsxBluetooth.mm b/ble/OsxBluetooth.mm
index e94edaf..32645d5 100644
--- a/ble/OsxBluetooth.mm
+++ b/ble/OsxBluetooth.mm
@@ -1,14 +1,32 @@
-#import <CoreFoundation/CoreFoundation.h>
-#import <IOBluetooth/IOBluetoothUtilities.h>
-#import <IOBluetooth/objc/IOBluetoothSDPUUID.h>
-#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
+#include <CoreBluetooth/CBAdvertisementData.h>
-#import "BluetoothImpl.h"
-#import "OsxBluetooth.h"
+#include "BluetoothImpl.h"
+#include "OsxBluetooth.h"
+#include "OsxBluetoothImpl.h"
#include <map>
+
using namespace std;
+@implementation InquiryDelegateWrapper
+
+- (id) initWithCPPInstance:(trygvis::bluetooth::osx::InquiryDelegate*)_adapter
+{
+ self = [super init];
+ if (self) {
+ adapter = _adapter;
+ }
+ return self;
+}
+
+- (void)deviceInquiryStarted:(IOBluetoothDeviceInquiry *)sender;
+{
+ if (adapter)
+ adapter->deviceInquiryStarted();
+}
+
+@end
+
namespace trygvis {
namespace bluetooth {
namespace osx {
@@ -74,7 +92,16 @@ void OsxBluetoothAdapter::startScan() {
void OsxBluetoothAdapter::stopScan() {
}
-void OsxBluetoothAdapter::runScan(std::function<void(BluetoothDevice &device)>) {
+void OsxBluetoothAdapter::runScan(std::function<void(BluetoothDevice &device)> callback) {
+ auto y = new InquiryDelegate(*this, callback);
+ id x = [InquiryDelegateWrapper ::initWithCPPInstance:y];
+ inq = [IOBluetoothDeviceInquiry inquiryWithDelegate:x];
+ if(!inq) {
+ throw BluetoothException(&adapter, "Could not initialize inquery");
+ }
+}
+
+void InquiryDelegate::deviceInquiryStarted() {
}
BluetoothDevice &OsxBluetoothAdapter::getDevice(Mac &mac) {
diff --git a/ble/OsxBluetoothImpl.h b/ble/OsxBluetoothImpl.h
new file mode 100644
index 0000000..2abea7e
--- /dev/null
+++ b/ble/OsxBluetoothImpl.h
@@ -0,0 +1,41 @@
+#ifndef OSX_BLUETOOTH_IMPL_H
+#define OSX_BLUETOOTH_IMPL_H
+
+#import <CoreFoundation/CoreFoundation.h>
+#import <IOBluetooth/IOBluetoothUtilities.h>
+#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
+#import <IOBluetooth/objc/IOBluetoothSDPUUID.h>
+#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
+
+namespace trygvis {
+namespace bluetooth {
+namespace osx {
+
+class InquiryDelegate {
+public:
+ InquiryDelegate(OsxBluetoothAdapter &adapter, std::function<void(BluetoothDevice &device)> callback) : adapter(adapter), callback(callback) {
+ }
+
+ void deviceInquiryStarted();
+private:
+ OsxBluetoothAdapter &adapter;
+ std::function<void(BluetoothDevice &device)> callback;
+};
+
+}
+}
+}
+
+// TODO: can this be in a c++ namespace?
+
+@interface InquiryDelegateWrapper : NSObject <IOBluetoothDeviceInquiryDelegate> {
+// - (void)deviceInquiryStarted:(IOBluetoothDeviceInquiry *)sender
+//trygvis::bluetooth::osx::OsxBluetoothAdapter *adapter;
+trygvis::bluetooth::osx::InquiryDelegate* adapter;
+}
+
+- (id) initWithCPPInstance:(trygvis::bluetooth::osx::InquiryDelegate*)adapter;
+- (void)deviceInquiryStarted:(IOBluetoothDeviceInquiry *)sender;
+@end
+
+#endif