summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2013-02-14 12:00:11 +0200
committerTor Lillqvist <tml@iki.fi>2013-02-14 12:10:40 +0200
commit100ac0876f1038aea7e7ef56f95d008ecc6aea3d (patch)
tree923764d69f5df01ea6e46caa3843d2f0893ca597
parent2848277180b9cb6dde639001a0f9612af5bd5992 (diff)
Start on Bluetooth code for the Impress Remote for OS X
Work in progress. It sets up the SDP service record and registers it, and that seems to work. Does not do anything with it yet. I wonder if the current approach to use the standard SerialPort service class will work for Macs, as they by default have one SerialPort service running, "Bluetooth-PDA-Sync", whatever that is. There is no code in the Android app to handle the case of there being several Serial Port services on the computer it wants to connect to, so what happens then when there are two will be interesting to see. (I can't find in the Android API any way to enumerate services that use the same service class. If there was, the app could choose the correct one based on its name.) So probably we should pretty soon switch to using a dedicated service class UUID instead of using the standard serial port one. As we already have the app out in the wild it will probably have to be modified to look for both Serial Port and our own service then? Sigh. Change-Id: I1bee6403642e9b8953b5a8fa8fb5fe6a9dc76a09
-rw-r--r--configure.ac2
-rw-r--r--sd/CppunitTest_sd_uimpress.mk11
-rw-r--r--sd/Library_sd.mk20
-rw-r--r--sd/source/ui/remotecontrol/BluetoothServer.cxx116
4 files changed, 143 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index 1436110f4900..a23e8d4e43c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9654,7 +9654,7 @@ if test -n "$enable_sdremote" -a "$enable_sdremote" != "no"; then
# If not explicitly enabled or disabled, default
if test -z "$enable_sdremote_bluetooth"; then
case "$OS" in
- LINUX|WNT)
+ LINUX|MACOSX|WNT)
# Default to yes for these
enable_sdremote_bluetooth=yes
;;
diff --git a/sd/CppunitTest_sd_uimpress.mk b/sd/CppunitTest_sd_uimpress.mk
index f41a4fb90fe5..64e21ccfdfe9 100644
--- a/sd/CppunitTest_sd_uimpress.mk
+++ b/sd/CppunitTest_sd_uimpress.mk
@@ -81,6 +81,17 @@ $(eval $(call gb_CppunitTest_use_system_win32_libs,sd_uimpress,\
))
endif
+ifeq ($(OS),MACOSX)
+$(eval $(call gb_CppunitTest_add_libs,sd_uimpress,\
+ -lobjc \
+))
+
+$(eval $(call gb_CppunitTest_use_system_darwin_frameworks,sd_uimpress,\
+ Foundation \
+ IOBluetooth \
+))
+endif
+
$(eval $(call gb_CppunitTest_use_externals,sd_uimpress,\
boost_headers \
gtk \
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index e2640dd79804..679c83670fda 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -532,10 +532,30 @@ $(eval $(call gb_Library_add_defs,sd,\
))
ifeq ($(ENABLE_SDREMOTE_BLUETOOTH),YES)
+
+ifeq (,$(filter IOS MACOSX,$(OS)))
+
$(eval $(call gb_Library_add_exception_objects,sd,\
sd/source/ui/remotecontrol/BluetoothServer \
))
+else
+
+$(eval $(call gb_Library_add_objcxxobjects,sd,\
+ sd/source/ui/remotecontrol/BluetoothServer \
+))
+
+$(eval $(call gb_Library_add_libs,sd,\
+ -lobjc \
+))
+
+$(eval $(call gb_Library_use_system_darwin_frameworks,sd,\
+ Foundation \
+ IOBluetooth \
+))
+
+endif
+
$(eval $(call gb_Library_add_defs,sd,\
-DENABLE_SDREMOTE_BLUETOOTH \
))
diff --git a/sd/source/ui/remotecontrol/BluetoothServer.cxx b/sd/source/ui/remotecontrol/BluetoothServer.cxx
index 735777ff77b4..7677e64b185a 100644
--- a/sd/source/ui/remotecontrol/BluetoothServer.cxx
+++ b/sd/source/ui/remotecontrol/BluetoothServer.cxx
@@ -8,7 +8,7 @@
*/
#include "BluetoothServer.hxx"
-#include "BluetoothServiceRecord.hxx"
+
#include <stdio.h>
#include <sal/log.hxx>
@@ -28,6 +28,7 @@
#ifndef DBusGObjectPath
#define DBusGObjectPath char // DBusGObjectPath is only present in newer version of dbus-glib
#endif
+ #include "BluetoothServiceRecord.hxx"
#endif
#ifdef WIN32
@@ -38,6 +39,12 @@
#include <ws2bth.h>
#endif
+#ifdef MACOSX
+ #include <premac.h>
+ #include <IOBluetooth/IOBluetooth.h>
+ #include <postmac.h>
+#endif
+
#ifdef __MINGW32__
// Value taken from http://msdn.microsoft.com/en-us/library/windows/desktop/ms738518%28v=vs.85%29.aspx
#define NS_BTH 16
@@ -243,7 +250,6 @@ void BluetoothServer::setDiscoverable( bool aDiscoverable )
dbus_g_connection_unref( aConnection );
#else // defined(LINUX) && defined(ENABLE_DBUS)
(void) aDiscoverable; // avoid warnings
- return;
#endif
}
@@ -337,7 +343,6 @@ void SAL_CALL BluetoothServer::run()
}
}
-// LINUX && ENABLE_DBUS
#elif defined(WIN32)
WORD wVersionRequested;
WSADATA wsaData;
@@ -430,8 +435,109 @@ void SAL_CALL BluetoothServer::run()
}
}
-// WIN32
-#else // !((defined(LINUX) && !defined(__FreeBSD_kernel__)) && defined(ENABLE_DBUS)) && !defined(WIN32)
+#elif defined(MACOSX)
+ // Build up dictionary at run-time instead of bothering with a
+ // .plist file, using the Objective-C API
+
+ // Compare to BluetoothServiceRecord.hxx
+
+ NSDictionary *dict =
+ [NSDictionary dictionaryWithObjectsAndKeys:
+
+ // Service class ID list
+ [NSArray arrayWithObject:
+ [IOBluetoothSDPUUID uuid16: kBluetoothSDPUUID16ServiceClassSerialPort]],
+ @"0001 - ServiceClassIDList",
+
+ // Protocol descriptor list
+ [NSArray arrayWithObjects:
+ [NSArray arrayWithObject: [IOBluetoothSDPUUID uuid16: kBluetoothSDPUUID16L2CAP]],
+ [NSArray arrayWithObjects:
+ [IOBluetoothSDPUUID uuid16: kBluetoothL2CAPPSMRFCOMM],
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt: 1],
+ @"DataElementSize",
+ [NSNumber numberWithInt: 1],
+ @"DataElementType",
+ [NSNumber numberWithInt: 5], // RFCOMM port number, will be replaced if necessary automatically
+ @"DataElementValue",
+ nil],
+ nil],
+ nil],
+ @"0004 - Protocol descriptor list",
+
+ // Browse group list
+ [NSArray arrayWithObject:
+ [IOBluetoothSDPUUID uuid16: kBluetoothSDPUUID16ServiceClassPublicBrowseGroup]],
+ @"0005 - BrowseGroupList",
+
+ // Language base attribute ID list
+ [NSArray arrayWithObjects:
+ [NSData dataWithBytes: "en" length: 2],
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt: 2],
+ @"DataElementSize",
+ [NSNumber numberWithInt: 1],
+ @"DataElementType",
+ [NSNumber numberWithInt: 0x006a], // encoding
+ @"DataElementValue",
+ nil],
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt: 2],
+ @"DataElementSize",
+ [NSNumber numberWithInt: 1],
+ @"DataElementType",
+ [NSNumber numberWithInt: 0x0100], // offset
+ @"DataElementValue",
+ nil],
+ nil],
+ @"0006 - LanguageBaseAttributeIDList",
+
+ // Bluetooth profile descriptor list
+ [NSArray arrayWithObject:
+ [NSArray arrayWithObjects:
+ [IOBluetoothSDPUUID uuid16: kBluetoothSDPUUID16ServiceClassSerialPort],
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt: 2],
+ @"DataElementSize",
+ [NSNumber numberWithInt: 1],
+ @"DataElementType",
+ [NSNumber numberWithInt: 0x0100], // version number ?
+ @"DataElementValue",
+ nil],
+ nil]],
+ @"0009 - BluetoothProfileDescriptorList",
+
+ // Attributes pointed to by the LanguageBaseAttributeIDList
+ @"LibreOffice Impress Remote Control",
+ @"0100 - ServiceName",
+ @"The Document Foundation",
+ @"0102 - ProviderName",
+ nil];
+
+ // Create service
+ IOBluetoothSDPServiceRecordRef serviceRecordRef;
+ IOReturn rc = IOBluetoothAddServiceDict((CFDictionaryRef) dict, &serviceRecordRef);
+
+ SAL_INFO("sd.bluetooth", "IOBluetoothAddServiceDict returned " << rc);
+
+ if (rc == kIOReturnSuccess)
+ {
+ IOBluetoothSDPServiceRecord *serviceRecord =
+ [IOBluetoothSDPServiceRecord withSDPServiceRecordRef: serviceRecordRef];
+
+ BluetoothRFCOMMChannelID channelID;
+ [serviceRecord getRFCOMMChannelID: &channelID];
+
+ BluetoothSDPServiceRecordHandle serviceRecordHandle;
+ [serviceRecord getServiceRecordHandle: &serviceRecordHandle];
+
+ // Do more...
+
+ (void) serviceRecord;
+ }
+ (void) mpCommunicators;
+#else
(void) mpCommunicators; // avoid warnings about unused member
#endif
}