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

Andrzej J.R. Hunt ajrhunt at kemper.freedesktop.org
Tue Jul 10 08:50:15 PDT 2012


 desktop/source/app/sofficemain.cxx      |   11 +---
 sd/source/ui/remotecontrol/Receiver.cxx |   82 +++++++++++++++++++++++---------
 sd/source/ui/remotecontrol/Receiver.hxx |    4 -
 sd/source/ui/remotecontrol/Server.cxx   |   36 +++++++-------
 sd/source/ui/remotecontrol/Server.hxx   |    1 
 5 files changed, 84 insertions(+), 50 deletions(-)

New commits:
commit 41685dad9bd5a66d5f63d4731a6a98c4f3ea98e9
Author: Andrzej J. R. Hunt <andrzej at ahunt.org>
Date:   Tue Jul 10 16:36:04 2012 +0100

    Fixed remote control code to work correctly.
    
    Change-Id: I Ia600ed456fba135056f7a00398030b7c9e873329

diff --git a/desktop/source/app/sofficemain.cxx b/desktop/source/app/sofficemain.cxx
index ed22834..43cd87f 100644
--- a/desktop/source/app/sofficemain.cxx
+++ b/desktop/source/app/sofficemain.cxx
@@ -43,13 +43,10 @@ int SVMain();
 
 extern "C" int DESKTOP_DLLPUBLIC soffice_main()
 {
-#if defined(ANDROID) || defined(LIBO_HEADLESS)
-#if defined(ANDROID)
+
+
     try {
-#endif
-        rtl::Bootstrap::setIniFilename(
-                rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///assets/program/lofficerc")));
-#endif
+
     tools::extendApplicationEnvironment();
 
     RTL_LOGFILE_PRODUCT_TRACE( "PERFORMANCE - enter Main()" );
@@ -77,13 +74,11 @@ extern "C" int DESKTOP_DLLPUBLIC soffice_main()
     }
 #endif
     return SVMain();
-#ifdef ANDROID
     } catch (const ::com::sun::star::uno::Exception &e) {
         fprintf (stderr, "Not handled UNO exception at main: '%s'\n",
                  rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
         throw; // to get exception type printed
     }
-#endif
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/remotecontrol/Receiver.cxx b/sd/source/ui/remotecontrol/Receiver.cxx
index 7c6187f..a2120b1 100644
--- a/sd/source/ui/remotecontrol/Receiver.cxx
+++ b/sd/source/ui/remotecontrol/Receiver.cxx
@@ -27,6 +27,7 @@
 #include "Receiver.hxx"
 #include <cstring>
 #include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <com/sun/star/uno/RuntimeException.hpp>
 #include <comphelper/processfactory.hxx>
 using namespace sd;
 using namespace ::com::sun::star::presentation;
@@ -41,48 +42,83 @@ Receiver::~Receiver()
 {
 }
 
-void Receiver::parseCommand( char* aCommand, sal_Int32 size, XSlideShowController *aController )
+void Receiver::executeCommand( JsonObject *aObject, Reference<XSlideShowController> xSlideShowController )
 {
-    uno::Reference< lang::XMultiServiceFactory > xServiceManager(
-            ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
+    const char* aInstruction = json_node_get_string( json_object_get_member( aObject, "command" ) );
 
-    uno::Reference< XFramesSupplier > xFramesSupplier( xServiceManager->createInstance(
-        "com.sun.star.frame.Desktop" ) , UNO_QUERY_THROW );
-    uno::Reference< frame::XFrame > xFrame = xFramesSupplier->getActiveFrame();
+    fprintf( stderr, "instruction:%s\n", aInstruction );
 
-    Reference<XPresentationSupplier> xPS ( xFrame->getController()->getModel(), UNO_QUERY_THROW);
+    if ( strcmp( aInstruction, "transition_next" ) == 0 )
+    {
 
-    Reference<XPresentation2> xPresentation(xPS->getPresentation(), UNO_QUERY_THROW);
+        xSlideShowController->gotoNextEffect();
+      // Next slide;
+    }
+    else if ( strcmp( aInstruction, "transition_previous" ) == 0 )
+    {
+        xSlideShowController->gotoPreviousEffect();
+    }
+    else if ( strcmp( aInstruction, "goto_slide" ) == 0 )
+    {
+        //
+    }
+
+}
 
-    Reference<XSlideShowController> xSlideShowController(xPresentation->getController(), UNO_QUERY_THROW);
+void Receiver::parseCommand( const char* aCommand, sal_Int32 size, XSlideShowController *aController )
+{
+    Reference<XSlideShowController> xSlideShowController;
+    try {
+        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(), UNO_QUERY_THROW );
+        Reference<XPresentationSupplier> xPS ( xFrame->getController()->getModel(), UNO_QUERY_THROW);
+        Reference<XPresentation2> xPresentation(xPS->getPresentation(), UNO_QUERY_THROW);
+        // Throws an exception if now slideshow running
+       xSlideShowController =  Reference<XSlideShowController>( xPresentation->getController(), UNO_QUERY_THROW );
+    }
+    catch ( com::sun::star::uno::RuntimeException &e )
+    {
+        return;
+    }
 
+    // Parsing
     JsonParser *parser;
     JsonNode *root;
     GError *error;
 
-    parser = json_parser_new ();
+    parser = json_parser_new();
     error = NULL;
     json_parser_load_from_data( parser, aCommand, size, &error );
 
     if (error) {
+        g_error_free( error );
+        g_object_unref( parser );
     }
 
     root = json_parser_get_root( parser );
     JsonObject *aObject = json_node_get_object( root );
-    const char* aInstruction = json_node_get_string( json_object_get_member( aObject, "command" ) );
 
-    if ( strcmp( aInstruction, "transition_next" ) )
-    {
-        xSlideShowController->gotoNextEffect();
-      // Next slide;
-    }
-    else if ( strcmp( aInstruction, "transition_previous" ) )
-    {
-        xSlideShowController->gotoPreviousEffect();
-    }
-    else if ( strcmp( aInstruction, "goto_slide" ) )
-    {
+    executeCommand( aObject, xSlideShowController );
 
-    }
+    g_object_unref( parser );
 
 }
+
+// void preparePreview(sal_Int32 aSlideNumber, Reference<SlideShowController> aController)
+// {
+//     uno::Reference< XDrawPage > aSlide( aController->getSlideByIndex( aSlideNumber ) );
+//
+//     uno::Reference< lang::XMultiServiceFactory > xServiceManager(
+//             ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
+//
+//     uno::Reference< XGraphicExportFilter > xGraphicExportFilter( xServiceManager->createInstance(
+//         "com.sun.star.drawing.GraphicExportFilter" ) , UNO_QUERY_THROW );
+//
+//     xGraphicExportFilter->setSource( aSlide );
+
+
+
+// }
diff --git a/sd/source/ui/remotecontrol/Receiver.hxx b/sd/source/ui/remotecontrol/Receiver.hxx
index 2466eb2..d4087e4 100644
--- a/sd/source/ui/remotecontrol/Receiver.hxx
+++ b/sd/source/ui/remotecontrol/Receiver.hxx
@@ -21,10 +21,10 @@ class Receiver
 public:
     Receiver();
     ~Receiver();
-    void parseCommand( char* aCommand, sal_Int32 size, XSlideShowController *aController );
+    void parseCommand( const char* aCommand, sal_Int32 size, XSlideShowController *aController );
 
 private:
-
+    void executeCommand( JsonObject *aObject, Reference<XSlideShowController> aController );
 
 };
 
diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx
index 00ecd2a..b4c0613 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -16,11 +16,9 @@ using rtl::OUString;
 using rtl::OString;
 
 Server::Server()
-:  Thread( "ServerThread" ), mSocket(), mStreamSocket(), mReceiver()
+:  Thread( "ServerThread" ), mSocket(), mReceiver()
 {
 
-//         boost::thread t( boost::bind(&Server::listenThread, this ))
-
 }
 
 Server::~Server()
@@ -30,36 +28,39 @@ Server::~Server()
 // Run as a thread
 void Server::listenThread()
 {
-    char aTemp;
-    vector<char> aBuffer;
+    // TODO: decryption
     while (true)
     {
+        vector<char> aBuffer;
         int aRet;
+        char aTemp;
         while ( (aRet = mStreamSocket.read( &aTemp, 1)) && aTemp != 0x0d ) // look for newline
         {
             aBuffer.push_back( aTemp );
-            // TODO: decryption
         }
         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();
+        aBuffer.push_back('\0');
+        OString aTempStr( &aBuffer.front() );
 
+        const sal_Char* aLengthChar = aTempStr.getStr();
         sal_Int32 aLen = strtol( aLengthChar, NULL, 10);
 
-        char *aMessage = new char[aLen];
+        char *aMessage = new char[aLen+1];
+        aMessage[aLen] = '\0';
 
-        if( mStreamSocket.read( (void*) aMessage, aLen ) != aLen)// Error reading or connection closed
+        if( mStreamSocket.read( (void*) aMessage, aLen ) != aLen) // Error reading or connection closed
         {
+            delete [] aMessage;
             return;
         }
-        // Parse.
-        mReceiver.parseCommand( aMessage, aLen, NULL );
 
+        aTempStr = OString( aMessage ); //, (sal_Int32) aLen, CHARSET, 0u
+        const sal_Char* aCommandChar = aTempStr.getStr();
+
+        mReceiver.parseCommand( aCommandChar, aTempStr.getLength(), NULL );
         delete [] aMessage;
 
         // TODO: deal with transmision errors gracefully.
@@ -69,20 +70,20 @@ void Server::listenThread()
 
 void Server::execute()
 {
-
-    osl::SocketAddr aAddr( "", PORT );
+    osl::SocketAddr aAddr( "0", PORT );
     if ( !mSocket.bind( aAddr ) )
     {
         // Error binding
     }
 
-    if ( !mSocket.listen() )
+    if ( !mSocket.listen(3) )
     {
         // Error listening
     }
     while ( true )
     {
         mSocket.acceptConnection( mStreamSocket );
+        fprintf( stderr, "Accepted a connection!\n" );
         listenThread();
     }
 
@@ -103,4 +104,5 @@ void SdDLL::RegisterRemotes()
 {
   fprintf( stderr, "Register our remote control goodness\n" );
   sd::Server::setup();
+
 }
diff --git a/sd/source/ui/remotecontrol/Server.hxx b/sd/source/ui/remotecontrol/Server.hxx
index 46bac2d..65b416b 100644
--- a/sd/source/ui/remotecontrol/Server.hxx
+++ b/sd/source/ui/remotecontrol/Server.hxx
@@ -22,6 +22,7 @@
 */
 #define PORT 1599
 
+#define CHARSET RTL_TEXTENCODING_UTF8
 
 namespace sd
 {


More information about the Libreoffice-commits mailing list