diff options
author | Andrzej J. R. Hunt <andrzej@ahunt.org> | 2012-07-09 15:53:03 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2012-08-06 10:21:49 +0100 |
commit | 21b4fecc6107465b64b7e4c9cfedcd787b26fe3a (patch) | |
tree | d7d47121fd0bd1c69b09fc75c23cf4fc82dbc659 /sd | |
parent | 2ee2fa61c6335ab8117233648b486603d19bf611 (diff) |
Replaced Unix with osl sockets. Added slideshow controller.
Change-Id: Ic2d34d666bb748b12e51266e04706d105ab7a3be
Diffstat (limited to 'sd')
-rw-r--r-- | sd/Library_sd.mk | 6 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Receiver.cxx | 50 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Receiver.hxx | 17 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Server.cxx | 103 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/Server.hxx | 23 |
5 files changed, 106 insertions, 93 deletions
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk index a61de772776f..0fadcbfd2132 100644 --- a/sd/Library_sd.mk +++ b/sd/Library_sd.mk @@ -63,6 +63,7 @@ $(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,\ @@ -109,6 +110,11 @@ $(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/Receiver.cxx b/sd/source/ui/remotecontrol/Receiver.cxx index ea7a3442f8c7..7c6187f9ea03 100644 --- a/sd/source/ui/remotecontrol/Receiver.cxx +++ b/sd/source/ui/remotecontrol/Receiver.cxx @@ -25,7 +25,13 @@ * ************************************************************************/ #include "Receiver.hxx" - +#include <cstring> +#include <com/sun/star/frame/XFramesSupplier.hpp> +#include <comphelper/processfactory.hxx> +using namespace sd; +using namespace ::com::sun::star::presentation; +using namespace ::com::sun::star; +using namespace ::com::sun::star::frame; Receiver::Receiver() { g_type_init (); @@ -35,34 +41,48 @@ Receiver::~Receiver() { } -void Receiver::parseCommand(char* aCommand, XSlideShowController *aController) +void Receiver::parseCommand( char* aCommand, sal_Int32 size, XSlideShowController *aController ) { + 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(); + + Reference<XPresentationSupplier> xPS ( xFrame->getController()->getModel(), UNO_QUERY_THROW); + + Reference<XPresentation2> xPresentation(xPS->getPresentation(), UNO_QUERY_THROW); + + Reference<XSlideShowController> xSlideShowController(xPresentation->getController(), UNO_QUERY_THROW); + JsonParser *parser; JsonNode *root; GError *error; parser = json_parser_new (); error = NULL; - json_parser_load_from_data( parser, aCommand, aCommand.size, error ); + json_parser_load_from_data( parser, aCommand, size, &error ); if (error) { } root = json_parser_get_root( parser ); JsonObject *aObject = json_node_get_object( root ); - char* aInstruction = json_node_get_string( json_object_get_member( "command" ) ); + const char* aInstruction = json_node_get_string( json_object_get_member( aObject, "command" ) ); - switch ( aInstruction ) + if ( strcmp( aInstruction, "transition_next" ) ) { - case "transition_next": - aController->gotoNextEffect(); + xSlideShowController->gotoNextEffect(); // Next slide; - break; - case "transition_previous": - aController->gotoPreviousEffect(); - break; - case "goto_slide": - // - break; - }; + } + else if ( strcmp( aInstruction, "transition_previous" ) ) + { + xSlideShowController->gotoPreviousEffect(); + } + else if ( strcmp( aInstruction, "goto_slide" ) ) + { + + } + } diff --git a/sd/source/ui/remotecontrol/Receiver.hxx b/sd/source/ui/remotecontrol/Receiver.hxx index 9757946beb01..2466eb2ecb3d 100644 --- a/sd/source/ui/remotecontrol/Receiver.hxx +++ b/sd/source/ui/remotecontrol/Receiver.hxx @@ -3,19 +3,16 @@ #define _SD_IMPRESSREMOTE_RECEIVER_HXX #include <com/sun/star/presentation/XSlideShowController.hpp> - - +#include <com/sun/star/presentation/XPresentationSupplier.hpp> +#include <com/sun/star/presentation/XPresentation.hpp> +#include <com/sun/star/presentation/XPresentation2.hpp> #include <stdlib.h> #include <glib-object.h> #include <json-glib/json-glib.h> -// Library_sd.mk: -// $(eval $(call gb_Library_use_externals,sd,\ -// gobject \ -// )) - - +using namespace com::sun::star::presentation; +using namespace com::sun::star::uno; namespace sd { @@ -24,12 +21,12 @@ class Receiver public: Receiver(); ~Receiver(); - void parseCommand(char* aCommand, XSlideShowController *aController); + void parseCommand( char* aCommand, sal_Int32 size, XSlideShowController *aController ); private: -} +}; } diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx index ba0007ac9e1e..9ebe555fabd3 100644 --- a/sd/source/ui/remotecontrol/Server.cxx +++ b/sd/source/ui/remotecontrol/Server.cxx @@ -8,38 +8,19 @@ #include "Server.hxx" #include "Receiver.hxx" -#include <boost/thread.hpp> + + using namespace std; -using namespace sd::remotecontrol; +using namespace sd; +using rtl::OUString; +using rtl::OString; -Server::Server(char* aEncryptionKey, XSlideShowController aController) -: mReceiver() +Server::Server() +: Thread( "ServerThread" ), mSocket(), mStreamSocket(), mReceiver() { - if ( (mSocket = socket(AF_INET, SOCK_STREAM, 0)) == -1) - { - // Error opening - } - sockaddr_in aAddress; - aAddress.sin_family = AF_INET; - aAddress.sin_port = htons(PORT); - aAddress.sin_addr.s_addr = htonl(INADDR_ANY); - - if ( bind( mSocket, (struct sockaddr*) &aAddress, sizeof(aAddress) ) == -1 ) - { - // Error binding - } +// boost::thread t( boost::bind(&Server::listenThread, this )) - if ( listen ( mSocket, 3 ) == -1 ) - { - // Error listening - } - while (true) - { - mNewSocket = accept( mSocket, (struct sockaddr*) &aAddress, (socklen_t*) &aAddrLen ); - boost::thread t( boost::bind(&Server::listenThread, this )) - } - // TODO: pass mNewSocket to the thread. } Server::~Server() @@ -50,55 +31,67 @@ Server::~Server() void Server::listenThread() { char aTemp; - vector<char> aBuffer(); + vector<char> aBuffer; while (true) { - int aLength; - while ( recv( mSocket, *aTemp, 1, 0) && aTemp != 0x0d ) // look for newline + int aRet; + while ( (aRet = mStreamSocket.read( &aTemp, 1)) && aTemp != 0x0d ) // look for newline { aBuffer.push_back( aTemp ); // TODO: decryption } - OUString aLengthString = OUString( aBuffer.front(), aBuffer.size(), RTL_TEXTENCODING_UNICODE ); - const sal_Char* aLengthChar = aLengthString.convertToString( *aCLength, RTL_TEXTENCODING_ASCII_US, 0).getStr(); + 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(); - sal_uInt32 aLen = strtol( aLengthChar, NULL, 10); + sal_Int32 aLen = strtol( aLengthChar, NULL, 10); char *aMessage = new char[aLen]; - recv( mSocket, *aMessage, aLen, 0); + + if( mStreamSocket.read( (void*) aMessage, aLen ) != aLen)// Error reading or connection closed + { + return; + } // Parse. - mReceiver.parseCommand( aCommand ); + mReceiver.parseCommand( aMessage, aLen, NULL ); delete [] aMessage; + // TODO: deal with transmision errors gracefully. } } -// void Server::clientConnected() -// { -// our_mServerList.insert( our_mServerList.end, new Server() ); -// thread aThread = Boost::thread( listen ); -// -// } -// -// void Server::clientDisconnected() -// { -// our_mServerList::iterator aBegin = our_mServerList.begin; -// while ( *aBegin != this ) { -// aBegin++; -// } -// if ( *aBegin == this ) -// { -// our_mServerList.erase( this ); -// delete this; -// } -// } +void Server::execute() +{ + + osl::SocketAddr aAddr( "", PORT ); + if ( !mSocket.bind( aAddr ) ) + { + // Error binding + } + + if ( !mSocket.listen() ) + { + // Error listening + } + while ( true ) + { + mSocket.acceptConnection( mStreamSocket ); + listenThread(); + } +} void SdDLL::RegisterRemotes() { fprintf( stderr, "Register our remote control goodness\n" ); + Server server; + server.launch(); // FIXME: create a thread - // FIXME: convert the above socket code to use sal/inc/osl/socket.hxx etc. } diff --git a/sd/source/ui/remotecontrol/Server.hxx b/sd/source/ui/remotecontrol/Server.hxx index 0728954e507f..9aa9687a8595 100644 --- a/sd/source/ui/remotecontrol/Server.hxx +++ b/sd/source/ui/remotecontrol/Server.hxx @@ -10,9 +10,12 @@ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> - +#include <osl/socket.hxx> //#include <com/sun/star/presentation/AnimationEffect.hpp> +#include <salhelper/thread.hxx> + +#include "Receiver.hxx" /** * The port for use for the main communication between LibO and remote control app. @@ -20,28 +23,22 @@ #define PORT 1599 -class XSlideShowController; - -class Receiver; - namespace sd { - class Server + class Server : public salhelper::Thread { public: Server(); ~Server(); - void setPresentationController( XSlideShowController aController) { mController = aController; } private: - int mSocket; -// static vector<Server> our_mServerList; - - void listen(); + osl::AcceptorSocket mSocket; + osl::StreamSocket mStreamSocket; + void listenThread(); Receiver mReceiver; -// Transmitter mTransmitter; + void execute(); }; - } + } #endif // _SD_IMPRESSREMOTE_SERVER_HXX |