[Libreoffice-commits] .: Branch 'feature/remote' - 4 commits - sd/Library_sd.mk sd/source

Andrzej J.R. Hunt ajrhunt at kemper.freedesktop.org
Thu Aug 2 04:31:55 PDT 2012


 sd/Library_sd.mk                                |    1 
 sd/source/ui/remotecontrol/DiscoveryService.cxx |   89 ++++++++++++
 sd/source/ui/remotecontrol/DiscoveryService.hxx |   52 +++++++
 sd/source/ui/remotecontrol/ImagePreparer.cxx    |  175 +++++++++++++++++-------
 sd/source/ui/remotecontrol/Server.cxx           |    2 
 5 files changed, 275 insertions(+), 44 deletions(-)

New commits:
commit 96fa4ace05c7c324227b0d4d152c466e0ef3c522
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Thu Aug 2 12:27:19 2012 +0200

    Discovery service implemented server side.
    
    Change-Id: I26c26ae96680c6264d7b927cb9206073239f2ef4

diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx
index f92b9ee..1ded965 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.cxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx
@@ -11,10 +11,14 @@
 #include <vector>
 
 #include <comphelper/processfactory.hxx>
+#include <rtl/strbuf.hxx>
 
 #include "DiscoveryService.hxx"
 
+using namespace osl;
+using namespace rtl;
 using namespace sd;
+using namespace std;
 
 DiscoveryService::DiscoveryService()
     :
@@ -28,10 +32,47 @@ DiscoveryService::~DiscoveryService()
 }
 
 
+void DiscoveryService::replyTo( SocketAddr& rAddr )
+{
+    SocketAddr aLocalAddr;
+    mSocket.getLocalAddr( aLocalAddr );
+    OString aAddrString = OUStringToOString( aLocalAddr.getHostname(),
+                                             RTL_TEXTENCODING_UTF8 );
+    OStringBuffer aBuffer( "LOREMOTE_ADVERTISE\n" );
+    aBuffer.append( aAddrString ).append( "\n" );
+    mSocket.sendTo( rAddr, aBuffer.getStr(), aBuffer.getLength() );
+}
 
 void DiscoveryService::execute()
 {
+    sal_uInt64 aRet, aRead;
+    vector<char> aBuffer;
+    aRead = 0;
 
+    SocketAddr aAddr;
+    while ( true )
+    {
+        aBuffer.resize( aRead + 100 );
+        aRet = mSocket.recvFrom( &aBuffer[aRead], 100 );
+        if ( aRet == 0 )
+        {
+            fprintf( stderr, "Socket returned 0\n" );
+//             break; // I.e. transmission finished.
+        }
+        aRead += aRet;
+        vector<char>::iterator aIt;
+        while ( (aIt = find( aBuffer.begin(), aBuffer.end(), '\n' ))
+            != aBuffer.end() )
+        {
+            sal_uInt64 aLocation = aIt - aBuffer.begin();
+            OString aString( &(*aBuffer.begin()), aLocation );
+            if ( aString.compareTo( "LOREMOTE_SEARCH" ) == 0 ) {
+                replyTo( aAddr );
+            }
+            aBuffer.erase( aBuffer.begin(), aIt + 1 ); // Also delete the newline
+            aRead -= (aLocation + 1);
+        }
+    }
 }
 
 DiscoveryService *sd::DiscoveryService::spService = NULL;
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.hxx b/sd/source/ui/remotecontrol/DiscoveryService.hxx
index 863ebb5..aa4b349 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.hxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.hxx
@@ -38,11 +38,13 @@ namespace sd
         private:
             DiscoveryService();
             ~DiscoveryService();
+
             static DiscoveryService *spService;
+            void execute();
 
             osl::DatagramSocket mSocket;
+            void replyTo( osl::SocketAddr& rAddr );
 
-            void execute();
     };
 }
 
commit d17346b830bbb00ce1a5dc5c829b1f4e3d621672
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Thu Aug 2 11:28:38 2012 +0200

    Basic structure for Disovery Service.
    
    Change-Id: Idaae84c46fa96b128ab32451853922c9eb11c6cc

diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index 4847abf..43e42d7 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -320,6 +320,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\
     sd/source/ui/presenter/PresenterPreviewCache \
     sd/source/ui/presenter/PresenterTextView \
     sd/source/ui/presenter/SlideRenderer \
+    sd/source/ui/remotecontrol/DiscoveryService \
     sd/source/ui/remotecontrol/ImagePreparer \
     sd/source/ui/remotecontrol/Server \
     sd/source/ui/remotecontrol/Receiver \
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx
new file mode 100644
index 0000000..f92b9ee
--- /dev/null
+++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#include <stdlib.h>
+#include <algorithm>
+#include <vector>
+
+#include <comphelper/processfactory.hxx>
+
+#include "DiscoveryService.hxx"
+
+using namespace sd;
+
+DiscoveryService::DiscoveryService()
+    :
+    Thread( "sd::DiscoveryService" ),
+    mSocket()
+{
+}
+
+DiscoveryService::~DiscoveryService()
+{
+}
+
+
+
+void DiscoveryService::execute()
+{
+
+}
+
+DiscoveryService *sd::DiscoveryService::spService = NULL;
+
+void DiscoveryService::setup()
+{
+  if (spService)
+    return;
+
+  spService = new DiscoveryService();
+  spService->launch();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.hxx b/sd/source/ui/remotecontrol/DiscoveryService.hxx
new file mode 100644
index 0000000..863ebb5
--- /dev/null
+++ b/sd/source/ui/remotecontrol/DiscoveryService.hxx
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#ifndef _SD_IMPRESSREMOTE_DISCOVERYSERVICE_HXX
+#define _SD_IMPRESSREMOTE_DISCOVERYSERVICE_HXX
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <osl/socket.hxx>
+#include <rtl/ref.hxx>
+#include <salhelper/thread.hxx>
+
+namespace css = ::com::sun::star;
+
+/**
+* The port for use for the main communication between LibO and remote control app.
+*/
+#define PORT_DISCOVERY 1598
+
+#define CHARSET RTL_TEXTENCODING_UTF8
+
+namespace sd
+{
+
+    class DiscoveryService : public salhelper::Thread
+    {
+        public:
+            static void setup();
+
+        private:
+            DiscoveryService();
+            ~DiscoveryService();
+            static DiscoveryService *spService;
+
+            osl::DatagramSocket mSocket;
+
+            void execute();
+    };
+}
+
+#endif // _SD_IMPRESSREMOTE_DISCOVERYSERVICE_HXX
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx
index 3b896fe..372103e 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -14,6 +14,7 @@
 
 #include "sddll.hxx"
 
+#include "DiscoveryService.hxx"
 #include "ImagePreparer.hxx"
 #include "Listener.hxx"
 #include "Receiver.hxx"
@@ -161,6 +162,7 @@ void SdDLL::RegisterRemotes()
 {
   fprintf( stderr, "Register our remote control goodness\n" );
   sd::RemoteServer::setup();
+  sd::DiscoveryService::setup();
 
 }
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 208cff2111c9495f95c766a5ad3e91fc17cadcc3
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Tue Jul 31 17:42:22 2012 +0200

    Discovered correct filter name.
    
    Change-Id: I2542ec663addca02874f3d449a1d8a243c7e5e97

diff --git a/sd/source/ui/remotecontrol/ImagePreparer.cxx b/sd/source/ui/remotecontrol/ImagePreparer.cxx
index 21754d1..f948834 100644
--- a/sd/source/ui/remotecontrol/ImagePreparer.cxx
+++ b/sd/source/ui/remotecontrol/ImagePreparer.cxx
@@ -342,7 +342,7 @@ OString ImagePreparer::prepareNotes( sal_uInt32 aSlideNumber )
 
 sal_Bool ExportTo( uno::Reference< drawing::XDrawPage>& aNotesPage, String aUrl )
 {
-    ::rtl::OUString aFilterName( "com.sun.star.comp.Writer.XmlFilterAdaptor" );
+    ::rtl::OUString aFilterName( "XHTML Draw File" );
     uno::Reference< document::XExporter > xExporter;
 
     {
@@ -354,6 +354,8 @@ sal_Bool ExportTo( uno::Reference< drawing::XDrawPage>& aNotesPage, String aUrl
         uno::Reference < container::XNameAccess > xFilters ( xFilterFact, uno::UNO_QUERY );
         if ( xFilters->hasByName( aFilterName ) )
             xFilters->getByName( aFilterName ) >>= aProps;
+        else
+            fprintf( stderr, "Couldn't find by name.\n" );
 
         ::rtl::OUString aFilterImplName;
         sal_Int32 nFilterProps = aProps.getLength();
@@ -367,16 +369,25 @@ sal_Bool ExportTo( uno::Reference< drawing::XDrawPage>& aNotesPage, String aUrl
             }
         }
 
+        fprintf( stderr, "aName%s\n", OUStringToOString(aFilterImplName, RTL_TEXTENCODING_UTF8).getStr() );
         if ( !aFilterImplName.isEmpty() )
         {
             try{
             xExporter = uno::Reference< document::XExporter >
                 ( xFilterFact->createInstanceWithArguments( aFilterName, uno::Sequence < uno::Any >() ), uno::UNO_QUERY );
             }catch(const uno::Exception&)
-                { xExporter.clear(); }
+                {
+                    xExporter.clear();
+                    fprintf( stderr, "Couldn't create instance of filter.\n" );
+                }
         }
     }
 
+    if (xExporter.is())
+        fprintf( stderr, "Is!\n" );
+    else
+        fprintf( stderr, "Isn't\n" );
+
     if ( xExporter.is() )
     {
         try{
commit ed4092d3dfacf3a3e9d1f1b3567a5477322b584a
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Tue Jul 31 15:27:12 2012 +0200

    Export now building, still missing some parameters to function.
    
    Change-Id: I5d893a292f99be46b0ca29c10345fc43a4366cfe

diff --git a/sd/source/ui/remotecontrol/ImagePreparer.cxx b/sd/source/ui/remotecontrol/ImagePreparer.cxx
index 06ebc4c..21754d1 100644
--- a/sd/source/ui/remotecontrol/ImagePreparer.cxx
+++ b/sd/source/ui/remotecontrol/ImagePreparer.cxx
@@ -33,10 +33,15 @@
 #include <rtl/ustrbuf.hxx>
 #include <sax/tools/converter.hxx>
 #include <rtl/strbuf.hxx>
+#include <unotools/streamwrap.hxx>
+
+#include <svl/itemset.hxx>
+#include <sfx2/docfile.hxx>
 
 #include <com/sun/star/beans/PropertyValue.hpp>
 #include <com/sun/star/container/XNameAccess.hpp>
 #include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/document/XImporter.hpp>
 #include <com/sun/star/document/XExporter.hpp>
 #include <com/sun/star/lang/XServiceName.hpp>
 #include <com/sun/star/presentation/XPresentationPage.hpp>
@@ -83,7 +88,7 @@ void ImagePreparer::execute()
         }
         sendNotes( i );
     }
-//     notesToHtml( 0 );
+     notesToHtml( 0 );
     mRef.clear();
 }
 
@@ -217,7 +222,7 @@ void ImagePreparer::sendNotes( sal_uInt32 aSlideNumber )
         Transmitter::Priority::LOW );
 }
 
