android/sdremote/src/org/libreoffice/impressremote/TestClient.java | 10 - android/sdremote/src/org/libreoffice/impressremote/communication/Client.java | 9 android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java | 3 android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java | 3 android/sdremote/src/org/libreoffice/impressremote/communication/Transmitter.java | 34 --- sd/Library_sd.mk | 9 sd/source/ui/remotecontrol/Listener.cxx | 70 +++---- sd/source/ui/remotecontrol/Receiver.cxx | 93 +++------- sd/source/ui/remotecontrol/Receiver.hxx | 9 sd/source/ui/remotecontrol/Server.cxx | 69 +++---- 10 files changed, 116 insertions(+), 193 deletions(-)
New commits: commit c6173817835643550d4f6ddc8105c30a8e584773 Author: Andrzej J. R. Hunt <andr...@ahunt.org> Date: Thu Jul 12 22:10:33 2012 +0100 Pure text for Client->Server. Json removed. Namespace cleanup. Change-Id: I60e5acac2d47aefec5dd195a5eca599eb1cb8586 diff --git a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java index ff25d0f..83f4c71 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java +++ b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java @@ -1,5 +1,8 @@ package org.libreoffice.impressremote; +import java.util.ArrayList; +import java.util.HashMap; + import org.libreoffice.impressremote.communication.CommunicationService; import android.app.Activity; import android.content.ComponentName; @@ -21,6 +24,8 @@ import android.widget.TextView; public class TestClient extends Activity { + HashMap<Integer, Bitmap> aPreviewImages = new HashMap<Integer, Bitmap>(); + private boolean mIsBound = false; private CommunicationService mCommunicationService; @@ -139,12 +144,13 @@ public class TestClient extends Activity { // TODO: set slide; break; case CommunicationService.MSG_SLIDE_PREVIEW: - int slideNumber = aData.getInt("slide_number"); + int aSlideNumber = aData.getInt("slide_number"); byte[] aPreviewImage = aData.getByteArray("preview_image"); Bitmap aBitmap = BitmapFactory.decodeByteArray(aPreviewImage, 0, aPreviewImage.length); + aPreviewImages.put(aSlideNumber, aBitmap); mImageView.setImageBitmap(aBitmap); - // TODO: update + // TODO: remove above line, use slide changed to show image. break; } diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java index 47321e5..d4c1c4e 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java @@ -49,7 +49,6 @@ public abstract class Client { private void listen() { BufferedReader aReader; try { - System.out.println("deb:Listening"); aReader = new BufferedReader(new InputStreamReader(mInputStream, CHARSET)); while (true) { @@ -57,10 +56,8 @@ public abstract class Client { 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 (UnsupportedEncodingException e) { @@ -80,13 +77,7 @@ public abstract class Client { * Must be a valid JSON string. */ public void sendCommand(String command) { - String aLengthString = Integer.toString(command.length()); - byte[] aLengthBytes; try { - aLengthBytes = aLengthString.getBytes(CHARSET); - - mOutputStream.write(aLengthBytes); - mOutputStream.write(0x0d); mOutputStream.write(command.getBytes(CHARSET)); } catch (UnsupportedEncodingException e) { throw new Error("Specified network encoding [" + CHARSET diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java index 3a2b4bf..d8bd86d 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java @@ -18,13 +18,12 @@ public class NetworkClient extends Client { private Socket mSocket; public NetworkClient(String ipAddress) { + // FIXME: eventually networking will be fully threaded. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .permitAll().build(); StrictMode.setThreadPolicy(policy); - System.out.println("Attempting to open port."); try { mSocket = new Socket(ipAddress, PORT); - System.out.println("We seem to have opened."); mInputStream = mSocket.getInputStream(); mOutputStream = mSocket.getOutputStream(); startListening(); diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java index 40c491b..e26ef31 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java @@ -10,9 +10,6 @@ package org.libreoffice.impressremote.communication; import java.util.ArrayList; -import org.json.JSONException; -import org.json.JSONObject; - import android.os.Bundle; import android.os.Message; import android.os.Messenger; diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Transmitter.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Transmitter.java index 2861498..40bb918 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/Transmitter.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Transmitter.java @@ -1,8 +1,5 @@ package org.libreoffice.impressremote.communication; -import org.json.JSONException; -import org.json.JSONObject; - /** * Interface to send commands to the server. * @@ -17,39 +14,16 @@ public class Transmitter { } public void nextTransition() { - JSONObject aCommand = new JSONObject(); - try { - aCommand.put("command", "transition_next"); - } catch (JSONException e) { - e.printStackTrace(); - // TODO: clean - } - // Create JSON - mClient.sendCommand(aCommand.toString()); + mClient.sendCommand("transition_next\n\n"); } public void previousTransition() { - JSONObject aCommand = new JSONObject(); - try { - aCommand.put("command", "transition_previous"); - } catch (JSONException e) { - e.printStackTrace(); - // TODO: clean - } - // Create JSON - mClient.sendCommand(aCommand.toString()); + + mClient.sendCommand("transition_previous\n\n"); } public void gotoSlide(int slide) { - JSONObject aCommand = new JSONObject(); - try { - aCommand.put("command", "goto_slide"); - aCommand.put("slide_numer", slide); - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - mClient.sendCommand(aCommand.toString()); + mClient.sendCommand("goto_slide\n" + slide + "\n\n"); } } diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk index 2f2c4c5..9deaefb 100644 --- a/sd/Library_sd.mk +++ b/sd/Library_sd.mk @@ -27,10 +27,6 @@ $(eval $(call gb_Library_Library,sd)) -$(eval $(call gb_Library_use_externals,sd,\ - gtk \ -)) - $(eval $(call gb_SdiTarget_SdiTarget,sd/sdi/sdslots,sd/sdi/sdslots)) $(eval $(call gb_SdiTarget_set_include,sd/sdi/sdslots,\ @@ -63,7 +59,6 @@ $(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,\ @@ -113,10 +108,6 @@ $(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/Listener.cxx b/sd/source/ui/remotecontrol/Listener.cxx index 959b694..9679912 100644 --- a/sd/source/ui/remotecontrol/Listener.cxx +++ b/sd/source/ui/remotecontrol/Listener.cxx @@ -11,9 +11,6 @@ #include "Listener.hxx" -#include <glib-object.h> -#include <json-glib/json-glib.h> - using namespace sd; using namespace ::com::sun::star::presentation; using rtl::OString; @@ -25,9 +22,6 @@ Listener::Listener( const css::uno::Reference<XSlideShowController>& rxSlideShow mxSlideShowController(rxSlideShowController), mStreamSocket( aSocket ) { - g_type_init(); - - if( mxSlideShowController.is() ) { // Listen for events from the slide show controller. @@ -57,38 +51,38 @@ 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(); - - - json_builder_begin_object( aBuilder ); - json_builder_set_member_name( aBuilder, "slide_numer"); - json_builder_add_int_value( aBuilder, 2 ); - // FIXME: get the slide number - json_builder_end_object( aBuilder ); - - 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(); - - mStreamSocket.write( aLengthChar, aLengthLength ); - mStreamSocket.write( "\n", 1 ); - mStreamSocket.write( aCommand, aLen ); - // Transmit here. - - g_free( aCommand ); +// (void) bReverse; +// JsonBuilder *aBuilder = json_builder_new(); +// +// +// json_builder_begin_object( aBuilder ); +// json_builder_set_member_name( aBuilder, "slide_number"); +// json_builder_add_int_value( aBuilder, 2 ); +// // FIXME: get the slide number +// json_builder_end_object( aBuilder ); +// +// 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(); +// +// mStreamSocket.write( aLengthChar, aLengthLength ); +// mStreamSocket.write( "\n", 1 ); +// mStreamSocket.write( aCommand, aLen ); +// // Transmit here. +// +// g_free( aCommand ); } void SAL_CALL Listener::hyperLinkClicked (const rtl::OUString &) diff --git a/sd/source/ui/remotecontrol/Receiver.cxx b/sd/source/ui/remotecontrol/Receiver.cxx index 59fb4f2..7b527ac 100644 --- a/sd/source/ui/remotecontrol/Receiver.cxx +++ b/sd/source/ui/remotecontrol/Receiver.cxx @@ -25,54 +25,30 @@ using namespace ::com::sun::star; using rtl::OUString; using rtl::OString; using namespace ::osl; +using namespace std; Receiver::Receiver() { - g_type_init (); } Receiver::~Receiver() { } -void Receiver::executeCommand( JsonObject *aObject, - uno::Reference<presentation::XSlideShowController> xSlideShowController ) +void Receiver::parseCommand( std::vector<OString> aCommand, osl::StreamSocket &aStreamSocket ) { - const char* aInstruction = json_node_get_string( json_object_get_member( aObject, "command" ) ); - - fprintf( stderr, "instruction:%s\n", aInstruction ); - - if ( strcmp( aInstruction, "transition_next" ) == 0 ) - { - - xSlideShowController->gotoNextEffect(); - // Next slide; - } - else if ( strcmp( aInstruction, "transition_previous" ) == 0 ) - { - xSlideShowController->gotoPreviousEffect(); - } - else if ( strcmp( aInstruction, "goto_slide" ) == 0 ) - { - // - } - -} - -void Receiver::parseCommand( const char* aCommand, sal_Int32 size, osl::StreamSocket &aStreamSocket ) -{ - css::uno::Reference<css::presentation::XSlideShowController> xSlideShowController; + uno::Reference<presentation::XSlideShowController> xSlideShowController; try { - 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 ); - 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); + uno::Reference< lang::XMultiServiceFactory > xServiceManager( + ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XFramesSupplier > xFramesSupplier( xServiceManager->createInstance( + "com.sun.star.frame.Desktop" ) , uno::UNO_QUERY_THROW ); + uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_QUERY_THROW ); + uno::Reference<presentation::XPresentationSupplier> xPS ( xFrame->getController()->getModel(), uno::UNO_QUERY_THROW); + uno::Reference<presentation::XPresentation2> xPresentation(xPS->getPresentation(), uno::UNO_QUERY_THROW); // Throws an exception if now slideshow running - xSlideShowController = Reference<css::presentation::XSlideShowController>( - xPresentation->getController(), UNO_QUERY_THROW ); + xSlideShowController = uno::Reference<presentation::XSlideShowController>( + xPresentation->getController(), uno::UNO_QUERY_THROW ); // FIXME: remove later, this is just to test functionality sendPreview( 0, xSlideShowController, aStreamSocket ); } @@ -81,26 +57,20 @@ void Receiver::parseCommand( const char* aCommand, sal_Int32 size, osl::StreamSo return; } - // Parsing - JsonParser *parser; - JsonNode *root; - GError *error; - - 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 ); + if ( aCommand[0].compareTo( "transition_next" ) == 0 ) + { + xSlideShowController->gotoNextEffect(); + } + else if ( aCommand[0].compareTo( "transition_previous" ) == 0 ) + { + xSlideShowController->gotoPreviousEffect(); + } + else if ( aCommand[0].compareTo( "goto_slide" ) == 0 ) + { + // FIXME: if 0 returned, then not a valid number + sal_Int32 aSlide = aCommand[1].toInt32(); + xSlideShowController->gotoSlideIndex( aSlide ); } - - root = json_parser_get_root( parser ); - JsonObject *aObject = json_node_get_object( root ); - - executeCommand( aObject, xSlideShowController ); - - g_object_unref( parser ); } @@ -110,7 +80,7 @@ void sendPreview(sal_uInt32 aSlideNumber, { sal_uInt64 aSize; // Unused - css::uno::Sequence<sal_Int8> aImageData = preparePreview( aSlideNumber, xSlideShowController, 320, 240, aSize ); + uno::Sequence<sal_Int8> aImageData = preparePreview( aSlideNumber, xSlideShowController, 320, 240, aSize ); rtl::OUStringBuffer aStrBuffer; ::sax::Converter::encodeBase64( aStrBuffer, aImageData ); @@ -121,8 +91,7 @@ void sendPreview(sal_uInt32 aSlideNumber, // Start the writing mStreamSocket.write( "slide_preview\n", strlen( "slide_preview\n" ) ); - rtl::OString aSlideNumberString(rtl::OUStringToOString( - rtl::OUString::valueOf( 2 ) , RTL_TEXTENCODING_UTF8 )); // FIXME get number + rtl::OString aSlideNumberString( rtl::OString::valueOf( 2 ) ); // FIXME get number mStreamSocket.write( aSlideNumberString.getStr(), aSlideNumberString.getLength() ); mStreamSocket.write( "\n", 1 ); @@ -150,8 +119,8 @@ preparePreview(sal_uInt32 aSlideNumber, uno::Reference< document::XExporter > xExporter( xFilter, uno::UNO_QUERY_THROW ); - css::uno::Reference< css::lang::XComponent > xSourceDoc( - xSlideShowController->getSlideByIndex( aSlideNumber ) , css::uno::UNO_QUERY_THROW ); + uno::Reference< lang::XComponent > xSourceDoc( + xSlideShowController->getSlideByIndex( aSlideNumber ) , uno::UNO_QUERY_THROW ); xExporter->setSourceDocument( xSourceDoc ); @@ -166,7 +135,7 @@ preparePreview(sal_uInt32 aSlideNumber, aFilterData[2].Name = "ColorMode"; aFilterData[2].Value <<= sal_Int32(0); // Color - css::uno::Sequence< css::beans::PropertyValue > aProps(3); + uno::Sequence< beans::PropertyValue > aProps(3); aProps[0].Name = "MediaType"; aProps[0].Value <<= OUString( "image/png" ); @@ -187,7 +156,7 @@ preparePreview(sal_uInt32 aSlideNumber, sal_uInt64 aRead; rSize = 0; aFile.getSize( rSize ); - css::uno::Sequence<sal_Int8> aContents( rSize ); + uno::Sequence<sal_Int8> aContents( rSize ); aFile.read( aContents.getArray(), rSize, aRead ); aFile.close(); diff --git a/sd/source/ui/remotecontrol/Receiver.hxx b/sd/source/ui/remotecontrol/Receiver.hxx index 15919f3..d74a039 100644 --- a/sd/source/ui/remotecontrol/Receiver.hxx +++ b/sd/source/ui/remotecontrol/Receiver.hxx @@ -16,8 +16,8 @@ #include <com/sun/star/presentation/XPresentation2.hpp> #include <osl/socket.hxx> #include <stdlib.h> -#include <glib-object.h> -#include <json-glib/json-glib.h> + +#include <vector> namespace css = ::com::sun::star; @@ -29,12 +29,9 @@ class Receiver public: Receiver(); ~Receiver(); - void parseCommand( const char* aCommand, sal_Int32 size, osl::StreamSocket &aSocket ); - + void parseCommand( std::vector<rtl::OString> aCommand, osl::StreamSocket &aStreamSocket ); private: - void executeCommand( JsonObject *aObject, css::uno::Reference<css::presentation::XSlideShowController> aController ); - }; } diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx index e6b7d9f..0a8f875 100644 --- a/sd/source/ui/remotecontrol/Server.cxx +++ b/sd/source/ui/remotecontrol/Server.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include <stdlib.h> +#include <algorithm> #include <vector> #include "sddll.hxx" @@ -15,6 +16,7 @@ using namespace std; using namespace sd; +using rtl::OString; Server::Server() : Thread( "ServerThread" ), mSocket(), mReceiver() @@ -31,41 +33,44 @@ void Server::listenThread() // TODO: decryption while (true) { + sal_uInt64 aRet, aRead; vector<char> aBuffer; - char aReadBuffer[100]; - aRet = mStreamSocket.read - - - int aRet; - char aTemp; - while ( (aRet = mStreamSocket.read( &aTemp, 1)) && aTemp != 0x0d ) // look for newline - { - aBuffer.push_back( aTemp ); - } - if (aRet != 1) // Error reading or connection closed + vector<OString> aCommand; + sal_Bool finished = false; + aRead = 0; + while ( !finished ) { - return; + aBuffer.resize( aRead + 100 ); + aRet = mStreamSocket.recv( &aBuffer[aRead], 100 ); + if ( aRet == 0 ) + { + 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 ) + { + mReceiver.parseCommand( aCommand, mStreamSocket ); + aCommand.clear(); + } } - aBuffer.push_back('\0'); - rtl::OString aTempStr( &aBuffer.front() ); - - const sal_Char* aLengthChar = aTempStr.getStr(); - sal_Int32 aLen = strtol( aLengthChar, NULL, 10); - - char *aMessage = new char[aLen+1]; - aMessage[aLen] = '\0'; - - if( mStreamSocket.read( (void*) aMessage, aLen ) != aLen) // Error reading or connection closed - { - delete [] aMessage; - return; - } - - aTempStr = rtl::OString( aMessage ); //, (sal_Int32) aLen, CHARSET, 0u - const sal_Char* aCommandChar = aTempStr.getStr(); - - mReceiver.parseCommand( aCommandChar, aTempStr.getLength(), mStreamSocket ); - delete [] aMessage; // TODO: deal with transmision errors gracefully. } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits