android/sdremote/src/org/libreoffice/impressremote/TestClient.java |   17 +-
 sd/Library_sd.mk                                                   |    1 
 sd/source/ui/remotecontrol/Receiver.cxx                            |   33 ++--
 sd/source/ui/remotecontrol/Receiver.hxx                            |    9 -
 sd/source/ui/remotecontrol/Server.cxx                              |   43 ++---
 sd/source/ui/remotecontrol/Server.hxx                              |    5 
 sd/source/ui/remotecontrol/Transmitter.cxx                         |   82 
++++++++++
 sd/source/ui/remotecontrol/Transmitter.hxx                         |   47 +++++
 8 files changed, 191 insertions(+), 46 deletions(-)

New commits:
commit fe02a263c6515e64f291c52f0fe187b098f73bcf
Author: Andrzej J. R. Hunt <andr...@ahunt.org>
Date:   Fri Jul 13 17:34:49 2012 +0100

    Transmitter for queuing of messages (Client->Server), fixed protocol.
    
    Change-Id: I Idcf6cf33b75dde2f921bec6c64e394e91994aba0

diff --git a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java 
b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
index 83f4c71..1b0f749 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
@@ -1,6 +1,5 @@
 package org.libreoffice.impressremote;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 
 import org.libreoffice.impressremote.communication.CommunicationService;
@@ -24,7 +23,8 @@ import android.widget.TextView;
 
 public class TestClient extends Activity {
 
-       HashMap<Integer, Bitmap> aPreviewImages = new HashMap<Integer, 
Bitmap>();
+       private HashMap<Integer, Bitmap> mPreviewImages = new HashMap<Integer, 
Bitmap>();
+       private boolean mCurrentPreviewImageMissing = false;
 
        private boolean mIsBound = false;
 
@@ -141,14 +141,23 @@ public class TestClient extends Activity {
                        case CommunicationService.MSG_SLIDE_CHANGED:
                                int newSlide = aData.getInt("slide_number");
                                mSlideLabel.setText("Slide " + newSlide);
-                               // TODO: set slide;
+                               if (mPreviewImages.containsKey(newSlide)) {
+                                       
mImageView.setImageBitmap(mPreviewImages.get(newSlide));
+                                       mCurrentPreviewImageMissing = false;
+                               } else {
+                                       mCurrentPreviewImageMissing = true;
+                               }
                                break;
                        case CommunicationService.MSG_SLIDE_PREVIEW:
                                int aSlideNumber = aData.getInt("slide_number");
                                byte[] aPreviewImage = 
aData.getByteArray("preview_image");
                                Bitmap aBitmap = 
BitmapFactory.decodeByteArray(aPreviewImage,
                                                0, aPreviewImage.length);
-                               aPreviewImages.put(aSlideNumber, aBitmap);
+                               mPreviewImages.put(aSlideNumber, aBitmap);
+                               if (mCurrentPreviewImageMissing) {
+                                       mImageView.setImageBitmap(aBitmap);
+                                       mCurrentPreviewImageMissing = false;
+                               }
                                mImageView.setImageBitmap(aBitmap);
                                // TODO: remove above line, use slide changed 
to show image.
                                break;
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index 9deaefb..2b43a36 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -323,6 +323,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\
     sd/source/ui/remotecontrol/Server \
     sd/source/ui/remotecontrol/Receiver \
     sd/source/ui/remotecontrol/Listener \
+    sd/source/ui/remotecontrol/Transmitter \
     sd/source/ui/slideshow/PaneHider \
     sd/source/ui/slideshow/SlideShowRestarter \
     sd/source/ui/slideshow/showwin \
diff --git a/sd/source/ui/remotecontrol/Receiver.cxx 
b/sd/source/ui/remotecontrol/Receiver.cxx
index 7b527ac..87eee7f 100644
--- a/sd/source/ui/remotecontrol/Receiver.cxx
+++ b/sd/source/ui/remotecontrol/Receiver.cxx
@@ -19,6 +19,7 @@
 #include <xmlsec/base64.h>
 #include <rtl/ustrbuf.hxx>
 #include <sax/tools/converter.hxx>
+#include <rtl/strbuf.hxx>
 
 using namespace sd;
 using namespace ::com::sun::star;
@@ -27,16 +28,22 @@ using rtl::OString;
 using namespace ::osl;
 using namespace std;
 
-Receiver::Receiver()
+Receiver::Receiver( Transmitter *aTransmitter )
 {
+    mTransmitter = aTransmitter;
 }
 
 Receiver::~Receiver()
 {
 }
 
-void Receiver::parseCommand( std::vector<OString> aCommand, osl::StreamSocket 
&aStreamSocket )
+void Receiver::parseCommand( std::vector<OString> aCommand )
 {
+    fprintf( stderr, "Parsing:\n");
+    for (int i = 0; i < aCommand.size(); i++)
+    {
+    fprintf( stderr, "%s\n", aCommand[i].getStr() );}
+    fprintf( stderr, "End parse\n" );
     uno::Reference<presentation::XSlideShowController> xSlideShowController;
     try {
         uno::Reference< lang::XMultiServiceFactory > xServiceManager(
@@ -49,8 +56,6 @@ void Receiver::parseCommand( std::vector<OString> aCommand, 
osl::StreamSocket &a
         // Throws an exception if now slideshow running
         xSlideShowController =  
uno::Reference<presentation::XSlideShowController>(
            xPresentation->getController(), uno::UNO_QUERY_THROW );
-        // FIXME: remove later, this is just to test functionality
-        sendPreview( 0, xSlideShowController, aStreamSocket );
     }
     catch ( com::sun::star::uno::RuntimeException &e )
     {
@@ -72,16 +77,18 @@ void Receiver::parseCommand( std::vector<OString> aCommand, 
osl::StreamSocket &a
         xSlideShowController->gotoSlideIndex( aSlide );
     }
 
+            // FIXME: remove later, this is just to test functionality
+        //sendPreview( 0, xSlideShowController, mTransmitter );
+
 }
 
 
 void sendPreview(sal_uInt32 aSlideNumber,
-                 uno::Reference<presentation::XSlideShowController> 
xSlideShowController, osl::StreamSocket &mStreamSocket )
+                 uno::Reference<presentation::XSlideShowController> 
xSlideShowController, Transmitter *aTransmitter )
 {
 
     sal_uInt64 aSize; // Unused
     uno::Sequence<sal_Int8> aImageData = preparePreview( aSlideNumber, 
xSlideShowController, 320, 240, aSize );
-
     rtl::OUStringBuffer aStrBuffer;
     ::sax::Converter::encodeBase64( aStrBuffer, aImageData );
 
@@ -89,15 +96,17 @@ void sendPreview(sal_uInt32 aSlideNumber,
         aStrBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
 
     // Start the writing
-    mStreamSocket.write( "slide_preview\n", strlen( "slide_preview\n" ) );
+    rtl::OStringBuffer aBuffer;
 
-    rtl::OString aSlideNumberString( rtl::OString::valueOf( 2 ) ); // FIXME 
get number
-    mStreamSocket.write( aSlideNumberString.getStr(), 
aSlideNumberString.getLength() );
-    mStreamSocket.write( "\n", 1 );
+    aBuffer.append( "slide_preview\n" );
 
-    mStreamSocket.write( aEncodedShortString.getStr(), 
aEncodedShortString.getLength() );
-    mStreamSocket.write( "\n\n", 2 );
+    rtl::OString aSlideNumberString( rtl::OString::valueOf( 2 ) ); // FIXME 
get number
+    aBuffer.append( aSlideNumberString.getStr() );
+    aBuffer.append( "\n" );
 
+    aBuffer.append( aEncodedShortString.getStr() );
+    aBuffer.append( "\n\n" );
+    aTransmitter->addMessage( aBuffer.makeStringAndClear(), 
Transmitter::Priority::LOW );
 
 }
 
diff --git a/sd/source/ui/remotecontrol/Receiver.hxx 
b/sd/source/ui/remotecontrol/Receiver.hxx
index d74a039..df736ad 100644
--- a/sd/source/ui/remotecontrol/Receiver.hxx
+++ b/sd/source/ui/remotecontrol/Receiver.hxx
@@ -19,6 +19,8 @@
 
 #include <vector>
 
+#include "Transmitter.hxx"
+
 namespace css = ::com::sun::star;
 
 namespace sd
@@ -27,18 +29,19 @@ namespace sd
 class Receiver
 {
 public:
-    Receiver();
+    Receiver( Transmitter *aTransmitter );
     ~Receiver();
-    void parseCommand( std::vector<rtl::OString> aCommand, osl::StreamSocket 
&aStreamSocket );
+    void parseCommand( std::vector<rtl::OString> aCommand );
 
 private:
+    Transmitter *mTransmitter;
 };
 
 }
 
 css::uno::Sequence<sal_Int8> preparePreview(sal_uInt32 aSlideNumber, 
css::uno::Reference<css::presentation::XSlideShowController> 
xSlideShowController, sal_uInt32 aWidth, sal_uInt32 aHeight, sal_uInt64 &aSize 
);
 
-void sendPreview(sal_uInt32 aSlideNumber, 
css::uno::Reference<css::presentation::XSlideShowController> 
xSlideShowController, osl::StreamSocket &mStreamSocket );
+void sendPreview(sal_uInt32 aSlideNumber, 
css::uno::Reference<css::presentation::XSlideShowController> 
xSlideShowController, sd::Transmitter *aTransmitter );
 
 #endif // _SD_IMPRESSREMOTE_RECEIVER_HXX
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/remotecontrol/Server.cxx 
b/sd/source/ui/remotecontrol/Server.cxx
index 0a8f875..f858a36 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -19,7 +19,7 @@ using namespace sd;
 using rtl::OString;
 
 Server::Server()
-:  Thread( "ServerThread" ), mSocket(), mReceiver()
+:  Thread( "ServerThread" ), mSocket()
 {
 }
 
@@ -30,15 +30,16 @@ Server::~Server()
 // Run as a thread
 void Server::listenThread()
 {
+    Transmitter aTransmitter( mStreamSocket );
+    Receiver aReceiver( &aTransmitter );
     // TODO: decryption
     while (true)
     {
         sal_uInt64 aRet, aRead;
         vector<char> aBuffer;
         vector<OString> aCommand;
-        sal_Bool finished = false;
         aRead = 0;
-        while ( !finished )
+        while ( true )
         {
             aBuffer.resize( aRead + 100 );
             aRet = mStreamSocket.recv( &aBuffer[aRead], 100 );
@@ -46,29 +47,23 @@ void Server::listenThread()
             {
                 return; // closed
             }
-            vector<char>::iterator aIt;
-            aIt = find( aBuffer.begin(), aBuffer.end(), '\n' ); // add aRead
             aRead += aRet;
-            if ( aIt == aBuffer.end() )
-            {
-                fprintf( stderr, "Continuing\n" );
-                continue;
-            }
-            fprintf( stderr, "parsing\n" );
-            sal_uInt64 aLocation = aIt - aBuffer.begin();
-
-            vector<char> aTemp( aLocation );
-            memcpy( &(*aTemp.begin()),  &(*aBuffer.begin()), aLocation );
-            aTemp.push_back( 0 );
-
-            aBuffer.erase( aBuffer.begin(), aBuffer.begin() + aLocation + 1 ); 
// Also delete the newline
-            aRead -= aLocation;
-
-            aCommand.push_back( OString( &(*aTemp.begin()) ) );
-            if ( (*aTemp.begin()) == 0 )
+            vector<char>::iterator aIt;
+            while ( (aIt = find( aBuffer.begin() + aRead - aRet, 
aBuffer.end(), '\n' ))
+                != aBuffer.end() )
             {
-                mReceiver.parseCommand( aCommand, mStreamSocket );
-                aCommand.clear();
+                fprintf( stderr, "we have string\n" );
+                sal_uInt64 aLocation = aIt - aBuffer.begin();
+
+                aCommand.push_back( OString( &(*aBuffer.begin()), aLocation ) 
);
+
+                if ( aIt == aBuffer.begin() )
+                {
+                    aReceiver.parseCommand( aCommand );
+                    aCommand.clear();
+                }
+                aBuffer.erase( aBuffer.begin(), aIt + 1 ); // Also delete the 
newline
+                aRead -= (aLocation + 1);
             }
         }
 
diff --git a/sd/source/ui/remotecontrol/Server.hxx 
b/sd/source/ui/remotecontrol/Server.hxx
index e953ff5..2b3c706 100644
--- a/sd/source/ui/remotecontrol/Server.hxx
+++ b/sd/source/ui/remotecontrol/Server.hxx
@@ -20,7 +20,7 @@
 
 #include <com/sun/star/presentation/XSlideShowListener.hpp>
 
-#include "Receiver.hxx"
+
 
 /**
 * The port for use for the main communication between LibO and remote control 
app.
@@ -35,7 +35,7 @@ namespace sd
     class Server : public salhelper::Thread
     {
         public:
-           static void setup();
+            static void setup();
         private:
             Server();
             ~Server();
@@ -43,7 +43,6 @@ namespace sd
             osl::AcceptorSocket mSocket;
             osl::StreamSocket mStreamSocket;
             void listenThread();
-            Receiver mReceiver;
             void execute();
     };
 }
diff --git a/sd/source/ui/remotecontrol/Transmitter.cxx 
b/sd/source/ui/remotecontrol/Transmitter.cxx
new file mode 100644
index 0000000..276fc89
--- /dev/null
+++ b/sd/source/ui/remotecontrol/Transmitter.cxx
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#include "Transmitter.hxx"
+
+using rtl::OString;
+using namespace std;
+using namespace osl; // Sockets etc.
+using namespace sd;
+
+Transmitter::Transmitter( StreamSocket &aSocket )
+  : Thread( "TransmitterThread" ),
+    mStreamSocket( aSocket ),
+    mQueuesNotEmpty(),
+    mQueueMutex()
+{
+    launch();
+    // Start a thread
+}
+
+void
+Transmitter::execute()
+{
+    while( mQueuesNotEmpty.wait() )
+    {
+        while ( true )
+        {
+            osl::MutexGuard aQueueGuard( mQueueMutex );
+            while ( mHighPriority.size() )
+            {
+                OString aMessage = mHighPriority.front();
+                mHighPriority.pop();
+                mStreamSocket.write( aMessage.getStr(), aMessage.getLength() );
+            }
+
+            if( mLowPriority.size() )
+            {
+                OString aMessage = mLowPriority.front();
+                mLowPriority.pop();
+                mStreamSocket.write( aMessage.getStr(), aMessage.getLength() );
+            }
+
+            //fprintf( stderr, "Lowsize:%i, Highsize:%i\n", 
mLowPriority.size(), mHighPriority.size() );
+            if ( (mLowPriority.size() == 0) && (mHighPriority.size() == 0) )
+            {
+                mQueuesNotEmpty.reset();
+                break;
+            }
+        }
+
+    }
+
+}
+
+Transmitter::~Transmitter()
+{
+
+}
+
+void Transmitter::addMessage( OString aMessage, Priority aPriority )
+{
+    osl::MutexGuard aQueueGuard( mQueueMutex );
+    switch ( aPriority )
+    {
+        case Priority::LOW:
+            mLowPriority.push( aMessage );
+            break;
+        case Priority::HIGH:
+            mHighPriority.push( aMessage );
+            break;
+    }
+    mQueuesNotEmpty.set();
+
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/sd/source/ui/remotecontrol/Transmitter.hxx 
b/sd/source/ui/remotecontrol/Transmitter.hxx
new file mode 100644
index 0000000..38f0534
--- /dev/null
+++ b/sd/source/ui/remotecontrol/Transmitter.hxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#ifndef _SD_IMPRESSREMOTE_TRANSMITTER_HXX
+#define _SD_IMPRESSREMOTE_TRANSMITTER_HXX
+
+#include <osl/conditn.hxx>
+#include <osl/mutex.hxx>
+#include <osl/socket.hxx>
+#include <salhelper/thread.hxx>
+#include <rtl/string.hxx>
+
+#include <queue>
+
+namespace sd
+{
+
+class Transmitter
+: public salhelper::Thread
+{
+public:
+    enum Priority { LOW = 1, HIGH };
+    Transmitter( osl::StreamSocket &aSocket );
+    ~Transmitter();
+    void addMessage( rtl::OString aMessage, Priority aPriority );
+
+private:
+    void execute();
+
+    osl::StreamSocket mStreamSocket;
+
+    osl::Condition mQueuesNotEmpty;
+
+    osl::Mutex mQueueMutex;
+
+    std::queue<rtl::OString> mLowPriority;
+    std::queue<rtl::OString> mHighPriority;
+};
+
+}
+#endif // _SD_IMPRESSREMOTE_TRANSMITTER_HXX
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to