desktop/source/lib/init.cxx               |   44 +++++++++++++++++++++++-------
 include/LibreOfficeKit/LibreOfficeKit.h   |   17 ++++++++++-
 include/LibreOfficeKit/LibreOfficeKit.hxx |   20 +++++--------
 libreofficekit/source/shim.c              |    2 -
 smoketest/libtest.cxx                     |    6 ++--
 5 files changed, 61 insertions(+), 28 deletions(-)

New commits:
commit 8ba3116a8f09650b47aa69cf3d828ca0b5f6b51e
Author: Andrzej Hunt <andrzej.h...@collabora.com>
Date:   Tue Jun 17 15:13:33 2014 +0100

    LOK: Split into instance and class.
    
    Change-Id: I2b6f33eaf12343c7da1328a932eb703bb4e4ef6f

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index af812c6..6c05f81 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -13,6 +13,9 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
+
 #include <LibreOfficeKit/LibreOfficeKit.h>
 
 #include <tools/errinf.hxx>
@@ -42,10 +45,14 @@
 using namespace css;
 using namespace utl;
 
+using namespace boost;
+
 struct LibLODocument_Impl;
 struct LibLibreOffice_Impl;
 
 static LibLibreOffice_Impl *gImpl = NULL;
+static weak_ptr< LibreOfficeKitClass > gOfficeClass;
+static weak_ptr< LibreOfficeKitDocumentClass > gDocumentClass;
 
 typedef struct
 {
@@ -151,15 +158,24 @@ static int  doc_saveAsWithOptions(LibreOfficeKitDocument* 
pThis, const char* pUr
 struct LibLODocument_Impl : public _LibreOfficeKitDocument
 {
     uno::Reference<css::lang::XComponent> mxComponent;
+    shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass;
 
     LibLODocument_Impl(const uno::Reference <css::lang::XComponent> 
&xComponent) :
         mxComponent( xComponent )
     {
-        nSize = sizeof(LibreOfficeKitDocument);
+        if (!(m_pDocumentClass = gDocumentClass.lock()))
+        {
+            m_pDocumentClass.reset(new LibreOfficeKitDocumentClass);
+
+            m_pDocumentClass->nSize = sizeof(LibreOfficeKitDocument);
+
+            m_pDocumentClass->destroy = doc_destroy;
+            m_pDocumentClass->saveAs = doc_saveAs;
+            m_pDocumentClass->saveAsWithOptions = doc_saveAsWithOptions;
 
-        destroy = doc_destroy;
-        saveAs = doc_saveAs;
-        saveAsWithOptions = doc_saveAsWithOptions;
+            gDocumentClass = m_pDocumentClass;
+        }
+        pClass = m_pDocumentClass.get();
     }
 
     ~LibLODocument_Impl()
@@ -182,15 +198,23 @@ static char *                  lo_getError      
(LibreOfficeKit* pThis);
 struct LibLibreOffice_Impl : public _LibreOfficeKit
 {
     OUString maLastExceptionMsg;
+    shared_ptr< LibreOfficeKitClass > m_pOfficeClass;
 
     LibLibreOffice_Impl()
     {
-        nSize = sizeof(LibreOfficeKit);
+        if(!(m_pOfficeClass = gOfficeClass.lock())) {
+            m_pOfficeClass.reset(new LibreOfficeKitClass);
+            m_pOfficeClass->nSize = sizeof(LibreOfficeKitClass);
+
+            m_pOfficeClass->destroy = lo_destroy;
+            m_pOfficeClass->initialize = lo_initialize;
+            m_pOfficeClass->documentLoad = lo_documentLoad;
+            m_pOfficeClass->getError = lo_getError;
+
+            gOfficeClass = m_pOfficeClass;
+        }
 
-        destroy = lo_destroy;
-        initialize = lo_initialize;
-        documentLoad = lo_documentLoad;
-        getError = lo_getError;
+        pClass = m_pOfficeClass.get();
     }
 };
 
@@ -416,7 +440,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* 
pAppPath)
     return bInitialized;
 }
 
-SAL_DLLPUBLIC_EXPORT LibreOfficeKit *liblibreoffice_hook(void)
+SAL_DLLPUBLIC_EXPORT LibreOfficeKit *libreofficekit_hook(void)
 {
     if (!gImpl)
     {
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h 
b/include/LibreOfficeKit/LibreOfficeKit.h
index 4c32fd2..6bc91e4 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -18,17 +18,25 @@ extern "C"
 #endif
 
 typedef struct _LibreOfficeKit LibreOfficeKit;
+typedef struct _LibreOfficeKitClass LibreOfficeKitClass;
+
 typedef struct _LibreOfficeKitDocument LibreOfficeKitDocument;
+typedef struct _LibreOfficeKitDocumentClass LibreOfficeKitDocumentClass;
 
 // Do we have an extended member in this struct ?
 #define LIBREOFFICEKIT_HAS_MEMBER(strct,member,nSize) \
     ((((size_t)((unsigned char *)&((strct *) 0)->member) +  \
       sizeof ((strct *) 0)->member)) <= (nSize))
 
-#define LIBREOFFICEKIT_HAS(pKit,member) 
LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKit,member,(pKit)->nSize)
+#define LIBREOFFICEKIT_HAS(pKit,member) 
LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitClass,member,(pKit)->pClass->nSize)
 
 struct _LibreOfficeKit
 {
+    LibreOfficeKitClass* pClass;
+};
+
+struct _LibreOfficeKitClass
+{
   size_t  nSize;
 
   void                    (*destroy)       (LibreOfficeKit *pThis);
@@ -37,10 +45,15 @@ struct _LibreOfficeKit
   char*                   (*getError)      (LibreOfficeKit *pThis);
 };
 
-#define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) 
LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocument,member,(pDoc)->nSize)
+#define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) 
LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocumentClass,member,(pDoc)->pClass->nSize)
 
 struct _LibreOfficeKitDocument
 {
+    LibreOfficeKitDocumentClass* pClass;
+};
+
+struct _LibreOfficeKitDocumentClass
+{
   size_t  nSize;
 
   void (*destroy)   (LibreOfficeKitDocument* pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx 
b/include/LibreOfficeKit/LibreOfficeKit.hxx
index ec11313..4cd502a 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -33,22 +33,18 @@ public:
 
     inline ~Document()
     {
-        mpDoc->destroy(mpDoc);
+        mpDoc->pClass->destroy(mpDoc);
     }
 
     // Save as the given format, if format is NULL sniff from ext'n
     inline bool saveAs(const char* pUrl, const char* pFormat = NULL)
     {
-        return mpDoc->saveAs(mpDoc, pUrl, pFormat);
+        return mpDoc->pClass->saveAs(mpDoc, pUrl, pFormat);
     }
 
     inline bool saveAsWithOptions(const char* pUrl, const char* pFormat = 
NULL, const char* pFilterOptions = NULL)
     {
-        // available since LibreOffice 4.3
-        if (!LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, saveAsWithOptions))
-            return false;
-
-        return mpDoc->saveAsWithOptions(mpDoc, pUrl, pFormat, pFilterOptions);
+        return mpDoc->pClass->saveAsWithOptions(mpDoc, pUrl, pFormat, 
pFilterOptions);
     }
     inline LibreOfficeKitDocument *get() { return mpDoc; }
 };
