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  * This file is part of the LibreOffice project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * This file incorporates work covered by the following license notice:
00010  *
00011  *   Licensed to the Apache Software Foundation (ASF) under one or more
00012  *   contributor license agreements. See the NOTICE file distributed
00013  *   with this work for additional information regarding copyright
00014  *   ownership. The ASF licenses this file to you under the Apache
00015  *   License, Version 2.0 (the "License"); you may not use this file
00016  *   except in compliance with the License. You may obtain a copy of
00017  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
00018  */
00019 
00020 #ifndef _SALHELPER_DYNLOAD_HXX_
00021 #define _SALHELPER_DYNLOAD_HXX_
00022 
00023 #include <sal/types.h>
00024 #include <rtl/ustring.hxx>
00025 #include <osl/module.h>
00026 #include "salhelperdllapi.h"
00027 
00028 namespace salhelper
00029 {
00030 
00033 class SALHELPER_DLLPUBLIC ORealDynamicLoader
00034 {
00035 public:
00043     static ORealDynamicLoader* SAL_CALL newInstance(
00044             ORealDynamicLoader ** ppSetToZeroInDestructor,
00045             const ::rtl::OUString& strModuleName,
00046             const ::rtl::OUString& strInitFunction );
00047 
00049     sal_uInt32 SAL_CALL acquire();
00051     sal_uInt32 SAL_CALL release();
00052 
00054     void* SAL_CALL getApi() const;
00055 
00056 protected:
00066     ORealDynamicLoader( ORealDynamicLoader ** ppSetToZeroInDestructor,
00067                         const ::rtl::OUString& strModuleName,
00068                         const ::rtl::OUString& strInitFunction,
00069                         void* pApi,
00070                         oslModule pModule );
00071 
00073     virtual ~ORealDynamicLoader();
00074 
00076     void*                   m_pApi;
00078     sal_uInt32              m_refCount;
00080     oslModule               m_pModule;
00082     ::rtl::OUString         m_strModuleName;
00084     ::rtl::OUString         m_strInitFunction;
00088     ORealDynamicLoader **   ppSetToZeroInDestructor;
00089 };
00090 
00091 
00104 template<class API>
00105 class ODynamicLoader
00106 {
00107 public:
00109     ODynamicLoader() SAL_THROW(())
00110     {
00111         m_pLoader = 0;
00112     }
00113 
00120     ODynamicLoader( const ::rtl::OUString& strModuleName,
00121                        const ::rtl::OUString& strInitFunction ) SAL_THROW(())
00122     {
00123         if (!m_pStaticLoader)
00124         {
00125             m_pStaticLoader = ORealDynamicLoader::newInstance(
00126                &m_pStaticLoader,
00127                strModuleName,
00128                strInitFunction);
00129         }
00130         else
00131         {
00132             m_pStaticLoader->acquire();
00133         }
00134 
00135         m_pLoader = m_pStaticLoader;
00136     }
00137 
00139     ODynamicLoader(const ODynamicLoader<API>& toCopy) SAL_THROW(())
00140     {
00141         m_pLoader = toCopy.m_pLoader;
00142         if( m_pLoader )
00143             m_pLoader->acquire();
00144     }
00145 
00147     ~ODynamicLoader() SAL_THROW(())
00148     {
00149         if( m_pLoader )
00150             m_pLoader->release();
00151     }
00152 
00154     ODynamicLoader<API>& SAL_CALL operator = (const ODynamicLoader<API>& toAssign) SAL_THROW(())
00155     {
00156         if( m_pLoader != toAssign.m_pLoader )
00157         {
00158             if( toAssign.m_pLoader )
00159             toAssign.m_pLoader->acquire();
00160             if( m_pLoader )
00161             m_pLoader->release();
00162             m_pLoader = toAssign.m_pLoader;
00163         }
00164 
00165         return (*this);
00166     }
00167 
00169     API* SAL_CALL getApi() const SAL_THROW(())
00170     {
00171         return (API*)m_pLoader->getApi();
00172     }
00173 
00175     API* SAL_CALL operator->() const SAL_THROW(())
00176     {
00177         return (API*)m_pLoader->getApi();
00178     }
00179 
00181     sal_Bool SAL_CALL isLoaded() const SAL_THROW(())
00182     {
00183         return (m_pLoader != NULL);
00184     }
00185 
00186 protected:
00188     static ORealDynamicLoader*  m_pStaticLoader;
00189     ORealDynamicLoader*         m_pLoader;
00190 };
00191 
00192 
00193 template<class API>
00194 ORealDynamicLoader* ODynamicLoader<API>::m_pStaticLoader = NULL;
00195 
00196 }
00197 
00198 #endif
00199 
00200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines