UDK 3.2.7 C/C++ API Reference
salhelper/dynload.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*************************************************************************
00003  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 
00029 #ifndef _SALHELPER_DYNLOAD_HXX_
00030 #define _SALHELPER_DYNLOAD_HXX_
00031 
00032 #include <sal/types.h>
00033 #include <rtl/ustring.hxx>
00034 #include <osl/module.h>
00035 #include "salhelperdllapi.h"
00036 
00037 namespace salhelper
00038 {
00039 
00042 class SALHELPER_DLLPUBLIC ORealDynamicLoader
00043 {
00044 public:
00052     static ORealDynamicLoader* SAL_CALL newInstance(
00053             ORealDynamicLoader ** ppSetToZeroInDestructor,
00054             const ::rtl::OUString& strModuleName,
00055             const ::rtl::OUString& strInitFunction );
00056 
00058     sal_uInt32 SAL_CALL acquire();
00060     sal_uInt32 SAL_CALL release();
00061 
00063     void* SAL_CALL getApi() const;
00064 
00065 protected:
00075     ORealDynamicLoader( ORealDynamicLoader ** ppSetToZeroInDestructor,
00076                         const ::rtl::OUString& strModuleName,
00077                         const ::rtl::OUString& strInitFunction,
00078                         void* pApi,
00079                         oslModule pModule );
00080 
00082     virtual ~ORealDynamicLoader();
00083 
00085     void*                   m_pApi;
00087     sal_uInt32              m_refCount;
00089     oslModule               m_pModule;
00091     ::rtl::OUString         m_strModuleName;
00093     ::rtl::OUString         m_strInitFunction;
00097     ORealDynamicLoader **   ppSetToZeroInDestructor;
00098 };
00099 
00100 
00113 template<class API>
00114 class ODynamicLoader
00115 {
00116 public:
00118     ODynamicLoader() SAL_THROW(())
00119     {
00120         m_pLoader = 0;
00121     }
00122 
00129     ODynamicLoader( const ::rtl::OUString& strModuleName,
00130                        const ::rtl::OUString& strInitFunction ) SAL_THROW(())
00131     {
00132         if (!m_pStaticLoader)
00133         {
00134             m_pStaticLoader = ORealDynamicLoader::newInstance(
00135                &m_pStaticLoader,
00136                strModuleName,
00137                strInitFunction);
00138         }
00139         else
00140         {
00141             m_pStaticLoader->acquire();
00142         }
00143 
00144         m_pLoader = m_pStaticLoader;
00145     }
00146 
00148     ODynamicLoader(const ODynamicLoader<API>& toCopy) SAL_THROW(())
00149     {
00150         m_pLoader = toCopy.m_pLoader;
00151         if( m_pLoader )
00152             m_pLoader->acquire();
00153     }
00154 
00156     ~ODynamicLoader() SAL_THROW(())
00157     {
00158         if( m_pLoader )
00159             m_pLoader->release();
00160     }
00161 
00163     ODynamicLoader<API>& SAL_CALL operator = (const ODynamicLoader<API>& toAssign) SAL_THROW(())
00164     {
00165         if( m_pLoader != toAssign.m_pLoader )
00166         {
00167             if( toAssign.m_pLoader )
00168             toAssign.m_pLoader->acquire();
00169             if( m_pLoader )
00170             m_pLoader->release();
00171             m_pLoader = toAssign.m_pLoader;
00172         }
00173 
00174         return (*this);
00175     }
00176 
00178     API* SAL_CALL getApi() const SAL_THROW(())
00179     {
00180         return (API*)m_pLoader->getApi();
00181     }
00182 
00184     API* SAL_CALL operator->() const SAL_THROW(())
00185     {
00186         return (API*)m_pLoader->getApi();
00187     }
00188 
00190     sal_Bool SAL_CALL isLoaded() const SAL_THROW(())
00191     {
00192         return (m_pLoader != NULL);
00193     }
00194 
00195 protected:
00197     static ORealDynamicLoader*  m_pStaticLoader;
00198     ORealDynamicLoader*         m_pLoader;
00199 };
00200 
00201 
00202 template<class API>
00203 ORealDynamicLoader* ODynamicLoader<API>::m_pStaticLoader = NULL;
00204 
00205 }
00206 
00207 #endif
00208 
00209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines