summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorAndrzej J. R. Hunt <andrzej@ahunt.org>2012-07-10 16:36:04 +0100
committerMichael Meeks <michael.meeks@suse.com>2012-08-06 10:22:54 +0100
commit0bb13b5e6163b963783ec46bd68c349392945e63 (patch)
tree552401e55824a618e9881940551fe8de69d11373 /sd
parentfa94d976596c4f0d2ffb03a8babbb7a573772621 (diff)
Fixed remote control code to work correctly.
Change-Id: I Ia600ed456fba135056f7a00398030b7c9e873329
Diffstat (limited to 'sd')
-rw-r--r--sd/source/ui/remotecontrol/Receiver.cxx82
-rw-r--r--sd/source/ui/remotecontrol/Receiver.hxx4
-rw-r--r--sd/source/ui/remotecontrol/Server.cxx36
-rw-r--r--sd/source/ui/remotecontrol/Server.hxx1
4 files changed, 81 insertions, 42 deletions
diff --git a/sd/source/ui/remotecontrol/Receiver.cxx b/sd/source/ui/remotecontrol/Receiver.cxx
index 7c6187f9ea03..a2120b1a7d64 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 2466eb2ecb3d..d4087e461285 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 00ecd2acc78b..b4c061334667 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 46bac2d66905..65b416b52b93 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
{