[Libreoffice-commits] .: Branch 'feature/remote' - 3 commits - android/sdremote sd/source
Andrzej J.R. Hunt
ajrhunt at kemper.freedesktop.org
Thu Aug 2 07:53:24 PDT 2012
android/sdremote/src/org/libreoffice/impressremote/TestClient.java | 3
android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java | 2
android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java | 105 ++++++++++
sd/source/ui/remotecontrol/DiscoveryService.cxx | 68 ++++--
sd/source/ui/remotecontrol/DiscoveryService.hxx | 9
sd/source/ui/remotecontrol/ImagePreparer.cxx | 2
6 files changed, 168 insertions(+), 21 deletions(-)
New commits:
commit 95f27663a7428018e09a13df4ab811ffb6d8363b
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Thu Aug 2 16:52:53 2012 +0200
Server discovery functional.
Change-Id: I8642e0ea95a8d6691b76cc4d2dc1ddfbbf2b03e2
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
index d787e34..b78a9a4 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
@@ -40,16 +40,17 @@ public class ServerFinder {
if (i == aBuffer.length || !aCommand.equals("LOREMOTE_ADVERTISE")) {
return;
}
-
- for (int j = i + 1; j < aBuffer.length; j++) {
- if (aPacket.getData()[j] == '\n') {
- aAddress = new String(aPacket.getData(), i + 1, j, CHARSET);
- }
- }
-
- if (aAddress != null) {
- System.out.println("Address is :" + aAddress + "\n");
- }
+ System.out.println("SF: " + aPacket.getAddress().toString());
+
+ // for (int j = i + 1; j < aBuffer.length; j++) {
+ // if (aPacket.getData()[j] == '\n') {
+ // aAddress = new String(aPacket.getData(), i + 1, j, CHARSET);
+ // }
+ // }
+ //
+ // if (aAddress != null) {
+ // System.out.println("Address is :" + aAddress + "\n");
+ // }
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx
index 612332f..bc514d7 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.cxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx
@@ -67,6 +67,8 @@ void DiscoveryService::replyTo( sockaddr_in& rAddr )
// OStringBuffer aBuffer( "LOREMOTE_ADVERTISE\n" );
// aBuffer.append( aAddrString ).append( "\n" );
// mSocket.sendTo( rAddr, aBuffer.getStr(), aBuffer.getLength() );
+ OString aMessage("LOREMOTE_ADVERTISE\n");
+ sendto( mSocket, aMessage.getStr(), aMessage.getLength(), 0, (sockaddr*) &rAddr, sizeof(rAddr) );
}
void DiscoveryService::execute()
commit 3d68126411374261b904b3b8bfce552fd6d796b7
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Thu Aug 2 16:40:31 2012 +0200
Multicast listening now working.
Change-Id: Icae91b26f1142d7f25d6e38af4f951be26d9b22a
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx
index 2d2b367..612332f 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.cxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx
@@ -15,6 +15,16 @@
#include "DiscoveryService.hxx"
+#ifdef WIN32
+ #include <winsock.h>
+ typedef int socklen_t;
+#else
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
+#endif
+
using namespace osl;
using namespace rtl;
using namespace sd;
@@ -22,9 +32,25 @@ using namespace std;
DiscoveryService::DiscoveryService()
:
- Thread( "sd::DiscoveryService" ),
- mSocket()
+ Thread( "sd::DiscoveryService" )
+// mSocket()
{
+ mSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
+
+ sockaddr_in aAddr;
+ aAddr.sin_family = AF_INET;
+ aAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ aAddr.sin_port = htons( PORT_DISCOVERY );
+
+ bind( mSocket, (sockaddr*) &aAddr, sizeof(sockaddr_in) );
+
+ struct ip_mreq multicastRequest;
+
+ multicastRequest.imr_multiaddr.s_addr = inet_addr( "239.0.0.1" );
+ multicastRequest.imr_interface.s_addr = htonl(INADDR_ANY);
+
+ setsockopt( mSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+ &multicastRequest, sizeof(multicastRequest));
}
DiscoveryService::~DiscoveryService()
@@ -32,15 +58,15 @@ DiscoveryService::~DiscoveryService()
}
-void DiscoveryService::replyTo( SocketAddr& rAddr )
+void DiscoveryService::replyTo( sockaddr_in& 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() );
+// 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()
@@ -50,24 +76,21 @@ void DiscoveryService::execute()
vector<char> aBuffer;
aRead = 0;
-
-
- SocketAddr aListenAddr( "239.0.0.1", PORT_DISCOVERY );
- mSocket.bind( aListenAddr );
-
- SocketAddr aAddr;
while ( true )
{
aBuffer.resize( aRead + 100 );
+ sockaddr_in aAddr;
+ socklen_t aLen = sizeof( aAddr );
fprintf( stderr, "DiscoveryService waiting for packet\n" );
- aRet = mSocket.recvFrom( &aBuffer[aRead], 100 );
+// aRet = mSocket.recvFrom( &aBuffer[aRead], 100 );
+ recvfrom( mSocket, &aBuffer[aRead], 100, 0, (sockaddr*) &aAddr, &aLen );
fprintf( stderr, "DiscoveryService received a packet.\n" );
- if ( aRet == 0 )
- {
- fprintf( stderr, "Socket returned 0\n" );
-// break; // I.e. transmission finished.
- }
+// 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' ))
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.hxx b/sd/source/ui/remotecontrol/DiscoveryService.hxx
index aa4b349..94a2765 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.hxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.hxx
@@ -27,9 +27,13 @@ namespace css = ::com::sun::star;
#define CHARSET RTL_TEXTENCODING_UTF8
+struct sockaddr_in;
+
namespace sd
{
+
+
class DiscoveryService : public salhelper::Thread
{
public:
@@ -42,8 +46,9 @@ namespace sd
static DiscoveryService *spService;
void execute();
- osl::DatagramSocket mSocket;
- void replyTo( osl::SocketAddr& rAddr );
+// osl::DatagramSocket mSocket;
+ int mSocket;
+ void replyTo( sockaddr_in& rAddr );
};
}
commit ec3e4aa950a810d77d1f52d431678cf05ea5723a
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Thu Aug 2 16:11:06 2012 +0200
Early non-functional multicast code.
Change-Id: Id982b40e5e9df4dee037a2e54ed34206930123c9
diff --git a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
index ee8c57b..dc74cd5 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
@@ -85,7 +85,8 @@ public class TestClient extends Activity {
mCommunicationService = ((CommunicationService.CBinder) aService)
.getService();
mCommunicationService.connectTo(
- CommunicationService.Protocol.NETWORK, "10.0.2.2");
+ CommunicationService.Protocol.NETWORK,
+ "192.168.0.18");
mCommunicationService.setActivityMessenger(mMessenger);
enableButtons(true);
}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index 258bff1..e1669cc 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -55,6 +55,8 @@ public class CommunicationService extends Service {
@Override
public void onCreate() {
// TODO Create a notification (if configured).
+ ServerFinder aFinder = new ServerFinder();
+ aFinder.startFinding();
}
@Override
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
new file mode 100644
index 0000000..d787e34
--- /dev/null
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
@@ -0,0 +1,104 @@
+package org.libreoffice.impressremote.communication;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.SocketException;
+
+public class ServerFinder {
+
+ private static final int PORT = 1598;
+ private static final String CHARSET = "UTF-8";
+
+ private DatagramSocket mSocket = null;
+
+ private Thread mListenerThread = null;
+
+ public ServerFinder() {
+
+ }
+
+ private void listenForServer() {
+ byte[] aBuffer = new byte[500];
+ DatagramPacket aPacket = new DatagramPacket(aBuffer, aBuffer.length);
+
+ try {
+ String aCommand = null;
+ String aAddress = null;
+ System.out.println("SF:listening for packet\n");
+ mSocket.receive(aPacket);
+ System.out.println("SF:received packet\n");
+ int i;
+ for (i = 0; i < aBuffer.length; i++) {
+ if (aPacket.getData()[i] == '\n') {
+ aCommand = new String(aPacket.getData(), 0, i, CHARSET);
+ break;
+ }
+ }
+ if (i == aBuffer.length || !aCommand.equals("LOREMOTE_ADVERTISE")) {
+ return;
+ }
+
+ for (int j = i + 1; j < aBuffer.length; j++) {
+ if (aPacket.getData()[j] == '\n') {
+ aAddress = new String(aPacket.getData(), i + 1, j, CHARSET);
+ }
+ }
+
+ if (aAddress != null) {
+ System.out.println("Address is :" + aAddress + "\n");
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ public void startFinding() {
+ if (mSocket != null)
+ return;
+
+ if (mListenerThread == null) {
+ mListenerThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ mSocket = new DatagramSocket();
+ String aString = "LOREMOTE_SEARCH\n";
+ DatagramPacket aPacket = new DatagramPacket(
+ aString.getBytes(CHARSET),
+ aString.length(),
+ InetAddress.getByName("239.0.0.1"),
+ PORT);
+ mSocket.send(aPacket);
+ System.out.println("SF:sent packet\n");
+ while (true) {
+ listenForServer();
+ }
+ } catch (SocketException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ };
+ mListenerThread.start();
+ }
+
+ }
+
+ public void stopFinding() {
+ if (mListenerThread != null) {
+
+ }
+ }
+}
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx
index 1ded965..2d2b367 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.cxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx
@@ -45,15 +45,24 @@ void DiscoveryService::replyTo( SocketAddr& rAddr )
void DiscoveryService::execute()
{
+ fprintf( stderr, "Discovery service is listening\n" );;
sal_uInt64 aRet, aRead;
vector<char> aBuffer;
aRead = 0;
+
+
+ SocketAddr aListenAddr( "239.0.0.1", PORT_DISCOVERY );
+ mSocket.bind( aListenAddr );
+
SocketAddr aAddr;
while ( true )
{
aBuffer.resize( aRead + 100 );
+
+ fprintf( stderr, "DiscoveryService waiting for packet\n" );
aRet = mSocket.recvFrom( &aBuffer[aRead], 100 );
+ fprintf( stderr, "DiscoveryService received a packet.\n" );
if ( aRet == 0 )
{
fprintf( stderr, "Socket returned 0\n" );
diff --git a/sd/source/ui/remotecontrol/ImagePreparer.cxx b/sd/source/ui/remotecontrol/ImagePreparer.cxx
index f948834..defc863 100644
--- a/sd/source/ui/remotecontrol/ImagePreparer.cxx
+++ b/sd/source/ui/remotecontrol/ImagePreparer.cxx
@@ -88,7 +88,7 @@ void ImagePreparer::execute()
}
sendNotes( i );
}
- notesToHtml( 0 );
+// notesToHtml( 0 );
mRef.clear();
}
More information about the Libreoffice-commits
mailing list