Changed from JSON to plaintext for Server->Client. Namespace usage cleanup.
Change-Id: I7e1b229b475e476c71ec3a110696942299b25733
This commit is contained in:
parent
9d7d8eb7a8
commit
dbe8d48227
5 changed files with 92 additions and 178 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 );
|
||||
::sax::Converter::encodeBase64( aStrBuffer, aImageData );
|
||||
|
||||
OUString aEncodedString = aStrBuffer.makeStringAndClear();
|
||||
OString aEncodedShortString = rtl::OUStringToOString( aEncodedString, RTL_TEXTENCODING_UTF8 );
|
||||
// aEncodedString.convertToString( &aEncodedShortString, RTL_TEXTENCODING_UTF8 , 0);
|
||||
OString aEncodedShortString = rtl::OUStringToOString(
|
||||
aStrBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
|
||||
|
||||
JsonBuilder *aBuilder = json_builder_new();
|
||||
// Start the writing
|
||||
mStreamSocket.write( "slide_preview\n", strlen( "slide_preview\n" ) );
|
||||
|
||||
|
||||
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 );
|
||||
|
||||
json_builder_set_member_name( aBuilder, "image_preview" );
|
||||
json_builder_add_string_value( aBuilder, aEncodedShortString.getStr() );
|
||||
|
||||
// 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();
|
||||
|
||||
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();
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue