From d3cbcbad7d160c7b44182cc5142c5cd4e0e1a034 Mon Sep 17 00:00:00 2001 From: Siqi LIU Date: Sun, 21 Jul 2013 14:09:10 +0200 Subject: restore old implementation of autodiscovery to keep android app happy ^^ Change-Id: I33d856c5654cedb0d6bf437bf4653fac8830369c --- sd/source/ui/remotecontrol/DiscoveryService.cxx | 83 ++++++++++++------------- sd/source/ui/remotecontrol/DiscoveryService.hxx | 4 +- 2 files changed, 43 insertions(+), 44 deletions(-) (limited to 'sd') diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx index b5d4544f46ee..cfe769143346 100644 --- a/sd/source/ui/remotecontrol/DiscoveryService.cxx +++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx @@ -45,18 +45,13 @@ using namespace osl; using namespace rtl; using namespace sd; -void SAL_CALL DiscoveryService::run() -{ - -} - DiscoveryService::DiscoveryService() { - #ifdef MACOSX +#ifdef MACOSX OSXNetworkService * service = [[OSXNetworkService alloc] init]; [service publishImpressRemoteServiceOnLocalNetworkWithName: @""]; - #endif - /* +#endif +// #else mSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); sockaddr_in aAddr; @@ -79,9 +74,9 @@ DiscoveryService::DiscoveryService() multicastRequest.imr_interface.s_addr = htonl(INADDR_ANY); rc = setsockopt( mSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, -#ifdef WNT + #ifdef WNT (const char*) -#endif + #endif &multicastRequest, sizeof(multicastRequest)); if (rc) @@ -89,43 +84,47 @@ DiscoveryService::DiscoveryService() SAL_WARN("sd", "DiscoveryService: setsockopt failed: " << errno); return; // would be better to throw, but unsure if caller handles that } - */ +// #endif } DiscoveryService::~DiscoveryService() { -// #ifdef WNT -// closesocket( mSocket ); -// #else -// close( mSocket ); +// #ifndef MACOSX + #ifdef WNT + closesocket( mSocket ); + #else + close( mSocket ); + #endif +// #endif +} + +void SAL_CALL DiscoveryService::run() +{ +// #ifndef MACOSX + char aBuffer[BUFFER_SIZE]; + while ( true ) + { + memset( aBuffer, 0, sizeof(char) * BUFFER_SIZE ); + sockaddr_in aAddr; + socklen_t aLen = sizeof( aAddr ); + recvfrom( mSocket, aBuffer, BUFFER_SIZE, 0, (sockaddr*) &aAddr, &aLen ); + OString aString( aBuffer, strlen( "LOREMOTE_SEARCH" ) ); + if ( aString == "LOREMOTE_SEARCH" ) + { + OStringBuffer aStringBuffer("LOREMOTE_ADVERTISE\n"); + aStringBuffer.append( OUStringToOString( + osl::SocketAddr::getLocalHostname(), RTL_TEXTENCODING_UTF8 ) ) + .append( "\n\n" ); + if ( sendto( mSocket, aStringBuffer.getStr(), + aStringBuffer.getLength(), 0, (sockaddr*) &aAddr, + sizeof(aAddr) ) <= 0 ) + { + // Read error or closed socket -- we are done. + return; + } + } + } // #endif -// } - -// void SAL_CALL DiscoveryService::run() -// { -// char aBuffer[BUFFER_SIZE]; -// while ( true ) -// { -// memset( aBuffer, 0, sizeof(char) * BUFFER_SIZE ); -// sockaddr_in aAddr; -// socklen_t aLen = sizeof( aAddr ); -// recvfrom( mSocket, aBuffer, BUFFER_SIZE, 0, (sockaddr*) &aAddr, &aLen ); -// OString aString( aBuffer, strlen( "LOREMOTE_SEARCH" ) ); -// if ( aString == "LOREMOTE_SEARCH" ) -// { -// OStringBuffer aStringBuffer("LOREMOTE_ADVERTISE\n"); -// aStringBuffer.append( OUStringToOString( -// osl::SocketAddr::getLocalHostname(), RTL_TEXTENCODING_UTF8 ) ) -// .append( "\n\n" ); -// if ( sendto( mSocket, aStringBuffer.getStr(), -// aStringBuffer.getLength(), 0, (sockaddr*) &aAddr, -// sizeof(aAddr) ) <= 0 ) -// { -// // Read error or closed socket -- we are done. -// return; -// } -// } -// } } DiscoveryService *sd::DiscoveryService::spService = NULL; diff --git a/sd/source/ui/remotecontrol/DiscoveryService.hxx b/sd/source/ui/remotecontrol/DiscoveryService.hxx index a50454b6d545..846b2119fcaf 100644 --- a/sd/source/ui/remotecontrol/DiscoveryService.hxx +++ b/sd/source/ui/remotecontrol/DiscoveryService.hxx @@ -47,8 +47,8 @@ namespace sd static DiscoveryService *spService; virtual void SAL_CALL run(); -// osl::DatagramSocket mSocket; - // int mSocket; + // osl::DatagramSocket mSocket; + int mSocket; }; } -- cgit