diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2012-08-02 12:27:19 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2012-08-06 10:23:08 +0100 |
commit | e43e36facc93b9e27e4d8757124ca0e6fcd9396b (patch) | |
tree | 098b4c54ef96d45615b0429506f192f2122e2b42 /sd | |
parent | 1a6bcd5bcdaf542c0a0db4fcc74149b9466dc58d (diff) |
Discovery service implemented server side.
Change-Id: I26c26ae96680c6264d7b927cb9206073239f2ef4
Diffstat (limited to 'sd')
-rw-r--r-- | sd/source/ui/remotecontrol/DiscoveryService.cxx | 41 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/DiscoveryService.hxx | 4 |
2 files changed, 44 insertions, 1 deletions
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx index f92b9ee490df..1ded965bcdf2 100644 --- a/sd/source/ui/remotecontrol/DiscoveryService.cxx +++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx @@ -11,10 +11,14 @@ #include <vector> #include <comphelper/processfactory.hxx> +#include <rtl/strbuf.hxx> #include "DiscoveryService.hxx" +using namespace osl; +using namespace rtl; using namespace sd; +using namespace std; DiscoveryService::DiscoveryService() : @@ -28,10 +32,47 @@ DiscoveryService::~DiscoveryService() } +void DiscoveryService::replyTo( SocketAddr& rAddr ) +{ + SocketAddr aLocalAddr; + mSocket.getLocalAddr( aLocalAddr ); + OString aAddrString = OUStringToOString( aLocalAddr.getHostname(), + RTL_TEXTENCODING_UTF8 ); + OStringBuffer aBuffer( "LOREMOTE_ADVERTISE\n" ); + aBuffer.append( aAddrString ).append( "\n" ); + mSocket.sendTo( rAddr, aBuffer.getStr(), aBuffer.getLength() ); +} void DiscoveryService::execute() { + sal_uInt64 aRet, aRead; + vector<char> aBuffer; + aRead = 0; + SocketAddr aAddr; + while ( true ) + { + aBuffer.resize( aRead + 100 ); + aRet = mSocket.recvFrom( &aBuffer[aRead], 100 ); + if ( aRet == 0 ) + { + fprintf( stderr, "Socket returned 0\n" ); +// break; // I.e. transmission finished. + } + aRead += aRet; + vector<char>::iterator aIt; + while ( (aIt = find( aBuffer.begin(), aBuffer.end(), '\n' )) + != aBuffer.end() ) + { + sal_uInt64 aLocation = aIt - aBuffer.begin(); + OString aString( &(*aBuffer.begin()), aLocation ); + if ( aString.compareTo( "LOREMOTE_SEARCH" ) == 0 ) { + replyTo( aAddr ); + } + aBuffer.erase( aBuffer.begin(), aIt + 1 ); // Also delete the newline + aRead -= (aLocation + 1); + } + } } DiscoveryService *sd::DiscoveryService::spService = NULL; diff --git a/sd/source/ui/remotecontrol/DiscoveryService.hxx b/sd/source/ui/remotecontrol/DiscoveryService.hxx index 863ebb56f489..aa4b349950db 100644 --- a/sd/source/ui/remotecontrol/DiscoveryService.hxx +++ b/sd/source/ui/remotecontrol/DiscoveryService.hxx @@ -38,11 +38,13 @@ namespace sd private: DiscoveryService(); ~DiscoveryService(); + static DiscoveryService *spService; + void execute(); osl::DatagramSocket mSocket; + void replyTo( osl::SocketAddr& rAddr ); - void execute(); }; } |