diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2012-09-13 20:58:12 +0200 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2012-09-13 20:58:12 +0200 |
commit | 741c56aa7309505f855e58239205cfa4b1d091dd (patch) | |
tree | 8398040d63045e86deaec597a3f50a238b127a2d /sd/source | |
parent | 522b4c65dcc90719288b4f7aa7eb565c15b64e86 (diff) |
Add support for Windows Bluetooth Stack.
Change-Id: I3a039889a033591c81e0fd531de3b053e8fa1b3e
Diffstat (limited to 'sd/source')
-rw-r--r-- | sd/source/ui/remotecontrol/BluetoothServer.cxx | 103 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/DiscoveryService.cxx | 4 |
2 files changed, 101 insertions, 6 deletions
diff --git a/sd/source/ui/remotecontrol/BluetoothServer.cxx b/sd/source/ui/remotecontrol/BluetoothServer.cxx index 5bf242c269ad..01adb96263fa 100644 --- a/sd/source/ui/remotecontrol/BluetoothServer.cxx +++ b/sd/source/ui/remotecontrol/BluetoothServer.cxx @@ -18,9 +18,16 @@ #include "bluetooth/rfcomm.h" #endif +#ifdef WIN32 + #undef MSC // Unset a legacy define, as otherwise ws2bth.h breaks + #include <winsock2.h> + #include <ws2bth.h> +#endif + // FIXME: move this into an external file and look at sharing definitions // across OS's (i.e. UUID and port ). // Also look at determining which ports are available. +// Alternatively use the binary sdp record #define BLUETOOTH_SERVICE_RECORD "<?xml version='1.0' encoding= 'UTF-8' ?><record><attribute id='0x0001'><sequence><uuid value='0x1101' /></sequence></attribute><attribute id='0x0004'><sequence><sequence><uuid value='0x0100' /></sequence><sequence><uuid value='0x0003' /><uint8 value='0x05' /></sequence></sequence></attribute><attribute id='0x0005'><sequence><uuid value='0x1002' /></sequence></attribute><attribute id='0x0006'><sequence><uint16 value='0x656e' /><uint16 value='0x006a' /><uint16 value='0x0100' /></sequence></attribute><attribute id='0x0009'><sequence><sequence><uuid value='0x1101' /><uint16 value='0x0100' /></sequence></sequence></attribute><attribute id='0x0100'><text value='Serial Port' /></attribute><attribute id='0x0101'><text value='COM Port' /></attribute></record>" #include "Communicator.hxx" @@ -146,10 +153,102 @@ void BluetoothServer::execute() } } -#else +// LINUX && ENABLE_DBUS +#elif defined(WIN32) + WORD wVersionRequested; + WSADATA wsaData; - (void) mpCommunicators; // avoid warnings about unused member + wVersionRequested = MAKEWORD(2, 2); + + if ( WSAStartup(wVersionRequested, &wsaData) ) + { + return; // winsock dll couldn't be loaded + } + + int aSocket = socket( AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM ); + if ( !aSocket ) + { + WSACleanup(); + return; + } + SOCKADDR_BTH aAddr; + aAddr.addressFamily = AF_BTH; + aAddr.btAddr = 0; + aAddr.serviceClassId = GUID_NULL; + aAddr.port = BT_PORT_ANY; // Select any free socket. + if ( bind( aSocket, (SOCKADDR*) &aAddr, sizeof(aAddr) ) == SOCKET_ERROR ) + { + closesocket( aSocket ); + WSACleanup(); + return; + } + + SOCKADDR aName; + int aNameSize = sizeof(aAddr); + getsockname( aSocket, &aName, &aNameSize ); // Retrieve the local address and port + + CSADDR_INFO aAddrInfo; + memset( &aAddrInfo, 0, sizeof(aAddrInfo) ); + aAddrInfo.LocalAddr.lpSockaddr = &aName; + aAddrInfo.LocalAddr.iSockaddrLength = sizeof( SOCKADDR_BTH ); + aAddrInfo.RemoteAddr.lpSockaddr = &aName; + aAddrInfo.RemoteAddr.iSockaddrLength = sizeof( SOCKADDR_BTH ); + aAddrInfo.iSocketType = SOCK_STREAM; + aAddrInfo.iProtocol = BTHPROTO_RFCOMM; + + // To be used for setting a custom UUID once available. +// GUID uuid; +// uuid.Data1 = 0x00001101; +// memset( &uuid, 0x1000 + UUID*2^96, sizeof( GUID ) ); +// uuid.Data2 = 0; +// uuid.Data3 = 0x1000; +// ULONGLONG aData4 = 0x800000805F9B34FB; +// memcpy( uuid.Data4, &aData4, sizeof(uuid.Data4) ); + + WSAQUERYSET aRecord; + memset( &aRecord, 0, sizeof(aRecord)); + aRecord.dwSize = sizeof(aRecord); + aRecord.lpszServiceInstanceName = "LibreOffice-SDRemote"; // Optional + aRecord.lpszComment = "Remote control of presentations over bluetooth."; + aRecord.lpServiceClassId = (LPGUID) &SerialPortServiceClass_UUID; + aRecord.dwNameSpace = NS_BTH; + aRecord.dwNumberOfCsAddrs = 1; + aRecord.lpcsaBuffer = &aAddrInfo; + + if ( WSASetService( &aRecord, RNRSERVICE_REGISTER, 0 ) == SOCKET_ERROR ) + { + closesocket( aSocket ); + WSACleanup(); + return; + } + if ( listen( aSocket, 1 ) == SOCKET_ERROR ) + { + closesocket( aSocket ); + WSACleanup(); + return; + } + + SOCKADDR_BTH aRemoteAddr; + int aRemoteAddrLen = sizeof(aRemoteAddr); + while ( true ) + { + int bSocket; + if ( (bSocket = accept(aSocket, (sockaddr*) &aRemoteAddr, &aRemoteAddrLen)) == INVALID_SOCKET ) + { + closesocket( aSocket ); + WSACleanup(); + return; + } else { + Communicator* pCommunicator = new Communicator( new BufferedStreamSocket( bSocket) ); + mpCommunicators->push_back( pCommunicator ); + pCommunicator->launch(); + } + } + +// WIN32 +#else // !(defined(LINUX) && defined(ENABLE_DBUS)) && !defined(WIN32) + (void) mpCommunicators; // avoid warnings about unused member #endif } diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx index 51982a348907..805ce0cdbd7b 100644 --- a/sd/source/ui/remotecontrol/DiscoveryService.cxx +++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx @@ -65,16 +65,12 @@ DiscoveryService::~DiscoveryService() void DiscoveryService::execute() { char aBuffer[BUFFER_SIZE]; - fprintf( stderr,"Created\n" ); while ( true ) { memset( aBuffer, 0, sizeof(char) * BUFFER_SIZE ); sockaddr_in aAddr; socklen_t aLen = sizeof( aAddr ); - fprintf( stderr,"REcing\n" ); recvfrom( mSocket, aBuffer, BUFFER_SIZE, 0, (sockaddr*) &aAddr, &aLen ); - fprintf( stderr,"Reced\n" ); - fprintf( stderr, "Received from\n" ); OString aString( aBuffer, strlen( "LOREMOTE_SEARCH" ) ); if ( aString.compareTo( "LOREMOTE_SEARCH" ) == 0 ) { |