diff options
author | Andrzej Hunt <andrzej.hunt@collabora.com> | 2014-06-17 15:13:33 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2014-06-17 16:58:57 +0100 |
commit | 8ba3116a8f09650b47aa69cf3d828ca0b5f6b51e (patch) | |
tree | 3dc21143fe4ef2b23d550d53c813f5ea62a9e396 | |
parent | DOCX filter: preserve AnchorId on shapes having a textbox (diff) | |
download | core-8ba3116a8f09650b47aa69cf3d828ca0b5f6b51e.tar.gz core-8ba3116a8f09650b47aa69cf3d828ca0b5f6b51e.zip |
LOK: Split into instance and class.
Change-Id: I2b6f33eaf12343c7da1328a932eb703bb4e4ef6f
-rw-r--r-- | desktop/source/lib/init.cxx | 44 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 17 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 20 | ||||
-rw-r--r-- | libreofficekit/source/shim.c | 2 | ||||
-rw-r--r-- | smoketest/libtest.cxx | 6 |
5 files changed, 61 insertions, 28 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index af812c621ec5..6c05f815f008 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 4c32fd254bb8..6bc91e453456 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 ec1131312280..4cd502addd97 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 325695f00313..78002ab81753 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 51c184b11af6..a116e0c5e60f 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; } |