-
+sal_Bool ExportTo( uno::Reference< drawing::XDrawPage>& aNotesPage, String aUrl );
 OString ImagePreparer::notesToHtml( sal_uInt32 aSlideNumber )
 {
     OString aRet("");
@@ -229,34 +234,11 @@ OString ImagePreparer::notesToHtml( sal_uInt32 aSlideNumber )
     if ( !xController->isRunning() )
         return "";
 
-    // Get the filter
-    uno::Reference< lang::XMultiServiceFactory > xServiceManager(
-        ::comphelper::getProcessServiceFactory(),
-        uno::UNO_QUERY_THROW );
-
-    uno::Reference< container::XNameAccess > xFilterFactory(
-        xServiceManager->createInstance( "com.sun.star.document.FilterFactory" ), uno::UNO_QUERY_THROW );
 
-    if ( xFilterFactory->hasByName( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) )
-        fprintf ( stderr, "Is contained\n" );
-    else fprintf( stderr, "Not contained\n" );
 
-//     uno::Sequence<Any> aList(6);
-//     aList[0] <<= OUString("com.sun.star.documentconversion.XSLTFilter");
-//     aList[1] <<= OUString("");
-//     aList[2] <<= OUString("com.sun.star.comp.Impress.XMLOasisImporter");
-//     aList[3] <<= OUString("com.sun.star.comp.Impress.XMLOasisExporter"),
-//     aList[4] <<= OUString("");
-//     aList[5] <<= OUString("../share/xslt/export/xhtml/opendoc2xhtml.xsl");
-
-//     uno::Reference< lang::XMultiServiceFactory > xFilterF( xFilterFactory, uno::UNO_QUERY_THROW );
-//         xFilterF->createInstanceWithArguments(OUString("com.sun.star.comp.Writer.XmlFilterAdaptor"), aList);
-
-    css::uno::Reference< document::XFilter > xFilter( xFilterFactory->getByName(
-        "com.sun.star.comp.Writer.XmlFilterAdaptor" ), uno::UNO_QUERY_THROW );
 
     // Get the page
-    uno::Reference< lang::XComponent > xNotesPage;
+    uno::Reference< drawing::XDrawPage > xNotesPage;
     uno::Reference< drawing::XDrawPage > xSourceDoc(
         xController->getSlideByIndex( aSlideNumber ),
         uno::UNO_QUERY_THROW );
@@ -264,29 +246,13 @@ OString ImagePreparer::notesToHtml( sal_uInt32 aSlideNumber )
     uno::Reference<presentation::XPresentationPage> xPresentationPage(
         xSourceDoc, UNO_QUERY);
     if (xPresentationPage.is())
-        xNotesPage = uno::Reference< lang::XComponent >(
+        xNotesPage = uno::Reference< drawing::XDrawPage >(
             xPresentationPage->getNotesPage(), uno::UNO_QUERY_THROW );
     else
         return "";
 
-    // Start Exporting
-    uno::Reference< document::XExporter > xExporter( xFilter,
-        uno::UNO_QUERY_THROW );
-
-    xExporter->setSourceDocument( xNotesPage );
-
-    uno::Sequence< beans::PropertyValue > aProps(1);
 
-    aProps[0].Name = "URL";
-    aProps[0].Value <<= aFileURL;
-
-//     aProps[1].Name = "com.sun.star.comp.Impress.XMLOasisExporter";
-//     aProps[1].Value <<= OUString( "../share/xslt/export/xhtml/opendoc2xhtml.xsl" );
-//     aProps[2].Name = "FilterData";
-//     aProps[2].Value <<= aFilterData;
-
-    fprintf( stderr, "Trying to filter\n" );
-    xFilter->filter( aProps );
+    ExportTo( xNotesPage, aFileURL );
 
     // FIXME: error handling.
 
@@ -373,4 +339,114 @@ OString ImagePreparer::prepareNotes( sal_uInt32 aSlideNumber )
     return OUStringToOString(
         aRet, RTL_TEXTENCODING_UTF8 );
 }
+
+sal_Bool ExportTo( uno::Reference< drawing::XDrawPage>& aNotesPage, String aUrl )
+{
+    ::rtl::OUString aFilterName( "com.sun.star.comp.Writer.XmlFilterAdaptor" );
+    uno::Reference< document::XExporter > xExporter;
+
+    {
+        uno::Reference< lang::XMultiServiceFactory >  xMan = ::comphelper::getProcessServiceFactory();
+        uno::Reference < lang::XMultiServiceFactory > xFilterFact (
+                xMan->createInstance( "com.sun.star.document.FilterFactory" ), uno::UNO_QUERY );
+
+        uno::Sequence < beans::PropertyValue > aProps;
+        uno::Reference < container::XNameAccess > xFilters ( xFilterFact, uno::UNO_QUERY );
+        if ( xFilters->hasByName( aFilterName ) )
+            xFilters->getByName( aFilterName ) >>= aProps;
+
+        ::rtl::OUString aFilterImplName;
+        sal_Int32 nFilterProps = aProps.getLength();
+        for ( sal_Int32 nFilterProp = 0; nFilterProp<nFilterProps; nFilterProp++ )
+        {
+            const beans::PropertyValue& rFilterProp = aProps[nFilterProp];
+            if ( rFilterProp.Name.compareToAscii("FilterService") == 0 )
+            {
+                rFilterProp.Value >>= aFilterImplName;
+                break;
+            }
+        }
+
+        if ( !aFilterImplName.isEmpty() )
+        {
+            try{
+            xExporter = uno::Reference< document::XExporter >
+                ( xFilterFact->createInstanceWithArguments( aFilterName, uno::Sequence < uno::Any >() ), uno::UNO_QUERY );
+            }catch(const uno::Exception&)
+                { xExporter.clear(); }
+        }
+    }
+
+    if ( xExporter.is() )
+    {
+        try{
+        uno::Reference< lang::XComponent >  xComp( aNotesPage, uno::UNO_QUERY_THROW );
+        uno::Reference< document::XFilter > xFilter( xExporter, uno::UNO_QUERY_THROW );
+        xExporter->setSourceDocument( xComp );
+
+        com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aOldArgs ( 2 );
+        aOldArgs[0].Name = "FileName";
+        aOldArgs[0].Value <<= OUString( aUrl );
+        aOldArgs[1].Name = "FilterName";
+        aOldArgs[1].Value <<= OUString("com.sun.star.documentconversion.XSLTFilter");
+
+        SfxMedium rMedium( aUrl , STREAM_STD_WRITE  );
+
+        const com::sun::star::beans::PropertyValue * pOldValue = aOldArgs.getConstArray();
+        com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aArgs ( aOldArgs.getLength() );
+        com::sun::star::beans::PropertyValue * pNewValue = aArgs.getArray();
+
+
+        // put in the REAL file name, and copy all PropertyValues
+        const OUString sOutputStream ( RTL_CONSTASCII_USTRINGPARAM ( "OutputStream" ) );
+        const OUString sStream ( RTL_CONSTASCII_USTRINGPARAM ( "StreamForOutput" ) );
+        sal_Bool bHasOutputStream = sal_False;
+        sal_Bool bHasStream = sal_False;
+        sal_Bool bHasBaseURL = sal_False;
+        sal_Int32 i;
+        sal_Int32 nEnd = aOldArgs.getLength();
+
+        for ( i = 0; i < nEnd; i++ )
+        {
+            pNewValue[i] = pOldValue[i];
+            if ( pOldValue[i].Name == "FileName" )
+                pNewValue[i].Value <<= OUString ( rMedium.GetName() );
+            else if ( pOldValue[i].Name == sOutputStream )
+                bHasOutputStream = sal_True;
+            else if ( pOldValue[i].Name == sStream )
+                bHasStream = sal_True;
+            else if ( pOldValue[i].Name == "DocumentBaseURL" )
+                bHasBaseURL = sal_True;
+        }
+
+        if ( !bHasOutputStream )
+        {
+            aArgs.realloc ( ++nEnd );
+            aArgs[nEnd-1].Name = sOutputStream;
+            aArgs[nEnd-1].Value <<= uno::Reference < io::XOutputStream > ( new utl::OOutputStreamWrapper ( *rMedium.GetOutStream() ) );
+        }
+
+        // add stream as well, for OOX export and maybe others
+        if ( !bHasStream )
+        {
+            aArgs.realloc ( ++nEnd );
+            aArgs[nEnd-1].Name = sStream;
+            aArgs[nEnd-1].Value <<= com::sun::star::uno::Reference < com::sun::star::io::XStream > ( new utl::OStreamWrapper ( *rMedium.GetOutStream() ) );
+        }
+
+        if ( !bHasBaseURL )
+        {
+            aArgs.realloc ( ++nEnd );
+            aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DocumentBaseURL" ) );
+            aArgs[nEnd-1].Value <<= rMedium.GetBaseURL( sal_True );
+        }
+
+        return xFilter->filter( aArgs );
+        }catch(const uno::Exception&)
+        {}
+    }
+
+    return sal_False;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file


More information about the Libreoffice-commits mailing list