summaryrefslogtreecommitdiff
path: root/sd/source/ui
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2013-02-14 12:00:11 +0200
committerMichael Meeks <michael.meeks@suse.com>2013-02-19 08:39:08 +0000
commitc56593f029b17f35672b0b01b269e6914f80cbdf (patch)
tree3587a51a77a55f8ec01edd3e312d2e72630f25ad /sd/source/ui
parent3d9911a925607ed58002c6c9488507bd5a818975 (diff)
Merge in Bluetooth code for the Impress Remote for OS X
Thirteen commits from master squashed into one commit. Original commit messages in order below, so note that claims are in many cases overridden by later commits. === This is the 1st commit message: 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. === This is the 2nd commit message: Add this single-line file === This is the 3rd commit message: Fix build against Mac OS X SDK 10.4 === This is the 4th commit message: More work on the Impress Remote Control Bluetooth code for OS X Mostly the work of Thorsten, from December, adapted to compile against the current remote control code, and with one or two crucial things added. Plus lots of SAL_INFO calls added; once it works well many of them can be dropped. Does not work properly yet, do not cherry-pick just this to 4.0. === This is the 5th commit message: Nothing in the C standard about sockets === This is the 6th commit message: Fix compilation for Linux and hopefully Windows, too === This is the 7th commit message: Blind fix for WaE: class does not fully implement protocol The Xcode 3 compiler warns: class 'ChannelDelegate' does not fully implement the 'IOBluetoothRFCOMMChannelDelegate' protocol. === This is the 8th commit message: pragma GCC diagnostic is not available for 4.0.1 === This is the 9th commit message: std::vector::data() is C++11 === This is the 10th commit message: WaE: comparison is always true due to limited range of data type === This is the 11th commit message: Be specific in the logging as multiple threads involved Sure, each SAL_INFO output line includes the thread ID, but still, good to avoid confusion from where this line is coming. === This is the 12th commit message: Plug autorelease leak === This is the 13th commit message: Handle gracefully the remote end closing the RFCOMM channel Avoids a crash if one presses the "back" key on the Android remote control. (cherry picked from commit 100ac0876f1038aea7e7ef56f95d008ecc6aea3d) (cherry picked from commit c30e94a9cfc05ca8882fe78749b41207611910fb) (cherry picked from commit bc96a84370fb167ab2c63582c10535992f31768c) (cherry picked from commit f9685dc555cc79fe3a52caf9da39df37da750cd4) (cherry picked from commit dca5d2b1677ebffd1a4ff791c47b33a6252210b2) (cherry picked from commit bd6201ee4df1b7f54b1e768167a88ea5faa38fcc) (cherry picked from commit 05dbe2dda095aee2b595a29b95b5952acbe55e67) (cherry picked from commit c21916ad8a315a9dd7f23bf9aef0576975470a5a) (cherry picked from commit 730cff74c04dc6ec2cfc9cf9dcec172392f50616) (cherry picked from commit 21bec368ad670e368d4b5cadae1c07962710f115) (cherry picked from commit da3d37b968a79ff59fcc4103174b5b6bc3ec74c0) (cherry picked from commit b008101fd754b6b81c4f31e3079f01a21434601d) (cherry picked from commit 6ce04df28c8b5d6043340efe6fdc229b51dd8c36) Change-Id: Ic72b432b2174e2ad31225a1b5fa97c1a79330e48 Signed-off-by: Michael Meeks <michael.meeks@suse.com>
Diffstat (limited to 'sd/source/ui')
-rw-r--r--sd/source/ui/remotecontrol/BluetoothServer.cxx299
-rw-r--r--sd/source/ui/remotecontrol/BluetoothServer.hxx2
-rw-r--r--sd/source/ui/remotecontrol/BluetoothServer.mm1
-rw-r--r--sd/source/ui/remotecontrol/BufferedStreamSocket.hxx12
-rw-r--r--sd/source/ui/remotecontrol/Communicator.cxx2
-rw-r--r--sd/source/ui/remotecontrol/Communicator.hxx10
-rw-r--r--sd/source/ui/remotecontrol/IBluetoothSocket.hxx41
-rw-r--r--sd/source/ui/remotecontrol/OSXBluetooth.h33
-rw-r--r--sd/source/ui/remotecontrol/OSXBluetooth.mm52
-rw-r--r--sd/source/ui/remotecontrol/OSXBluetoothWrapper.hxx41
-rw-r--r--sd/source/ui/remotecontrol/Server.cxx1
-rw-r--r--sd/source/ui/remotecontrol/Transmitter.cxx2
-rw-r--r--sd/source/ui/remotecontrol/Transmitter.hxx8
13 files changed, 481 insertions, 23 deletions
diff --git a/sd/source/ui/remotecontrol/BluetoothServer.cxx b/sd/source/ui/remotecontrol/BluetoothServer.cxx
index 0a5e1d03d19b..4d948663b9bd 100644
--- a/sd/source/ui/remotecontrol/BluetoothServer.cxx
+++ b/sd/source/ui/remotecontrol/BluetoothServer.cxx
@@ -8,8 +8,9 @@
*/
#include "BluetoothServer.hxx"
-#include "BluetoothServiceRecord.hxx"
-#include <stdio.h>
+
+#include <iostream>
+#include <iomanip>
#include <sal/log.hxx>
@@ -27,6 +28,8 @@
#ifndef DBusGObjectPath
#define DBusGObjectPath char // DBusGObjectPath is only present in newer version of dbus-glib
#endif
+ #include "BluetoothServiceRecord.hxx"
+ #include "BufferedStreamSocket.hxx"
#endif
#ifdef WIN32
@@ -43,6 +46,23 @@
#include <ws2bth.h>
#undef MSC
#define MSC
+ #include "BufferedStreamSocket.hxx"
+#endif
+
+#ifdef MACOSX
+ #include <osl/conditn.hxx> // Include this early to avoid error as check() gets defined by some SDK header to empty
+ #include <premac.h>
+ #if MACOSX_SDK_VERSION >= 1070
+ #import <IOBluetooth/IOBluetooth.h>
+ #else
+ #import <CoreFoundation/CoreFoundation.h>
+ #import <IOBluetooth/IOBluetoothUtilities.h>
+ #import <IOBluetooth/objc/IOBluetoothSDPUUID.h>
+ #import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
+ #endif
+ #include <postmac.h>
+ #import "OSXBluetooth.h"
+ #include "OSXBluetoothWrapper.hxx"
#endif
#ifdef __MINGW32__
@@ -97,6 +117,155 @@ DBusGProxy* bluezGetDefaultAdapter( DBusGConnection* aConnection,
}
#endif // defined(LINUX) && defined(ENABLE_DBUS)
+#if defined(MACOSX)
+
+OSXBluetoothWrapper::OSXBluetoothWrapper( IOBluetoothRFCOMMChannel* channel ) :
+ mpChannel(channel),
+ mnMTU(0),
+ mHaveBytes(),
+ mMutex(),
+ mBuffer()
+{
+ // silly enough, can't write more than mnMTU bytes at once
+ mnMTU = [channel getMTU];
+
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::OSXBluetoothWrapper(): mnMTU=" << mnMTU );
+}
+
+sal_Int32 OSXBluetoothWrapper::readLine( rtl::OString& aLine )
+{
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::readLine()" );
+
+ while( true )
+ {
+ {
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::readLine: entering mutex" );
+ ::osl::MutexGuard aQueueGuard( mMutex );
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::readLine: entered mutex" );
+
+#ifdef SAL_LOG_INFO
+ // We should have in the sal logging some standard way to
+ // output char buffers with non-printables escaped.
+ std::ostringstream s;
+ if (mBuffer.size() > 0)
+ {
+ for (unsigned char *p = (unsigned char *) &mBuffer.front(); p != (unsigned char *) &mBuffer.front() + mBuffer.size(); p++)
+ {
+ if (*p == '\n')
+ s << "\\n";
+ else if (*p < ' ' || *p >= 0x7F)
+ s << "\\0x" << std::hex << std::setw(2) << std::setfill('0') << (int) *p << std::setfill(' ') << std::setw(1) << std::dec;
+ else
+ s << *p;
+ }
+ }
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::readLine mBuffer: \"" << s.str() << "\"" );
+#endif
+
+ // got enough bytes to return a line?
+ std::vector<char>::iterator aIt;
+ if ( (aIt = find( mBuffer.begin(), mBuffer.end(), '\n' ))
+ != mBuffer.end() )
+ {
+ sal_uInt64 aLocation = aIt - mBuffer.begin();
+
+ aLine = OString( &(*mBuffer.begin()), aLocation );
+
+ mBuffer.erase( mBuffer.begin(), aIt + 1 ); // Also delete the empty line
+
+ // yeps
+ SAL_INFO( "sdremote.bluetooth", " returning, got \"" << OStringToOUString( aLine, RTL_TEXTENCODING_UTF8 ) << "\"" );
+ return aLine.getLength() + 1;
+ }
+
+ // nope - wait some more (after releasing the mutex)
+ SAL_INFO( "sdremote.bluetooth", " resetting mHaveBytes" );
+ mHaveBytes.reset();
+ SAL_INFO( "sdremote.bluetooth", " leaving mutex" );
+ }
+
+ SAL_INFO( "sdremote.bluetooth", " waiting for mHaveBytes" );
+ mHaveBytes.wait();
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::readLine: got mHaveBytes" );
+ }
+}
+
+sal_Int32 OSXBluetoothWrapper::write( const void* pBuffer, sal_uInt32 n )
+{
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::write(" << pBuffer << ", " << n << ") mpChannel=" << mpChannel );
+
+ char* ptr = (char*)pBuffer;
+ sal_uInt32 nBytesWritten = 0;
+
+ if (mpChannel == nil)
+ return 0;
+
+ while( nBytesWritten < n )
+ {
+ int toWrite = n - nBytesWritten;
+ toWrite = toWrite <= mnMTU ? toWrite : mnMTU;
+ if ( [mpChannel writeSync:ptr length:toWrite] != kIOReturnSuccess )
+ {
+ SAL_INFO( "sdremote.bluetooth", " [mpChannel writeSync:" << (void *) ptr << " length:" << toWrite << "] returned error, total written " << nBytesWritten );
+ return nBytesWritten;
+ }
+ ptr += toWrite;
+ nBytesWritten += toWrite;
+ }
+ SAL_INFO( "sdremote.bluetooth", " total written " << nBytesWritten );
+ return nBytesWritten;
+}
+
+void OSXBluetoothWrapper::appendData(void* pBuffer, size_t len)
+{
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::appendData(" << pBuffer << ", " << len << ")" );
+
+ if( len )
+ {
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::appendData: entering mutex" );
+ ::osl::MutexGuard aQueueGuard( mMutex );
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::appendData: entered mutex" );
+ mBuffer.insert(mBuffer.begin()+mBuffer.size(),
+ (char*)pBuffer, (char *)pBuffer+len);
+ SAL_INFO( "sdremote.bluetooth", " setting mHaveBytes" );
+ mHaveBytes.set();
+ SAL_INFO( "sdremote.bluetooth", " leaving mutex" );
+ }
+}
+
+void OSXBluetoothWrapper::channelClosed()
+{
+ SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::channelClosed()" );
+
+ mpChannel = nil;
+}
+
+void incomingCallback( void *userRefCon,
+ IOBluetoothUserNotificationRef inRef,
+ IOBluetoothObjectRef objectRef )
+{
+ (void) inRef;
+
+ SAL_INFO( "sdremote.bluetooth", "incomingCallback()" );
+
+ BluetoothServer* pServer = (BluetoothServer*)userRefCon;
+
+ IOBluetoothRFCOMMChannel* channel = [IOBluetoothRFCOMMChannel withRFCOMMChannelRef:(IOBluetoothRFCOMMChannelRef)objectRef];
+
+ OSXBluetoothWrapper* socket = new OSXBluetoothWrapper( channel);
+ Communicator* pCommunicator = new Communicator( socket );
+ pServer->addCommunicator( pCommunicator );
+
+ ChannelDelegate* delegate = [[ChannelDelegate alloc] initWithCommunicatorAndSocket: pCommunicator socket: socket];
+ [channel setDelegate: delegate];
+ [delegate retain];
+
+ pCommunicator->launch();
+}
+
+#endif // MACOSX
+
+
BluetoothServer::BluetoothServer( std::vector<Communicator*>* pCommunicators )
: mpCommunicators( pCommunicators )
{
@@ -249,10 +418,15 @@ void BluetoothServer::setDiscoverable( bool aDiscoverable )
g_object_unref( G_OBJECT( aAdapter ));
dbus_g_connection_unref( aConnection );
#else // defined(LINUX) && defined(ENABLE_DBUS)
- return;
+ (void) aDiscoverable; // avoid warnings
#endif
}
+void BluetoothServer::addCommunicator( Communicator* pCommunicator )
+{
+ mpCommunicators->push_back( pCommunicator );
+}
+
void SAL_CALL BluetoothServer::run()
{
SAL_INFO( "sdremote.bluetooth", "BluetoothServer::execute called" );
@@ -342,7 +516,6 @@ void SAL_CALL BluetoothServer::run()
}
}
-// LINUX && ENABLE_DBUS
#elif defined(WIN32)
WORD wVersionRequested;
WSADATA wsaData;
@@ -435,8 +608,122 @@ 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
+
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
+ 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("sdremote.bluetooth", "IOBluetoothAddServiceDict returned " << rc);
+
+ if (rc == kIOReturnSuccess)
+ {
+ IOBluetoothSDPServiceRecord *serviceRecord =
+ [IOBluetoothSDPServiceRecord withSDPServiceRecordRef: serviceRecordRef];
+
+ BluetoothRFCOMMChannelID channelID;
+ [serviceRecord getRFCOMMChannelID: &channelID];
+
+ BluetoothSDPServiceRecordHandle serviceRecordHandle;
+ [serviceRecord getServiceRecordHandle: &serviceRecordHandle];
+
+ // Register callback for incoming connections
+ IOBluetoothUserNotificationRef callbackRef =
+ IOBluetoothRegisterForFilteredRFCOMMChannelOpenNotifications(
+ incomingCallback,
+ this,
+ channelID,
+ kIOBluetoothUserNotificationChannelDirectionIncoming);
+
+ (void) callbackRef;
+
+ [serviceRecord release];
+ }
+
+ [pool release];
+
+ (void) mpCommunicators;
+#else
(void) mpCommunicators; // avoid warnings about unused member
#endif
}
diff --git a/sd/source/ui/remotecontrol/BluetoothServer.hxx b/sd/source/ui/remotecontrol/BluetoothServer.hxx
index 51be45f7d9bc..d8c9879ab59b 100644
--- a/sd/source/ui/remotecontrol/BluetoothServer.hxx
+++ b/sd/source/ui/remotecontrol/BluetoothServer.hxx
@@ -24,6 +24,8 @@ namespace sd
static bool isDiscoverable();
static void setDiscoverable( bool aDiscoverable );
+ void addCommunicator( Communicator* pCommunicator );
+
private:
BluetoothServer( std::vector<Communicator*>* pCommunicators );
~BluetoothServer();
diff --git a/sd/source/ui/remotecontrol/BluetoothServer.mm b/sd/source/ui/remotecontrol/BluetoothServer.mm
new file mode 100644
index 000000000000..eabecac4e7e8
--- /dev/null
+++ b/sd/source/ui/remotecontrol/BluetoothServer.mm
@@ -0,0 +1 @@
+#include "BluetoothServer.cxx"
diff --git a/sd/source/ui/remotecontrol/BufferedStreamSocket.hxx b/sd/source/ui/remotecontrol/BufferedStreamSocket.hxx
index bf9a58aad7c0..0e6b99aa5f22 100644
--- a/sd/source/ui/remotecontrol/BufferedStreamSocket.hxx
+++ b/sd/source/ui/remotecontrol/BufferedStreamSocket.hxx
@@ -9,7 +9,7 @@
#ifndef _SD_IMPRESSREMOTE_BUFFEREDSTREAMSOCKET_HXX
#define _SD_IMPRESSREMOTE_BUFFEREDSTREAMSOCKET_HXX
-#include <boost/noncopyable.hpp>
+#include "IBluetoothSocket.hxx"
#include <osl/socket.hxx>
#include <vector>
@@ -28,8 +28,8 @@ namespace sd
* integrated into osl Sockets.
*/
class BufferedStreamSocket :
- private ::osl::StreamSocket,
- private ::boost::noncopyable
+ public IBluetoothSocket,
+ private ::osl::StreamSocket
{
public:
/**
@@ -38,7 +38,7 @@ namespace sd
*/
BufferedStreamSocket( const osl::StreamSocket &aSocket );
/**
- * Create a BufferedStreamSocket on top of a standard c socket.
+ * Create a BufferedStreamSocket on top of a POSIX or WinSock socket.
*/
BufferedStreamSocket( int aSocket );
BufferedStreamSocket( const BufferedStreamSocket &aSocket );
@@ -47,9 +47,9 @@ namespace sd
* Returns whatever the last call of recv returned, i.e. 0 or less
* if there was a problem in communications.
*/
- sal_Int32 readLine(OString& aLine);
+ virtual sal_Int32 readLine( OString& aLine );
- sal_Int32 write( const void* pBuffer, sal_uInt32 n );
+ virtual sal_Int32 write( const void* pBuffer, sal_uInt32 n );
void getPeerAddr(osl::SocketAddr&);
private:
diff --git a/sd/source/ui/remotecontrol/Communicator.cxx b/sd/source/ui/remotecontrol/Communicator.cxx
index 3e3e7bce1b90..7f013349153e 100644
--- a/sd/source/ui/remotecontrol/Communicator.cxx
+++ b/sd/source/ui/remotecontrol/Communicator.cxx
@@ -21,7 +21,7 @@ using namespace std;
using namespace com::sun::star;
using namespace osl;
-Communicator::Communicator( BufferedStreamSocket *pSocket ):
+Communicator::Communicator( IBluetoothSocket *pSocket ):
Thread( "CommunicatorThread" ),
mpSocket( pSocket ),
pTransmitter( 0 ),
diff --git a/sd/source/ui/remotecontrol/Communicator.hxx b/sd/source/ui/remotecontrol/Communicator.hxx
index 10078bf63387..a783bacb7672 100644
--- a/sd/source/ui/remotecontrol/Communicator.hxx
+++ b/sd/source/ui/remotecontrol/Communicator.hxx
@@ -9,20 +9,17 @@
#ifndef _SD_IMPRESSREMOTE_COMMUNICATOR_HXX
#define _SD_IMPRESSREMOTE_COMMUNICATOR_HXX
-// SERVER
-#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <vector>
-#include <osl/socket.hxx>
#include <rtl/ref.hxx>
#include <salhelper/thread.hxx>
#include <com/sun/star/presentation/XSlideShowController.hpp>
-#include "BufferedStreamSocket.hxx"
+#include "IBluetoothSocket.hxx"
#define CHARSET RTL_TEXTENCODING_UTF8
namespace sd
@@ -39,7 +36,7 @@ namespace sd
class Communicator : public salhelper::Thread
{
public:
- Communicator( BufferedStreamSocket *pSocket );
+ Communicator( IBluetoothSocket *pSocket );
~Communicator();
void presentationStarted( const css::uno::Reference<
@@ -49,7 +46,7 @@ namespace sd
private:
void execute();
- BufferedStreamSocket *mpSocket;
+ IBluetoothSocket *mpSocket;
Transmitter *pTransmitter;
rtl::Reference<Listener> mListener;
@@ -57,4 +54,5 @@ namespace sd
}
#endif // _SD_IMPRESSREMOTE_COMMUNICATOR_HXX
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/remotecontrol/IBluetoothSocket.hxx b/sd/source/ui/remotecontrol/IBluetoothSocket.hxx
new file mode 100644
index 000000000000..194936730058
--- /dev/null
+++ b/sd/source/ui/remotecontrol/IBluetoothSocket.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef _SD_IMPRESSREMOTE_IBLUETOOTHSOCKET_HXX
+#define _SD_IMPRESSREMOTE_IBLUETOOTHSOCKET_HXX
+
+#include <rtl/string.hxx>
+#include <boost/noncopyable.hpp>
+
+namespace sd
+{
+ /** Interface for bluetooth data io
+ */
+ struct IBluetoothSocket : private boost::noncopyable
+ {
+ virtual ~IBluetoothSocket() {}
+
+ /** Blocks until a line is read.
+
+ @return whatever the last call of recv returned, i.e. 0 or less
+ if there was a problem in communications.
+ */
+ virtual sal_Int32 readLine(rtl::OString& aLine) = 0;
+
+ /** Write a number of bytes
+
+ @return number of bytes actually written
+ */
+ virtual sal_Int32 write( const void* pBuffer, sal_uInt32 n ) = 0;
+ };
+}
+
+#endif // _SD_IMPRESSREMOTE_IBLUETOOTHSOCKET_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/remotecontrol/OSXBluetooth.h b/sd/source/ui/remotecontrol/OSXBluetooth.h
new file mode 100644
index 000000000000..4c1900adb65d
--- /dev/null
+++ b/sd/source/ui/remotecontrol/OSXBluetooth.h
@@ -0,0 +1,33 @@
+/* -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_OSXBLUETOOTH_H
+#define INCLUDED_OSXBLUETOOTH_H
+
+#import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>
+
+#include "IBluetoothSocket.hxx"
+#include "Communicator.hxx"
+#include "OSXBluetoothWrapper.hxx"
+
+@interface ChannelDelegate : NSObject<IOBluetoothRFCOMMChannelDelegate>
+{
+ sd::Communicator* pCommunicator;
+ sd::OSXBluetoothWrapper* pSocket;
+}
+
+- (id) initWithCommunicatorAndSocket:(sd::Communicator*)communicator socket:(sd::OSXBluetoothWrapper*)socket;
+- (void) rfcommChannelData:(IOBluetoothRFCOMMChannel*)rfcommChannel data:(void *)dataPointer length:(size_t)dataLength;
+- (void) rfcommChannelClosed:(IOBluetoothRFCOMMChannel*)rfcommChannel;
+
+@end
+
+#endif /* INCLUDED_OSXBLUETOOTH_H */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/remotecontrol/OSXBluetooth.mm b/sd/source/ui/remotecontrol/OSXBluetooth.mm
new file mode 100644
index 000000000000..f364389df78e
--- /dev/null
+++ b/sd/source/ui/remotecontrol/OSXBluetooth.mm
@@ -0,0 +1,52 @@
+/* -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#include <osl/conditn.hxx> // Include this early to avoid error as check() gets defined by some SDK header to empty
+
+#include <premac.h>
+#import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>
+#include <postmac.h>
+
+#include "OSXBluetooth.h"
+
+@implementation ChannelDelegate
+
+- (id) initWithCommunicatorAndSocket:(sd::Communicator*)communicator socket:(sd::OSXBluetoothWrapper*)socket
+{
+ pCommunicator = communicator;
+ pSocket = socket;
+ return self;
+}
+
+- (void) rfcommChannelData:(IOBluetoothRFCOMMChannel*)rfcommChannel data:(void *)dataPointer length:(size_t)dataLength
+{
+ (void) rfcommChannel;
+
+ if ( pSocket )
+ {
+ pSocket->appendData(dataPointer, dataLength);
+ }
+}
+
+- (void) rfcommChannelClosed:(IOBluetoothRFCOMMChannel*)rfcommChannel
+{
+ (void) rfcommChannel;
+
+ SAL_INFO( "sdremote.bluetooth", "ChannelDelegate::rfcommChannelClosed()\n");
+
+ if ( pSocket )
+ {
+ pSocket->channelClosed();
+ }
+ pCommunicator = NULL;
+ pSocket = NULL;
+}
+
+@end
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/remotecontrol/OSXBluetoothWrapper.hxx b/sd/source/ui/remotecontrol/OSXBluetoothWrapper.hxx
new file mode 100644
index 000000000000..cecaa7a8b1e5
--- /dev/null
+++ b/sd/source/ui/remotecontrol/OSXBluetoothWrapper.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef _SD_IMPRESSREMOTE_OSXBLUETOOTHWRAPPER_HXX
+#define _SD_IMPRESSREMOTE_OSXBLUETOOTHWRAPPER_HXX
+
+#include <rtl/string.hxx>
+#include <osl/conditn.hxx>
+#include <osl/mutex.hxx>
+#include <vector>
+
+#include "IBluetoothSocket.hxx"
+
+namespace sd
+{
+ class OSXBluetoothWrapper : public IBluetoothSocket
+ {
+ IOBluetoothRFCOMMChannel* mpChannel;
+ int mnMTU;
+ osl::Condition mHaveBytes;
+ osl::Mutex mMutex;
+ std::vector<char> mBuffer;
+
+ public:
+ OSXBluetoothWrapper( IOBluetoothRFCOMMChannel* channel );
+ virtual sal_Int32 readLine( rtl::OString& aLine );
+ virtual sal_Int32 write( const void* pBuffer, sal_uInt32 len );
+ void appendData(void* pBuffer, size_t len );
+ void channelClosed();
+ };
+}
+
+#endif // _SD_IMPRESSREMOTE_OSXBLUETOOTHWRAPPER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx
index 76b4dd7c1562..9989ed05bb57 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -29,6 +29,7 @@
#include "RemoteServer.hxx"
#include "BluetoothServer.hxx"
#include "Communicator.hxx"
+#include "BufferedStreamSocket.hxx"
using namespace std;
using namespace sd;
diff --git a/sd/source/ui/remotecontrol/Transmitter.cxx b/sd/source/ui/remotecontrol/Transmitter.cxx
index e8e3388d7e88..a7c211b20ad1 100644
--- a/sd/source/ui/remotecontrol/Transmitter.cxx
+++ b/sd/source/ui/remotecontrol/Transmitter.cxx
@@ -13,7 +13,7 @@ using namespace std;
using namespace osl; // Sockets etc.
using namespace sd;
-Transmitter::Transmitter( BufferedStreamSocket* aSocket )
+Transmitter::Transmitter( IBluetoothSocket* aSocket )
: pStreamSocket( aSocket ),
mQueuesNotEmpty(),
mFinishRequested(),
diff --git a/sd/source/ui/remotecontrol/Transmitter.hxx b/sd/source/ui/remotecontrol/Transmitter.hxx
index 80e09b1793df..783e1d5dbc3c 100644
--- a/sd/source/ui/remotecontrol/Transmitter.hxx
+++ b/sd/source/ui/remotecontrol/Transmitter.hxx
@@ -6,12 +6,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+
#ifndef _SD_IMPRESSREMOTE_TRANSMITTER_HXX
#define _SD_IMPRESSREMOTE_TRANSMITTER_HXX
#include <osl/conditn.hxx>
#include <osl/mutex.hxx>
-#include "BufferedStreamSocket.hxx"
+#include "IBluetoothSocket.hxx"
#include <osl/thread.hxx>
#include <rtl/string.hxx>
@@ -25,7 +26,7 @@ class Transmitter
{
public:
enum Priority { PRIORITY_LOW = 1, PRIORITY_HIGH };
- Transmitter( ::sd::BufferedStreamSocket* aSocket );
+ Transmitter( ::sd::IBluetoothSocket* aSocket );
~Transmitter();
void addMessage( const rtl::OString& aMessage, const Priority aPriority );
void notifyFinished();
@@ -33,7 +34,7 @@ public:
private:
virtual void SAL_CALL run();
- ::sd::BufferedStreamSocket* pStreamSocket;
+ ::sd::IBluetoothSocket* pStreamSocket;
::osl::Condition mQueuesNotEmpty;
::osl::Condition mFinishRequested;
@@ -46,4 +47,5 @@ private:
}
#endif // _SD_IMPRESSREMOTE_TRANSMITTER_HXX
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */