android/sdremote/src/org/libreoffice/impressremote/communication/Client.java   
|   80 +------
 android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java 
|   77 ++-----
 sd/source/ui/remotecontrol/Listener.cxx                                        
|    1 
 sd/source/ui/remotecontrol/Listener.hxx                                        
|    2 
 sd/source/ui/remotecontrol/Receiver.cxx                                        
|  108 +++-------
 sd/source/ui/remotecontrol/Server.cxx                                          
|   17 -
 sd/source/ui/remotecontrol/Server.hxx                                          
|    8 
 7 files changed, 101 insertions(+), 192 deletions(-)

New commits:
commit aebd43aebb9fa46dbeb690ad13bf8bc27bec8b5b
Author: Andrzej J. R. Hunt <andr...@ahunt.org>
Date:   Thu Jul 12 17:48:29 2012 +0100

    Intermediate commit for mmeeks.
    
    Change-Id: I4e8e4322d670247bc87e1b1ac6dccaa0a79a1e4d

diff --git a/sd/source/ui/remotecontrol/Listener.cxx 
b/sd/source/ui/remotecontrol/Listener.cxx
index 699d7a6..959b694 100644
--- a/sd/source/ui/remotecontrol/Listener.cxx
+++ b/sd/source/ui/remotecontrol/Listener.cxx
@@ -57,6 +57,7 @@ void SAL_CALL Listener::resumed (void)
 void SAL_CALL Listener::slideEnded (sal_Bool bReverse)
     throw (css::uno::RuntimeException)
 {
+    (void) bReverse;
     JsonBuilder *aBuilder = json_builder_new();
 
 
diff --git a/sd/source/ui/remotecontrol/Server.cxx 
b/sd/source/ui/remotecontrol/Server.cxx
index d838b67..04c51bd 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -7,20 +7,13 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 #include <stdlib.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
 #include <vector>
 
 #include "sddll.hxx"
 #include "Server.hxx"
-#include "Receiver.hxx"
-
-
 
 using namespace std;
 using namespace sd;
-using rtl::OUString;
-using rtl::OString;
 
 Server::Server()
 :  Thread( "ServerThread" ), mSocket(), mReceiver()
@@ -38,6 +31,10 @@ void Server::listenThread()
     while (true)
     {
         vector<char> aBuffer;
+        char aReadBuffer[100];
+        aRet = mStreamSocket.read
+
+
         int aRet;
         char aTemp;
         while ( (aRet = mStreamSocket.read( &aTemp, 1)) && aTemp != 0x0d ) // 
look for newline
@@ -49,7 +46,7 @@ void Server::listenThread()
             return;
         }
         aBuffer.push_back('\0');
-        OString aTempStr( &aBuffer.front() );
+        rtl::OString aTempStr( &aBuffer.front() );
 
         const sal_Char* aLengthChar = aTempStr.getStr();
         sal_Int32 aLen = strtol( aLengthChar, NULL, 10);
@@ -63,7 +60,7 @@ void Server::listenThread()
             return;
         }
 
-        aTempStr = OString( aMessage ); //, (sal_Int32) aLen, CHARSET, 0u
+        aTempStr = rtl::OString( aMessage ); //, (sal_Int32) aLen, CHARSET, 0u
         const sal_Char* aCommandChar = aTempStr.getStr();
 
         mReceiver.parseCommand( aCommandChar, aTempStr.getLength(), 
mStreamSocket );
@@ -96,8 +93,6 @@ void Server::execute()
 
 }
 
-
-
 Server *sd::Server::spServer = NULL;
 
 void Server::setup()
diff --git a/sd/source/ui/remotecontrol/Server.hxx 
b/sd/source/ui/remotecontrol/Server.hxx
index 1ee1885..e953ff5 100644
--- a/sd/source/ui/remotecontrol/Server.hxx
+++ b/sd/source/ui/remotecontrol/Server.hxx
@@ -14,13 +14,12 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
-#include <netinet/in.h>
+
 #include <osl/socket.hxx>
+#include <salhelper/thread.hxx>
 
 #include <com/sun/star/presentation/XSlideShowListener.hpp>
 
-#include <salhelper/thread.hxx>
-
 #include "Receiver.hxx"
 
 /**
commit b26d6f459fde2885c34ba566b588ee1f4868eebe
Author: Andrzej J. R. Hunt <andr...@ahunt.org>
Date:   Thu Jul 12 17:22:12 2012 +0100

    Changed from JSON to plaintext for Server->Client. Namespace usage cleanup.
    
    Change-Id: I7e1b229b475e476c71ec3a110696942299b25733

diff --git 
a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java 
b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java
index 049950a..47321e5 100644
--- 
a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java
+++ 
b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java
@@ -1,9 +1,12 @@
 package org.libreoffice.impressremote.communication;
 
+import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
 
 import org.apache.http.util.ByteArrayBuffer;
 import org.json.JSONException;
@@ -44,69 +47,28 @@ public abstract class Client {
        }
 
        private void listen() {
-               while (true) {
-                       ByteArrayBuffer aBuffer = new ByteArrayBuffer(0);
-                       int aTemp;
-                       System.out.println("Now listening");
-                       try {
-                               while ((aTemp =  mInputStream.read()) != 0x0a) {
-                                       if (aTemp == -1) {
-                                               System.out.println("EOF 
Reached!!!");
-                                       }
-                                       System.out.println("Char: " + aTemp);
-                                       aBuffer.append((byte) aTemp);
-                               }
-                       } catch (IOException e1) {
-                               // TODO stream couldn't be opened.
-                               e1.printStackTrace();
-                       }
-                       System.out.println("Escaped the loop!");
-                       String aLengthString;
-                       try {
-                               aLengthString = new 
String(aBuffer.toByteArray(), CHARSET);
-                       } catch (Exception e1) {
-                               e1.printStackTrace();
-                               throw new Error("Specified network encoding [" 
+ CHARSET
-                                               + " not available.");
-                       }
-
-                       int aLength = Integer.parseInt(aLengthString);
-                       System.out.println("Lenth = " + aLength);
-                       byte[] aCommand = new byte[aLength];
-                       try {
-                               int readIn = 0;
-                               while (readIn < aLength) {
-                                       readIn += mInputStream.read(aCommand, 
0, aLength - readIn);
-//                                     System.out.println("Read in :" + readIn 
+ " of : "
-//                                                     + aLength);
-                               }
-                       } catch (IOException e) {
-                               // TODO close and notify that the connection 
has closed
-                               e.printStackTrace();
-                       }
-                       String aCommandString;
-                       try {
-                               aCommandString = new String(aCommand, CHARSET);
-                       } catch (UnsupportedEncodingException e) {
-                               throw new Error("Specified network encoding [" 
+ CHARSET
-                                               + " not available.");
-                       }
-                       mReceiver.parseCommand(aCommandString);
-               }
-       }
-
-       private void parseCommand(String aCommand) {
-               JSONObject aCommandObject;
-               String aInstruction;
+               BufferedReader aReader;
                try {
-                       aCommandObject = new JSONObject(aCommand);
-                       aInstruction = aCommandObject.getString("command");
-                       if (aInstruction.equals("slide_changed")) {
-                               // TODO: process and notify
+                       System.out.println("deb:Listening");
+                       aReader = new BufferedReader(new 
InputStreamReader(mInputStream,
+                                       CHARSET));
+                       while (true) {
+                               ArrayList<String> aList = new 
ArrayList<String>();
+                               String aTemp;
+                               // read until empty line
+                               while ((aTemp = aReader.readLine()).length() != 
0) {
+                                       System.out.println("deb__:" + aTemp);
+                                       aList.add(aTemp);
+                               }
+                               System.out.println("deb:parsing");
+                               mReceiver.parseCommand(aList);
                        }
-               } catch (JSONException e) {
+               } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
+               } catch (IOException e1) {
+                       // TODO stream couldn't be opened.
+                       e1.printStackTrace();
                }
 
        }
diff --git 
a/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java
 
b/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java
index a46cd4f..40c491b 100644
--- 
a/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java
+++ 
b/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java
@@ -8,6 +8,8 @@
  */
 package org.libreoffice.impressremote.communication;
 
+import java.util.ArrayList;
+
 import org.json.JSONException;
 import org.json.JSONObject;
 
@@ -25,57 +27,40 @@ public class Receiver {
                mActivityMessenger = aActivityMessenger;
        }
 
-       public void parseCommand(String aJSONCommandString) {
+       public void parseCommand(ArrayList<String> aCommand) {
                if (mActivityMessenger == null) {
                        return;
                }
-               try {
-//                     int aPrinted = 0;
-//                     while (aPrinted < aJSONCommandString.length()) {
-//                             if (aPrinted + 100 < 
aJSONCommandString.length())
-//                                     
System.out.println(aJSONCommandString.substring(aPrinted,
-//                                                     aPrinted + 100));
-//                             else
-//                                     
System.out.println(aJSONCommandString.substring(aPrinted));
-//                             aPrinted += 100;
-//                     }
-
-                       JSONObject aJSONCommand = new 
JSONObject(aJSONCommandString);
-                       String aInstruction = aJSONCommand.getString("command");
-                       if (aInstruction.equals("slide_updated")) {
-                               int aSlideNumber = 
aJSONCommand.getInt("slide_number");
-                               Message aMessage = Message.obtain(null,
-                                               
CommunicationService.MSG_SLIDE_CHANGED);
-                               Bundle aData = new Bundle();
-                               aData.putInt("slide_number", aSlideNumber);
-                               aMessage.setData(aData);
-                               try {
-                                       mActivityMessenger.send(aMessage);
-                               } catch (RemoteException e) {
-                                       // TODO Auto-generated catch block
-                                       e.printStackTrace();
-                               }
-                       } else if (aInstruction.equals("slide_preview")) {
-                               int aSlideNumber = 
aJSONCommand.getInt("slide_number");
-                               String aImageString = 
aJSONCommand.getString("image_preview");
-                               byte[] aImage = Base64.decode(aImageString, 
Base64.DEFAULT);
-                               Message aMessage = Message.obtain(null,
-                                               
CommunicationService.MSG_SLIDE_PREVIEW);
-                               Bundle aData = new Bundle();
-                               aData.putInt("slide_number", aSlideNumber);
-                               aData.putByteArray("preview_image", aImage);
-                               aMessage.setData(aData);
-                               try {
-                                       mActivityMessenger.send(aMessage);
-                               } catch (RemoteException e) {
-                                       // TODO Auto-generated catch block
-                                       e.printStackTrace();
-                               }
+               String aInstruction = aCommand.get(0);
+               if (aInstruction.equals("slide_updated")) {
+                       int aSlideNumber = Integer.parseInt(aCommand.get(1));
+                       Message aMessage = Message.obtain(null,
+                                       CommunicationService.MSG_SLIDE_CHANGED);
+                       Bundle aData = new Bundle();
+                       aData.putInt("slide_number", aSlideNumber);
+                       aMessage.setData(aData);
+                       try {
+                               mActivityMessenger.send(aMessage);
+                       } catch (RemoteException e) {
+                               // Dead Handler -- i.e. Activity gone.
+                       }
+               } else if (aInstruction.equals("slide_preview")) {
+                       int aSlideNumber = Integer.parseInt(aCommand.get(1));
+                       String aImageString = aCommand.get(2);
+                       byte[] aImage = Base64.decode(aImageString, 
Base64.DEFAULT);
+                       Message aMessage = Message.obtain(null,
+                                       CommunicationService.MSG_SLIDE_PREVIEW);
+                       Bundle aData = new Bundle();
+                       aData.putInt("slide_number", aSlideNumber);
+                       aData.putByteArray("preview_image", aImage);
+                       aMessage.setData(aData);
+                       try {
+                               mActivityMessenger.send(aMessage);
+                       } catch (RemoteException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
                        }
 
-               } catch (JSONException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
                }
 
        }
diff --git a/sd/source/ui/remotecontrol/Listener.hxx 
b/sd/source/ui/remotecontrol/Listener.hxx
index 2009074..8b2b97f 100644
--- a/sd/source/ui/remotecontrol/Listener.hxx
+++ b/sd/source/ui/remotecontrol/Listener.hxx
@@ -18,8 +18,6 @@
 #include <osl/socket.hxx>
 
 namespace css = ::com::sun::star;
-//using namespace ::com::sun::star::presentation;
-
 namespace sd {
 class Listener
     : protected ::cppu::BaseMutex,
diff --git a/sd/source/ui/remotecontrol/Receiver.cxx 
b/sd/source/ui/remotecontrol/Receiver.cxx
index 9015d79..06c9328 100644
--- a/sd/source/ui/remotecontrol/Receiver.cxx
+++ b/sd/source/ui/remotecontrol/Receiver.cxx
@@ -20,11 +20,12 @@
 #include <rtl/ustrbuf.hxx>
 #include <sax/tools/converter.hxx>
 using namespace sd;
-using namespace ::com::sun::star::presentation;
-using namespace ::com::sun::star;
-using namespace ::com::sun::star::frame;
-using namespace ::com::sun::star::beans;
-using namespace ::com::sun::star::document;
+// using namespace ::com::sun::star::presentation;
+// using namespace ::com::sun::star;
+// using namespace ::com::sun::star::frame;
+// using namespace ::com::sun::star::beans;
+// using namespace ::com::sun::star::document;
+namespace css = ::com::sun::star;
 using rtl::OUString;
 using rtl::OString;
 using namespace ::osl;
@@ -38,7 +39,7 @@ Receiver::~Receiver()
 {
 }
 
-void Receiver::executeCommand( JsonObject *aObject, 
Reference<XSlideShowController> xSlideShowController )
+void Receiver::executeCommand( JsonObject *aObject, 
css::uno::Reference<css::presentation::XSlideShowController> 
xSlideShowController )
 {
     const char* aInstruction = json_node_get_string( json_object_get_member( 
aObject, "command" ) );
 
@@ -63,18 +64,20 @@ void Receiver::executeCommand( JsonObject *aObject, 
Reference<XSlideShowControll
 
 void Receiver::parseCommand( const char* aCommand, sal_Int32 size, 
osl::StreamSocket &aStreamSocket )
 {
-    Reference<XSlideShowController> xSlideShowController;
+    css::uno::Reference<css::presentation::XSlideShowController> 
xSlideShowController;
     try {
-        uno::Reference< lang::XMultiServiceFactory > xServiceManager(
-            ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
-        uno::Reference< XFramesSupplier > xFramesSupplier( 
xServiceManager->createInstance(
+        css::uno::Reference< css::lang::XMultiServiceFactory > xServiceManager(
+            ::comphelper::getProcessServiceFactory(), 
css::uno::UNO_QUERY_THROW );
+        css::uno::Reference< css::frame::XFramesSupplier > xFramesSupplier( 
xServiceManager->createInstance(
         "com.sun.star.frame.Desktop" ) , UNO_QUERY_THROW );
-        uno::Reference< frame::XFrame > xFrame ( 
xFramesSupplier->getActiveFrame(), UNO_QUERY_THROW );
+        css::uno::Reference< css::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 );
-       sendPreview( 1, xSlideShowController, aStreamSocket );
+        xSlideShowController =  
Reference<css::presentation::XSlideShowController>(
+           xPresentation->getController(), UNO_QUERY_THROW );
+        // FIXME: remove later, this is just to test functionality
+        sendPreview( 0, xSlideShowController, aStreamSocket );
     }
     catch ( com::sun::star::uno::RuntimeException &e )
     {
@@ -108,59 +111,26 @@ void Receiver::parseCommand( const char* aCommand, 
sal_Int32 size, osl::StreamSo
 void sendPreview(sal_uInt32 aSlideNumber, Reference<XSlideShowController> 
xSlideShowController, osl::StreamSocket &mStreamSocket )
 {
 
-    sal_uInt64 aSize;
-
-    uno::Sequence<sal_Int8> aData = preparePreview( aSlideNumber, 
xSlideShowController, 320, 240, aSize );
+    sal_uInt64 aSize; // Unused
+    css::uno::Sequence<sal_Int8> aImageData = preparePreview( aSlideNumber, 
xSlideShowController, 320, 240, aSize );
 
     rtl::OUStringBuffer aStrBuffer;
-//     char* aDataEncoded = (char*) xmlSecBase64Encode( (xmlSecByte *) aData, 
aSize, 0 );
-    ::sax::Converter::encodeBase64( aStrBuffer, aData );
-
-    OUString aEncodedString = aStrBuffer.makeStringAndClear();
-    OString aEncodedShortString = rtl::OUStringToOString( aEncodedString, 
RTL_TEXTENCODING_UTF8 );
-//     aEncodedString.convertToString( &aEncodedShortString, 
RTL_TEXTENCODING_UTF8 , 0);
-
-    JsonBuilder *aBuilder = json_builder_new();
-
-
-    json_builder_begin_object( aBuilder );
-
-    json_builder_set_member_name( aBuilder, "command" );
-    json_builder_add_string_value( aBuilder, "slide_preview" );
-
-    json_builder_set_member_name( aBuilder, "slide_number" );
-    json_builder_add_int_value( aBuilder, 2 );
+    ::sax::Converter::encodeBase64( aStrBuffer, aImageData );
 
-    json_builder_set_member_name( aBuilder, "image_preview" );
-    json_builder_add_string_value( aBuilder, aEncodedShortString.getStr() );
+    OString aEncodedShortString = rtl::OUStringToOString(
+        aStrBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
 
-    // FIXME: get the slide number
-    json_builder_end_object( aBuilder );
+    // Start the writing
+    mStreamSocket.write( "slide_preview\n", strlen( "slide_preview\n" ) );
 
-    JsonGenerator *aGen = json_generator_new();
-    JsonNode *aRoot = json_builder_get_root( aBuilder );
-    json_generator_set_root( aGen, aRoot );
-    char *aCommand = json_generator_to_data( aGen, NULL);
-
-    json_node_free( aRoot );
-    g_object_unref ( aGen );
-    g_object_unref ( aBuilder );
-
-    sal_Int32 aLen = strlen( aCommand );
-
-    OString aLengthString = OString::valueOf( aLen );
-    const char *aLengthChar = aLengthString.getStr();
-
-    sal_Int32 aLengthLength = aLengthString.getLength();
-
-    fprintf( stderr, "%s\n", aCommand );
-
-    mStreamSocket.write( aLengthChar, aLengthLength );
+    rtl::OString aSlideNumberString(rtl::OUStringToOString(
+        rtl::OUString::valueOf( 2 ) , RTL_TEXTENCODING_UTF8 )); // FIXME get 
number
+    mStreamSocket.write( aSlideNumberString.getStr(), 
aSlideNumberString.getLength() );
     mStreamSocket.write( "\n", 1 );
-    mStreamSocket.write( aCommand, aLen );
-    // Transmit here.
 
-    g_free( aCommand );
+    mStreamSocket.write( aEncodedShortString.getStr(), 
aEncodedShortString.getLength() );
+    mStreamSocket.write( "\n\n", 2 );
+
 
 }
 
@@ -172,21 +142,21 @@ Sequence<sal_Int8> preparePreview(sal_uInt32 
aSlideNumber, Reference<XSlideShowC
     FileBase::createTempFile( 0, 0, &aFileURL );
 
 
-    uno::Reference< lang::XMultiServiceFactory > xServiceManager(
-            ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
+    css::uno::Reference< css::lang::XMultiServiceFactory > xServiceManager(
+            ::comphelper::getProcessServiceFactory(), 
css::uno::UNO_QUERY_THROW );
 
-    uno::Reference< XFilter > xFilter( xServiceManager->createInstance(
-        "com.sun.star.drawing.GraphicExportFilter"  ) , UNO_QUERY_THROW );
+    css::uno::Reference< css::document::XFilter > xFilter( 
xServiceManager->createInstance(
+        "com.sun.star.drawing.GraphicExportFilter"  ) , 
css::uno::UNO_QUERY_THROW );
 
-    uno::Reference< XExporter > xExporter( xFilter, uno::UNO_QUERY_THROW );
+    css::uno::Reference< css::document::XExporter > xExporter( xFilter, 
css::uno::UNO_QUERY_THROW );
 
 
-    uno::Reference< lang::XComponent > xSourceDoc(
-        xSlideShowController->getSlideByIndex( aSlideNumber ) , 
uno::UNO_QUERY_THROW );
+    css::uno::Reference< css::lang::XComponent > xSourceDoc(
+        xSlideShowController->getSlideByIndex( aSlideNumber ) , 
css::uno::UNO_QUERY_THROW );
 
     xExporter->setSourceDocument( xSourceDoc );
 
-    Sequence< beans::PropertyValue > aFilterData(3);
+    css::uno::Sequence< css::beans::PropertyValue > aFilterData(3);
     aFilterData[0].Name = "PixelWidth";
     aFilterData[0].Value <<= 2000;
     aFilterData[1].Name = "PixelHeight";
@@ -197,7 +167,7 @@ Sequence<sal_Int8> preparePreview(sal_uInt32 aSlideNumber, 
Reference<XSlideShowC
     aFilterData[2].Name = "ColorMode";
     aFilterData[2].Value <<= 0; // Color
 
-    uno::Sequence< beans::PropertyValue > aProps(3);
+    css::uno::Sequence< css::beans::PropertyValue > aProps(3);
     aProps[0].Name = "MediaType";
     aProps[0].Value <<= OUString( "image/png" );
 
@@ -218,7 +188,7 @@ Sequence<sal_Int8> preparePreview(sal_uInt32 aSlideNumber, 
Reference<XSlideShowC
     sal_uInt64 aRead;
     rSize = 0;
     aFile.getSize( rSize );
-    uno::Sequence<sal_Int8> aContents( rSize );
+    css::uno::Sequence<sal_Int8> aContents( rSize );
 
     aFile.read( aContents.getArray(), rSize, aRead );
     aFile.close();
diff --git a/sd/source/ui/remotecontrol/Server.hxx 
b/sd/source/ui/remotecontrol/Server.hxx
index ba6f8cd..1ee1885 100644
--- a/sd/source/ui/remotecontrol/Server.hxx
+++ b/sd/source/ui/remotecontrol/Server.hxx
@@ -12,12 +12,11 @@
 // SERVER
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <osl/socket.hxx>
-//#include <com/sun/star/presentation/AnimationEffect.hpp>
+
 #include <com/sun/star/presentation/XSlideShowListener.hpp>
 
 #include <salhelper/thread.hxx>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to