LibreOffice: salhelper/dynload.hxx Source File

LibreOffice LibreOffice 25.8 SDK C/C++ API Reference

Loading...
Searching...
No Matches
dynload.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20/*
21 * This file is part of LibreOffice published API.
22 */
23
24#ifndef INCLUDED_SALHELPER_DYNLOAD_HXX
25#define INCLUDED_SALHELPER_DYNLOAD_HXX
26
27#include "sal/types.h"
28#include "rtl/ustring.hxx"
29#include "osl/module.h"
30#include "salhelper/salhelperdllapi.h"
31
32namespace salhelper
33{
34
37 class SALHELPER_DLLPUBLIC ORealDynamicLoader
38{
39public:
47 static ORealDynamicLoader* SAL_CALL newInstance(
48 ORealDynamicLoader ** ppSetToZeroInDestructor,
49 const ::rtl::OUString& strModuleName,
50 const ::rtl::OUString& strInitFunction );
51
53 sal_uInt32 SAL_CALL acquire();
55 sal_uInt32 SAL_CALL release();
56
58 void* SAL_CALL getApi() const;
59
60protected:
70 ORealDynamicLoader( ORealDynamicLoader ** ppSetToZeroInDestructor,
71 const ::rtl::OUString& strModuleName,
72 const ::rtl::OUString& strInitFunction,
73 void* pApi,
74 oslModule pModule );
75
77 virtual ~ORealDynamicLoader();
78
80 void* m_pApi;
82 sal_uInt32 m_refCount;
84 oslModule m_pModule;
86 ::rtl::OUString m_strModuleName;
88 ::rtl::OUString m_strInitFunction;
92 ORealDynamicLoader ** ppSetToZeroInDestructor;
93};
94
95
108template<class API>
109 class ODynamicLoader
110{
111public:
113 ODynamicLoader()
114 {
115 m_pLoader = NULL;
116 }
117
124 ODynamicLoader( const ::rtl::OUString& strModuleName,
125 const ::rtl::OUString& strInitFunction )
126 {
127 if (!m_pStaticLoader)
128 {
129 m_pStaticLoader = ORealDynamicLoader::newInstance(
130 &m_pStaticLoader,
131 strModuleName,
132 strInitFunction);
133 }
134 else
135 {
136 m_pStaticLoader->acquire();
137 }
138
139 m_pLoader = m_pStaticLoader;
140 }
141
143 ODynamicLoader(const ODynamicLoader<API>& toCopy)
144 {
145 m_pLoader = toCopy.m_pLoader;
146 if( m_pLoader )
147 m_pLoader->acquire();
148 }
149
151 ~ODynamicLoader()
152 {
153 if( m_pLoader )
154 if (m_pLoader->release()==0)
155 m_pStaticLoader = NULL;
156 }
157
159 ODynamicLoader<API>& SAL_CALL operator = (const ODynamicLoader<API>& toAssign)
160 {
161 if( m_pLoader != toAssign.m_pLoader )
162 {
163 if( toAssign.m_pLoader )
164 {
165 toAssign.m_pLoader->acquire();
166 }
167 if( m_pLoader )
168 {
169 m_pLoader->release();
170 }
171 m_pLoader = toAssign.m_pLoader;
172 }
173
174 return (*this);
175 }
176
178 API* SAL_CALL getApi() const
179 {
180 return static_cast<API*>(m_pLoader->getApi());
181 }
182
184 API* SAL_CALL operator->() const
185 {
186 return static_cast<API*>(m_pLoader->getApi());
187 }
188
190 bool SAL_CALL isLoaded() const
191 {
192 return (m_pLoader != NULL);
193 }
194
195protected:
197 static ORealDynamicLoader* m_pStaticLoader;
198 ORealDynamicLoader* m_pLoader;
199};
200
201
202template<class API>
203 ORealDynamicLoader* ODynamicLoader<API>::m_pStaticLoader = NULL;
204
205}
206
207#endif
208
209/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
types.h
salhelperdllapi.h
SALHELPER_DLLPUBLIC
#define SALHELPER_DLLPUBLIC
Definition salhelperdllapi.h:32
ustring.hxx
module.h
oslModule
void * oslModule
Definition module.h:59
salhelper
Definition condition.hxx:34
salhelper::ORealDynamicLoader
The ORealDynamicLoader is an implementation helper class for the template loader ODynamicLoader.
Definition dynload.hxx:38
salhelper::ORealDynamicLoader::release
sal_uInt32 release()
decrease the reference count and delete the last instance.
salhelper::ORealDynamicLoader::m_strModuleName
::rtl::OUString m_strModuleName
stores the library name.
Definition dynload.hxx:86
salhelper::ORealDynamicLoader::newInstance
static ORealDynamicLoader * newInstance(ORealDynamicLoader **ppSetToZeroInDestructor, const ::rtl::OUString &strModuleName, const ::rtl::OUString &strInitFunction)
initializes the loader, loads the library and call the initialization function.
salhelper::ORealDynamicLoader::m_pModule
oslModule m_pModule
stores the library handle.
Definition dynload.hxx:84
salhelper::ORealDynamicLoader::m_pApi
void * m_pApi
points to the structure with the initialized API function pointers.
Definition dynload.hxx:80
salhelper::ORealDynamicLoader::m_refCount
sal_uInt32 m_refCount
stores the reference count.
Definition dynload.hxx:82
salhelper::ORealDynamicLoader::getApi
void * getApi() const
returns a pointer to the initialized API function structure.
salhelper::ORealDynamicLoader::ORealDynamicLoader
ORealDynamicLoader(ORealDynamicLoader **ppSetToZeroInDestructor, const ::rtl::OUString &strModuleName, const ::rtl::OUString &strInitFunction, void *pApi, oslModule pModule)
Constructor.
salhelper::ORealDynamicLoader::m_strInitFunction
::rtl::OUString m_strInitFunction
stores the name of the initialization function.
Definition dynload.hxx:88
salhelper::ORealDynamicLoader::~ORealDynamicLoader
virtual ~ORealDynamicLoader()
Destructor, try to unload the library.
salhelper::ORealDynamicLoader::acquire
sal_uInt32 acquire()
increase the reference count.
salhelper::ORealDynamicLoader::ppSetToZeroInDestructor
ORealDynamicLoader ** ppSetToZeroInDestructor
stores a pointer to itself, which must be reset in the destructor to signal that the loader is invali...
Definition dynload.hxx:92
salhelper::ODynamicLoader::~ODynamicLoader
~ODynamicLoader()
Destructor, decrease the reference count and unload the library if it is the last instance.
Definition dynload.hxx:151
salhelper::ODynamicLoader::m_pStaticLoader
static ORealDynamicLoader * m_pStaticLoader
stores the real loader helper instance
Definition dynload.hxx:197
salhelper::ODynamicLoader::ODynamicLoader
ODynamicLoader(const ::rtl::OUString &strModuleName, const ::rtl::OUString &strInitFunction)
Constructor, loads the library if necessary otherwise the reference count will be increased.
Definition dynload.hxx:124
salhelper::ODynamicLoader::getApi
API * getApi() const
returns a pointer to the initialized API function structure.
Definition dynload.hxx:178
salhelper::ODynamicLoader::ODynamicLoader
ODynamicLoader(const ODynamicLoader< API > &toCopy)
Copy constructor.
Definition dynload.hxx:143
salhelper::ODynamicLoader::operator->
API * operator->() const
cast operator, which cast to a pointer with the initialized API function structure.
Definition dynload.hxx:184
salhelper::ODynamicLoader::m_pLoader
ORealDynamicLoader * m_pLoader
Definition dynload.hxx:198
salhelper::ODynamicLoader::ODynamicLoader
ODynamicLoader()
Default constructor.
Definition dynload.hxx:113
salhelper::ODynamicLoader::isLoaded
bool isLoaded() const
checks if the loader works on a loaded and initialized library.
Definition dynload.hxx:190
salhelper::ODynamicLoader::operator=
ODynamicLoader< API > & operator=(const ODynamicLoader< API > &toAssign)
Assign operator.
Definition dynload.hxx:159
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling.
Definition ustring.hxx:172