@@ -65,17 +61,17 @@ public:
 
     inline ~Office()
     {
-        mpThis->destroy(mpThis);
+        mpThis->pClass->destroy(mpThis);
     }
 
     inline bool initialize(const char* pInstallPath)
     {
-        return mpThis->initialize(mpThis, pInstallPath);
+        return mpThis->pClass->initialize(mpThis, pInstallPath);
     }
 
     inline Document* documentLoad(const char* pUrl)
     {
-        LibreOfficeKitDocument* pDoc = mpThis->documentLoad(mpThis, pUrl);
+        LibreOfficeKitDocument* pDoc = mpThis->pClass->documentLoad(mpThis, 
pUrl);
         if (pDoc == NULL)
             return NULL;
         return new Document(pDoc);
@@ -84,14 +80,14 @@ public:
     // return the last error as a string, free me.
     inline char* getError()
     {
-        return mpThis->getError(mpThis);
+        return mpThis->pClass->getError(mpThis);
     }
 };
 
 inline Office* lok_cpp_init(const char* pInstallPath)
 {
     LibreOfficeKit* pThis = lok_init(pInstallPath);
-    if (pThis == NULL || pThis->nSize == 0)
+    if (pThis == NULL || pThis->pClass->nSize == 0)
         return NULL;
     return new ::lok::Office(pThis);
 }
diff --git a/libreofficekit/source/shim.c b/libreofficekit/source/shim.c
index 325695f..78002ab 100644
--- a/libreofficekit/source/shim.c
+++ b/libreofficekit/source/shim.c
@@ -50,7 +50,7 @@ SAL_DLLPUBLIC_EXPORT LibreOfficeKit *lok_init( const char 
*install_path )
         return NULL;
     }
 
-    pSym = (HookFunction *) dlsym( dlhandle, "liblibreoffice_hook" );
+    pSym = (HookFunction *) dlsym( dlhandle, "libreofficekit_hook" );
     if( !pSym ) {
         fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
         dlclose( dlhandle );
diff --git a/smoketest/libtest.cxx b/smoketest/libtest.cxx
index 51c184b..a116e0c 100644
--- a/smoketest/libtest.cxx
+++ b/smoketest/libtest.cxx
@@ -79,9 +79,9 @@ int main (int argc, char **argv)
     if (!LIBREOFFICEKIT_DOCUMENT_HAS(pDocument->get(), saveAsWithOptions))
     {
         fprintf( stderr, "using obsolete LibreOffice %" SAL_PRI_SIZET "d + %" 
SAL_PRI_SIZET "d vs. %" SAL_PRI_SIZET "d\n",
-                 (size_t)((unsigned char *)&((LibreOfficeKitDocument *) 
0)->saveAsWithOptions),
-                 sizeof ((LibreOfficeKitDocument *) 0)->saveAsWithOptions,
-                 pDocument->get()->nSize );
+                 (size_t)((unsigned char *)&((LibreOfficeKitDocumentClass *) 
0)->saveAsWithOptions),
+                 sizeof ((LibreOfficeKitDocumentClass *) 0)->saveAsWithOptions,
+                 pDocument->get()->pClass->nSize );
         return -1;
     }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to