[Libreoffice-commits] .: Branch 'feature/remote' - sd/Library_sd.mk sd/source

Andrzej J.R. Hunt ajrhunt at kemper.freedesktop.org
Mon Jul 9 07:57:21 PDT 2012


 sd/Library_sd.mk                        |    6 +
 sd/source/ui/remotecontrol/Receiver.cxx |   50 ++++++++++-----
 sd/source/ui/remotecontrol/Receiver.hxx |   17 ++---
 sd/source/ui/remotecontrol/Server.cxx   |  103 ++++++++++++++------------------
 sd/source/ui/remotecontrol/Server.hxx   |   23 +++----
 5 files changed, 106 insertions(+), 93 deletions(-)

New commits:
commit 0c81bae4481dfe02dcf58482a95d213a2f934293
Author: Andrzej J. R. Hunt <andrzej at ahunt.org>
Date:   Mon Jul 9 15:53:03 2012 +0100

    Replaced Unix with osl sockets. Added slideshow controller.
    
    Change-Id: Ic2d34d666bb748b12e51266e04706d105ab7a3be

diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index 9a31f20..98c083d 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -63,6 +63,7 @@ $(eval $(call gb_Library_set_include,sd,\
     -I$(SRCDIR)/sd/source/ui/inc \
     -I$(SRCDIR)/sd/source/ui/slidesorter/inc \
     -I$(WORKDIR)/SdiTarget/sd/sdi \
+    $(shell pkg-config --cflags json-glib-1.0) \
 ))
 
 $(eval $(call gb_Library_add_defs,sd,\
@@ -112,6 +113,11 @@ $(eval $(call gb_Library_use_libraries,sd,\
     $(gb_STDLIBS) \
 ))
 
+$(eval $(call gb_Library_add_libs,sd,\
+    $(shell pkg-config --libs glib-2.0 json-glib-1.0) \
+))
+
+
 $(eval $(call gb_Library_set_componentfile,sd,sd/util/sd))
 
 $(eval $(call gb_Library_add_exception_objects,sd,\
diff --git a/sd/source/ui/remotecontrol/Receiver.cxx b/sd/source/ui/remotecontrol/Receiver.cxx
index ea7a344..7c6187f 100644
--- a/sd/source/ui/remotecontrol/Receiver.cxx
+++ b/sd/source/ui/remotecontrol/Receiver.cxx
@@ -25,7 +25,13 @@
  *
  ************************************************************************/
 #include "Receiver.hxx"
-
+#include <cstring>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <comphelper/processfactory.hxx>
+using namespace sd;
+using namespace ::com::sun::star::presentation;
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::frame;
 Receiver::Receiver()
 {
     g_type_init ();
@@ -35,34 +41,48 @@ Receiver::~Receiver()
 {
 }
 
-void Receiver::parseCommand(char* aCommand, XSlideShowController *aController)
+void Receiver::parseCommand( char* aCommand, sal_Int32 size, XSlideShowController *aController )
 {
+    uno::Reference< lang::XMultiServiceFactory > xServiceManager(
+            ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
+
+    uno::Reference< XFramesSupplier > xFramesSupplier( xServiceManager->createInstance(
+        "com.sun.star.frame.Desktop" ) , UNO_QUERY_THROW );
+    uno::Reference< frame::XFrame > xFrame = xFramesSupplier->getActiveFrame();
+
+    Reference<XPresentationSupplier> xPS ( xFrame->getController()->getModel(), UNO_QUERY_THROW);
+
+    Reference<XPresentation2> xPresentation(xPS->getPresentation(), UNO_QUERY_THROW);
+
+    Reference<XSlideShowController> xSlideShowController(xPresentation->getController(), UNO_QUERY_THROW);
+
     JsonParser *parser;
     JsonNode *root;
     GError *error;
 
     parser = json_parser_new ();
     error = NULL;
-    json_parser_load_from_data( parser, aCommand, aCommand.size, error );
+    json_parser_load_from_data( parser, aCommand, size, &error );
 
     if (error) {
     }
 
     root = json_parser_get_root( parser );
     JsonObject *aObject = json_node_get_object( root );
-    char* aInstruction = json_node_get_string( json_object_get_member( "command" ) );
+    const char* aInstruction = json_node_get_string( json_object_get_member( aObject, "command" ) );
 
-    switch ( aInstruction )
+    if ( strcmp( aInstruction, "transition_next" ) )
     {
-    case "transition_next":
-        aController->gotoNextEffect();
+        xSlideShowController->gotoNextEffect();
       // Next slide;
-        break;
-    case "transition_previous":
-        aController->gotoPreviousEffect();
-        break;
-    case "goto_slide":
-        //
-        break;
-    };
+    }
+    else if ( strcmp( aInstruction, "transition_previous" ) )
+    {
+        xSlideShowController->gotoPreviousEffect();
+    }
+    else if ( strcmp( aInstruction, "goto_slide" ) )
+    {
+
+    }
+
 }
diff --git a/sd/source/ui/remotecontrol/Receiver.hxx b/sd/source/ui/remotecontrol/Receiver.hxx
index 9757946..2466eb2 100644
--- a/sd/source/ui/remotecontrol/Receiver.hxx
+++ b/sd/source/ui/remotecontrol/Receiver.hxx
@@ -3,19 +3,16 @@
 #define _SD_IMPRESSREMOTE_RECEIVER_HXX
 
 #include <com/sun/star/presentation/XSlideShowController.hpp>
-
-
+#include <com/sun/star/presentation/XPresentationSupplier.hpp>
+#include <com/sun/star/presentation/XPresentation.hpp>
+#include <com/sun/star/presentation/XPresentation2.hpp>
 
 #include <stdlib.h>
 #include <glib-object.h>
 #include <json-glib/json-glib.h>
 
-// Library_sd.mk:
-// $(eval $(call gb_Library_use_externals,sd,\
-//     gobject \
-// ))
-
-
+using namespace com::sun::star::presentation;
+using namespace com::sun::star::uno;
 namespace sd
 {
 
@@ -24,12 +21,12 @@ class Receiver
 public:
     Receiver();
     ~Receiver();
-    void parseCommand(char* aCommand, XSlideShowController *aController);
+    void parseCommand( char* aCommand, sal_Int32 size, XSlideShowController *aController );
 
 private:
 
 
-}
+};
 
 }
 
diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx
index ba0007a..9ebe555 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -8,38 +8,19 @@
 #include "Server.hxx"
 #include "Receiver.hxx"
 
-#include <boost/thread.hpp>
+
+
 using namespace std;
-using namespace sd::remotecontrol;
+using namespace sd;
+using rtl::OUString;
+using rtl::OString;
 
-Server::Server(char* aEncryptionKey, XSlideShowController aController)
-:     mReceiver()
+Server::Server()
+:  Thread( "ServerThread" ), mSocket(), mStreamSocket(), mReceiver()
 {
-    if ( (mSocket = socket(AF_INET, SOCK_STREAM, 0)) == -1)
-    {
-        // Error opening
-    }
 
-    sockaddr_in aAddress;
-    aAddress.sin_family = AF_INET;
-    aAddress.sin_port = htons(PORT);
-    aAddress.sin_addr.s_addr = htonl(INADDR_ANY);
-
-    if ( bind( mSocket, (struct sockaddr*) &aAddress, sizeof(aAddress) ) == -1 )
-    {
-        // Error binding
-    }
+//         boost::thread t( boost::bind(&Server::listenThread, this ))
 
-    if ( listen ( mSocket, 3 ) == -1 )
-    {
-        // Error listening
-    }
-    while (true)
-    {
-        mNewSocket = accept( mSocket, (struct sockaddr*) &aAddress, (socklen_t*) &aAddrLen );
-        boost::thread t( boost::bind(&Server::listenThread, this ))
-    }
-    // TODO: pass mNewSocket to the thread.
 }
 
 Server::~Server()
@@ -50,55 +31,67 @@ Server::~Server()
 void Server::listenThread()
 {
     char aTemp;
-    vector<char> aBuffer();
+    vector<char> aBuffer;
     while (true)
     {
-        int aLength;
-        while ( recv( mSocket, *aTemp, 1, 0) && aTemp != 0x0d ) // look for newline
+        int aRet;
+        while ( (aRet = mStreamSocket.read( &aTemp, 1)) && aTemp != 0x0d ) // look for newline
         {
             aBuffer.push_back( aTemp );
             // TODO: decryption
         }
-        OUString aLengthString = OUString( aBuffer.front(), aBuffer.size(), RTL_TEXTENCODING_UNICODE );
-        const sal_Char* aLengthChar = aLengthString.convertToString( *aCLength, RTL_TEXTENCODING_ASCII_US, 0).getStr();
+        if (aRet != 1) // Error reading or connection closed
+        {
+            return;
+        }
+        OUString aLengthString = OUString( &aBuffer.front(), aBuffer.size(), RTL_TEXTENCODING_UNICODE );
+        OString aTempStr;
+        aLengthString.convertToString( &aTempStr, RTL_TEXTENCODING_ASCII_US, 0);
+        const sal_Char* aLengthChar = aTempStr.getStr();
 
-        sal_uInt32 aLen = strtol( aLengthChar, NULL, 10);
+        sal_Int32 aLen = strtol( aLengthChar, NULL, 10);
 
         char *aMessage = new char[aLen];
-        recv( mSocket, *aMessage, aLen, 0);
+
+        if( mStreamSocket.read( (void*) aMessage, aLen ) != aLen)// Error reading or connection closed
+        {
+            return;
+        }
         // Parse.
-        mReceiver.parseCommand( aCommand );
+        mReceiver.parseCommand( aMessage, aLen, NULL );
 
         delete [] aMessage;
+
         // TODO: deal with transmision errors gracefully.
     }
 }
 
 
-// void Server::clientConnected()
-// {
-//   our_mServerList.insert( our_mServerList.end, new Server() );
-//   thread aThread = Boost::thread( listen );
-//
-// }
-//
-// void Server::clientDisconnected()
-// {
-//   our_mServerList::iterator aBegin = our_mServerList.begin;
-//   while ( *aBegin != this ) {
-//     aBegin++;
-//   }
-//   if ( *aBegin == this )
-//   {
-//     our_mServerList.erase( this );
-//     delete this;
-//   }
-// }
+void Server::execute()
+{
+
+    osl::SocketAddr aAddr( "", PORT );
+    if ( !mSocket.bind( aAddr ) )
+    {
+        // Error binding
+    }
+
+    if ( !mSocket.listen() )
+    {
+        // Error listening
+    }
+    while ( true )
+    {
+        mSocket.acceptConnection( mStreamSocket );
+        listenThread();
+    }
 
+}
 
 void SdDLL::RegisterRemotes()
 {
   fprintf( stderr, "Register our remote control goodness\n" );
+  Server server;
+  server.launch();
   // FIXME: create a thread
-  // FIXME: convert the above socket code to use sal/inc/osl/socket.hxx etc.
 }
diff --git a/sd/source/ui/remotecontrol/Server.hxx b/sd/source/ui/remotecontrol/Server.hxx
index 0728954..9aa9687 100644
--- a/sd/source/ui/remotecontrol/Server.hxx
+++ b/sd/source/ui/remotecontrol/Server.hxx
@@ -10,9 +10,12 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-
+#include <osl/socket.hxx>
 //#include <com/sun/star/presentation/AnimationEffect.hpp>
 
+#include <salhelper/thread.hxx>
+
+#include "Receiver.hxx"
 
 /**
 * The port for use for the main communication between LibO and remote control app.
@@ -20,28 +23,22 @@
 #define PORT 1599
 
 
-class XSlideShowController;
-
-class Receiver;
-
 namespace sd
 {
 
-    class Server
+    class Server : public salhelper::Thread
         {
         public:
             Server();
             ~Server();
-            void setPresentationController( XSlideShowController aController) { mController = aController; }
         private:
-            int mSocket;
-//     static vector<Server> our_mServerList;
-
-            void listen();
+            osl::AcceptorSocket mSocket;
+            osl::StreamSocket mStreamSocket;
+            void listenThread();
             Receiver mReceiver;
-//             Transmitter mTransmitter;
+            void execute();
         };
-    }
+
 }
 
 #endif // _SD_IMPRESSREMOTE_SERVER_HXX


More information about the Libreoffice-commits mailing list