diff options
author | Xisco Fauli <anistenis@gmail.com> | 2011-08-21 21:50:13 +0200 |
---|---|---|
committer | Xisco Fauli <anistenis@gmail.com> | 2011-08-21 21:50:13 +0200 |
commit | 6c76e4db034fd2c43884698b1a30225fd00b3bfd (patch) | |
tree | 1937cb9be81cd2b9f3d0ad27adcc7a7531b8f29d /salhelper | |
parent | e9440fb5a0579096423c081b0f0a2185b628e896 (diff) | |
parent | 36703ca1de68cd62782d0d425123521a5bc6732b (diff) |
Merge branch 'master' into feature/gsoc2011_wizards
Conflicts:
automation/source/inc/cmdbasestream.hxx
automation/source/server/cmdbasestream.cxx
automation/source/server/retstrm.hxx
automation/source/testtool/cmdstrm.cxx
automation/source/testtool/cmdstrm.hxx
automation/source/testtool/tcommuni.cxx
basctl/prj/d.lst
basctl/uiconfig/basicide/toolbar/findbar.xml
cui/source/dialogs/about.cxx
cui/source/dialogs/about.src
cui/source/inc/about.hxx
extensions/source/abpilot/abpservices.cxx
extensions/source/dbpilots/dbpservices.cxx
extensions/source/propctrlr/pcrservices.cxx
extensions/source/svg/makefile.mk
forms/Library_frm.mk
lingucomponent/source/hyphenator/altlinuxhyph/hyphen/hyphenimp.cxx
lingucomponent/source/spellcheck/spell/sspellimp.cxx
package/prj/d.lst
package/source/zipapi/XMemoryStream.cxx
package/source/zipapi/XMemoryStream.hxx
setup_native/prj/d.lst
setup_native/source/win32/customactions/relnotes/makefile.mk
tools/test/export.map
wizards/com/sun/star/wizards/common/ConfigGroup.py
wizards/com/sun/star/wizards/common/ConfigNode.py
wizards/com/sun/star/wizards/common/Configuration.py
wizards/com/sun/star/wizards/common/Desktop.py
wizards/com/sun/star/wizards/common/FileAccess.py
wizards/com/sun/star/wizards/common/Helper.py
wizards/com/sun/star/wizards/common/SystemDialog.py
wizards/com/sun/star/wizards/document/OfficeDocument.py
wizards/com/sun/star/wizards/fax/FaxDocument.py
wizards/com/sun/star/wizards/fax/FaxWizardDialog.py
wizards/com/sun/star/wizards/fax/FaxWizardDialogConst.py
wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py
wizards/com/sun/star/wizards/letter/LetterDocument.py
wizards/com/sun/star/wizards/letter/LetterWizardDialog.py
wizards/com/sun/star/wizards/letter/LetterWizardDialogConst.py
wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py
wizards/com/sun/star/wizards/letter/LetterWizardDialogResources.py
wizards/com/sun/star/wizards/text/TextDocument.py
wizards/com/sun/star/wizards/text/TextFieldHandler.py
wizards/com/sun/star/wizards/text/TextSectionHandler.py
wizards/com/sun/star/wizards/text/ViewHandler.py
wizards/com/sun/star/wizards/ui/UnoDialog.py
wizards/com/sun/star/wizards/ui/UnoDialog2.py
wizards/com/sun/star/wizards/ui/WizardDialog.py
wizards/com/sun/star/wizards/ui/event/CommonListener.py
wizards/com/sun/star/wizards/ui/event/DataAware.py
wizards/com/sun/star/wizards/ui/event/RadioDataAware.py
wizards/com/sun/star/wizards/ui/event/UnoDataAware.py
wizards/util/helpids.h
wizards/util/hidother.src
xmlsecurity/prj/build.lst
xmlsecurity/prj/d.lst
xmlsecurity/qa/certext/SanCertExt.cxx
Diffstat (limited to 'salhelper')
40 files changed, 4061 insertions, 0 deletions
diff --git a/salhelper/inc/salhelper/condition.hxx b/salhelper/inc/salhelper/condition.hxx new file mode 100644 index 000000000000..efc042ca6156 --- /dev/null +++ b/salhelper/inc/salhelper/condition.hxx @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#ifndef _SALHELPER_CONDITION_HXX_ +#define _SALHELPER_CONDITION_HXX_ + + +#include <osl/conditn.h> +#include <osl/mutex.hxx> + + +namespace salhelper +{ + class ConditionModifier; + class ConditionWaiter; + + + class Condition + { + friend class ConditionModifier; + friend class ConditionWaiter; + + public: + + Condition(osl::Mutex& aMutex); + + virtual ~Condition(); + + + protected: + + virtual bool applies() const = 0; + + + private: + Condition(Condition &); // not defined + void operator =(Condition &); // not defined + + osl::Mutex& m_aMutex; + oslCondition m_aCondition; + }; + + + + class ConditionModifier + { + public: + + ConditionModifier(Condition& aCond); + + ~ConditionModifier(); + + + private: + ConditionModifier(ConditionModifier &); // not defined + void operator =(ConditionModifier &); // not defined + + Condition& m_aCond; + }; + + + + class ConditionWaiter + { + public: + + ConditionWaiter(Condition& aCond); + + struct timedout { + timedout(); + + timedout(timedout const &); + + virtual ~timedout(); + + timedout & operator =(timedout const &); + }; + + ConditionWaiter(Condition& aCond,sal_uInt32 milliSec) + throw( + timedout + ); + + + ~ConditionWaiter(); + + + private: + ConditionWaiter(ConditionWaiter &); // not defined + void operator =(ConditionWaiter &); // not defined + + Condition& m_aCond; + }; + + +} // namespace salhelper + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/inc/salhelper/dynload.hxx b/salhelper/inc/salhelper/dynload.hxx new file mode 100644 index 000000000000..8f0325162455 --- /dev/null +++ b/salhelper/inc/salhelper/dynload.hxx @@ -0,0 +1,208 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SALHELPER_DYNLOAD_HXX_ +#define _SALHELPER_DYNLOAD_HXX_ + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <osl/module.h> + +namespace salhelper +{ + +/** The ORealDynamicLoader is an implementation helper class for the template loader ODynamicLoader. + */ +class ORealDynamicLoader +{ +public: + /** initializes the loader, loads the library and call the initialization fucntion. + + @param ppSetToZeroInDestructor points to the loader instance which must be set to NULL + if the loader will be destroyed. + @param strModuleName specifies the library name. + @param strInitFunction specifies the name of the initialization function. + */ + static ORealDynamicLoader* SAL_CALL newInstance( + ORealDynamicLoader ** ppSetToZeroInDestructor, + const ::rtl::OUString& strModuleName, + const ::rtl::OUString& strInitFunction ); + + /// increase the reference count. + sal_uInt32 SAL_CALL acquire(); + /// decrease the reference count and delete the last instance. + sal_uInt32 SAL_CALL release(); + + /// returns a poiner to the initialized API function structure. + void* SAL_CALL getApi() const; + +protected: + /** Constructor. + + @param ppSetToZeroInDestructor points to the loader instance which must be set to NULL + if the loader will be destroyed. + @param strModuleName specifies the library name. + @param strInitFunction specifies the name of the initialization function. + @param pApi points to a structure with the initialized API function pointers. + @param pModule points to the loaded library handle. + */ + ORealDynamicLoader( ORealDynamicLoader ** ppSetToZeroInDestructor, + const ::rtl::OUString& strModuleName, + const ::rtl::OUString& strInitFunction, + void* pApi, + oslModule pModule ); + + /// Destructor, try to unload the library. + virtual ~ORealDynamicLoader(); + + /// points to the structure with the initialzed API function pointers. + void* m_pApi; + /// stores the reference count. + sal_uInt32 m_refCount; + /// stores the library handle. + oslModule m_pModule; + /// stores the library name. + ::rtl::OUString m_strModuleName; + /// stores the name of the initialization function. + ::rtl::OUString m_strInitFunction; + /** stores a pointer to itself, which must be reset in the destructor to signal + that the loader is invalid. + */ + ORealDynamicLoader ** ppSetToZeroInDestructor; +}; + + +/** The ODynmaicLoader provides a special load on call mechanism for dynamic libraries + which support a C-API. + + The libraries must provide a struct with function pointers for all supported C functions. + The loader loads the specified library and call the specified initialization function + to initialize the function pointers with the real functions. Furthermore provides the + loader a reference counter for the library. When the last instance of the laoder will + be destroyed the loader will unload the library. + + @deprecated + Do not use. + */ +template<class API> +class ODynamicLoader +{ +public: + /// Default constructor + ODynamicLoader() SAL_THROW(()) + { + m_pLoader = 0; + } + + /** Constructor, loads the library if necessary otherwise the refernece count will + be increased. + + @param strModuleName specifies the library name. + @param strInitFunction specifies the name of the initialization function. + */ + ODynamicLoader( const ::rtl::OUString& strModuleName, + const ::rtl::OUString& strInitFunction ) SAL_THROW(()) + { + if (!m_pStaticLoader) + { + m_pStaticLoader = ORealDynamicLoader::newInstance( + &m_pStaticLoader, + strModuleName, + strInitFunction); + } + else + { + m_pStaticLoader->acquire(); + } + + m_pLoader = m_pStaticLoader; + } + + /// Copy constructor + ODynamicLoader(const ODynamicLoader<API>& toCopy) SAL_THROW(()) + { + m_pLoader = toCopy.m_pLoader; + if( m_pLoader ) + m_pLoader->acquire(); + } + + /// Destructor, decrease the reference count and unload the library if it is tha last instance. + ~ODynamicLoader() SAL_THROW(()) + { + if( m_pLoader ) + m_pLoader->release(); + } + + /// Assign operator + ODynamicLoader<API>& SAL_CALL operator = (const ODynamicLoader<API>& toAssign) SAL_THROW(()) + { + if( m_pLoader != toAssign.m_pLoader ) + { + if( toAssign.m_pLoader ) + toAssign.m_pLoader->acquire(); + if( m_pLoader ) + m_pLoader->release(); + m_pLoader = toAssign.m_pLoader; + } + + return (*this); + } + + /// returns a poiner to the initialized API function structure. + API* SAL_CALL getApi() const SAL_THROW(()) + { + return (API*)m_pLoader->getApi(); + } + + /// cast operator, which cast to a poiner with the initialized API function structure. + API* SAL_CALL operator->() const SAL_THROW(()) + { + return (API*)m_pLoader->getApi(); + } + + /// checks if the loader works on a loaded and initialized library. + sal_Bool SAL_CALL isLoaded() const SAL_THROW(()) + { + return (m_pLoader != NULL); + } + +protected: + /// stores the real loader helper instance + static ORealDynamicLoader* m_pStaticLoader; + ORealDynamicLoader* m_pLoader; +}; + + +template<class API> +ORealDynamicLoader* ODynamicLoader<API>::m_pStaticLoader = NULL; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/inc/salhelper/future.hxx b/salhelper/inc/salhelper/future.hxx new file mode 100644 index 000000000000..96159b649cf1 --- /dev/null +++ b/salhelper/inc/salhelper/future.hxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SALHELPER_FUTURE_HXX_ +#define _SALHELPER_FUTURE_HXX_ + +#include <sal/types.h> +#include <osl/diagnose.h> +#include <osl/conditn.hxx> +#include <salhelper/refobj.hxx> + +namespace salhelper +{ + +//---------------------------------------------------------------------------- + +#ifndef SALHELPER_COPYCTOR_API +#define SALHELPER_COPYCTOR_API(C) C (const C&); C& operator= (const C&) +#endif + +//---------------------------------------------------------------------------- + +template<class value_type> +class FutureValue : protected osl::Condition +{ + /** Representation. + */ + value_type m_aValue; + + /** Not implemented. + */ + SALHELPER_COPYCTOR_API(FutureValue<value_type>); + +public: + inline FutureValue (const value_type& value = value_type()) SAL_THROW(()) + : m_aValue (value) + { + Condition::reset(); + } + + inline ~FutureValue() SAL_THROW(()) + {} + + inline sal_Bool is() const SAL_THROW(()) + { + return const_cast<FutureValue*>(this)->check(); + } + + inline void set (const value_type& value) SAL_THROW(()) + { + m_aValue = value; + Condition::set(); + } + + inline value_type& get() SAL_THROW(()) + { + Condition::wait(); + return m_aValue; + } +}; + +//---------------------------------------------------------------------------- + +template<class value_type> +class Future : public salhelper::ReferenceObject +{ + /** Representation. + */ + FutureValue<value_type> m_aValue; + + /** Not implemented. + */ + SALHELPER_COPYCTOR_API(Future<value_type>); + +public: + inline Future (const value_type& value = value_type()) SAL_THROW(()) + : m_aValue (value) + {} + + inline void set (const value_type& value) SAL_THROW(()) + { + OSL_PRECOND(!m_aValue.is(), "Future::set(): value already set"); + m_aValue.set (value); + } + + inline value_type& get() SAL_THROW(()) + { + return m_aValue.get(); + } +}; + +//---------------------------------------------------------------------------- + +} // namespace salhelper + +#endif /* !_SALHELPER_FUTURE_HXX_ */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/inc/salhelper/futurequeue.hxx b/salhelper/inc/salhelper/futurequeue.hxx new file mode 100644 index 000000000000..6b4214825fe1 --- /dev/null +++ b/salhelper/inc/salhelper/futurequeue.hxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SALHELPER_FUTUREQUEUE_HXX_ +#define _SALHELPER_FUTUREQUEUE_HXX_ + +#include <sal/types.h> +#include <rtl/ref.hxx> +#include <osl/mutex.hxx> +#include <salhelper/future.hxx> +#include <salhelper/queue.hxx> + +namespace salhelper +{ + +//---------------------------------------------------------------------------- + +#ifndef SALHELPER_COPYCTOR_API +#define SALHELPER_COPYCTOR_API(C) C (const C&); C& operator= (const C&) +#endif + +//---------------------------------------------------------------------------- + +template<class element_type> +class FutureQueue : protected osl::Mutex +{ + /** Representation. + */ + typedef salhelper::Future<element_type> future_type; + + salhelper::QueueBase< rtl::Reference<future_type> > m_aDelayed; + salhelper::QueueBase< rtl::Reference<future_type> > m_aPresent; + + /** Not implemented. + */ + SALHELPER_COPYCTOR_API(FutureQueue<element_type>); + +public: + /** Construction. + */ + inline FutureQueue() + {} + + /** Destruction. + */ + inline ~FutureQueue() + {} + + /** Enqueue element at queue tail. + */ + inline void put (const element_type& element) + { + osl::MutexGuard aGuard (*this); + + rtl::Reference<future_type> xFuture (m_aDelayed.get()); + if (!xFuture.is()) + { + xFuture = new future_type(); + m_aPresent.put (xFuture); + } + xFuture->set (element); + } + + /** Dequeue a future to element at queue head. + */ + inline rtl::Reference< salhelper::Future<element_type> > get() + { + osl::MutexGuard aGuard (*this); + + rtl::Reference<future_type> xFuture (m_aPresent.get()); + if (!xFuture.is()) + { + xFuture = new future_type(); + m_aDelayed.put (xFuture); + } + return (xFuture); + } +}; + +//---------------------------------------------------------------------------- + +} // namespace salhelper + +#endif /* !_SALHELPER_FUTUREQUEUE */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/inc/salhelper/linkhelper.hxx b/salhelper/inc/salhelper/linkhelper.hxx new file mode 100644 index 000000000000..c8744dcca0b4 --- /dev/null +++ b/salhelper/inc/salhelper/linkhelper.hxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Caolán McNamara <caolanm@redhat.com> (Red Hat, Inc.) + * Portions created by the Initial Developer are Copyright (C) 2011 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Caolán McNamara <caolanm@redhat.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#ifndef _SALHELPER_LINKHELPER_HXX +#define _SALHELPER_LINKHELPER_HXX + +#include <rtl/ustring.hxx> +#include <osl/file.hxx> + +namespace salhelper +{ + class LinkResolver + { + public: + osl::FileStatus m_aStatus; + + LinkResolver(sal_uInt32 nMask) + : m_aStatus(nMask | + osl_FileStatus_Mask_FileURL | + osl_FileStatus_Mask_Type | + osl_FileStatus_Mask_LinkTargetURL) + { + } + + /** Resolve a file url if its a symbolic link, to a maximum depth of + * nDepth and fill in m_aStatus with the requested ctor flags + * + * @return osl::FileBase::E_None on success + * + * @see DirectoryItem::getFileStatus + */ + osl::FileBase::RC fetchFileStatus(const rtl::OUString &rURL, + int nDepth = 128) + { + //In an ideal world this wouldn't be inline, but I want to use this + //in jvmfwk hence salhelper, but salhelper is .map controlled and + //getting all the mangled names right is a misery, moving it over + //to visibility markup would drop per-symbol versioning + osl::FileBase::RC eReturn; + + osl::DirectoryItem item; + rtl::OUString sURL(rURL); + while ((eReturn = osl::DirectoryItem::get(sURL, item)) + == osl::File::E_None) + { + if (--nDepth == 0) + { + eReturn = osl::FileBase::E_MULTIHOP; + break; + } + eReturn = item.getFileStatus(m_aStatus); + if (eReturn != osl::File::E_None) + break; + if (m_aStatus.getFileType() != osl::FileStatus::Link) + { + eReturn = osl::FileBase::E_None; + break; + } + sURL = m_aStatus.getLinkTargetURL(); + } + + return eReturn; + } + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/inc/salhelper/monitor.hxx b/salhelper/inc/salhelper/monitor.hxx new file mode 100644 index 000000000000..b7c0ceec9d3c --- /dev/null +++ b/salhelper/inc/salhelper/monitor.hxx @@ -0,0 +1,291 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SALHELPER_MONITOR_HXX_ +#define _SALHELPER_MONITOR_HXX_ + +#include <sal/types.h> +#include <osl/conditn.hxx> +#include <osl/diagnose.h> +#include <osl/interlck.h> +#include <rtl/ref.hxx> +#include <salhelper/refobj.hxx> +#include <salhelper/future.hxx> +#include <salhelper/futurequeue.hxx> + +namespace salhelper +{ + +//---------------------------------------------------------------------------- + +#ifndef SALHELPER_COPYCTOR_API +#define SALHELPER_COPYCTOR_API(C) C (const C&); C& operator= (const C&) +#endif + +//---------------------------------------------------------------------------- + +class MonitorCondition : protected osl::Condition +{ + /** Representation. + */ + oslInterlockedCount m_nReferenceCount; + + /** Not implemented. + */ + SALHELPER_COPYCTOR_API(MonitorCondition); + +public: + /** Construction. + */ + inline MonitorCondition() SAL_THROW(()) : m_nReferenceCount (0) + { + Condition::set(); + } + + /** Destruction. + */ + inline ~MonitorCondition() SAL_THROW(()) + { + OSL_ASSERT(m_nReferenceCount == 0); + } + + /** Acquire or enter the monitor. + */ + inline void acquire() SAL_THROW(()) + { + if (osl_incrementInterlockedCount (&m_nReferenceCount) == 1) + { + Condition::reset(); + } + } + + /** Release or leave the monitor. + */ + inline void release() SAL_THROW(()) + { + if (osl_decrementInterlockedCount (&m_nReferenceCount) == 0) + { + Condition::set(); + } + } + + /** Wait until all references are released. + */ + inline void wait() SAL_THROW(()) + { + Condition::wait(); + } +}; + +//---------------------------------------------------------------------------- + +class QueuedReaderWriterMonitor : public salhelper::ReferenceObject +{ + /** Representation. + */ + typedef salhelper::Future<sal_Int32> future_type; + + salhelper::FutureQueue<sal_Int32> m_aQueue; + salhelper::MonitorCondition m_aMonitor; + + /** Not implemented. + */ + SALHELPER_COPYCTOR_API(QueuedReaderWriterMonitor); + +public: + /** Construction. + */ + inline QueuedReaderWriterMonitor() + { + // Insert the token. + m_aQueue.put(0); + } + + /** Acquire read access. + */ + inline void acquireReader() + { + // Obtain the token. + rtl::Reference<future_type> xFuture (m_aQueue.get()); + xFuture->get(); + + // Enter the monitor. + m_aMonitor.acquire(); + + // Push back the token. + m_aQueue.put(0); + } + + /** Release read access. + */ + inline void releaseReader() + { + // Leave the monitor. + m_aMonitor.release(); + } + + /** Acquire write access. + */ + inline void acquireWriter() + { + // Obtain the token. + rtl::Reference<future_type> xFuture (m_aQueue.get()); + xFuture->get(); + + // Wait until all readers have left. + m_aMonitor.wait(); + } + + /** Release write access. + */ + inline void releaseWriter() + { + // Push back the token. + m_aQueue.put(0); + } + +protected: + /** Destruction. + */ + virtual ~QueuedReaderWriterMonitor() + {} +}; + +//---------------------------------------------------------------------------- + +template<class monitor_type> +class ReaderGuard +{ + /** Representation. + */ + monitor_type *m_pMonitor; + + /** Not implemented. + */ + SALHELPER_COPYCTOR_API(ReaderGuard<monitor_type>); + +public: + /** Construction. Acquire monitor read access. + */ + inline ReaderGuard (monitor_type & rMonitor) : m_pMonitor (&rMonitor) + { + m_pMonitor->acquireReader(); + } + + /** Construction. Acquire monitor read access. + */ + inline ReaderGuard (monitor_type * pMonitor) : m_pMonitor (pMonitor) + { + OSL_PRECOND(m_pMonitor, "ReaderGuard::ReaderGuard(): No Monitor"); + m_pMonitor->acquireReader(); + } + + /** Destruction. Release monitor read access. + */ + inline ~ReaderGuard() + { + if (m_pMonitor) + m_pMonitor->releaseReader(); + } + + /** Release monitor read access. + */ + inline void clear() + { + if (m_pMonitor) + { + m_pMonitor->releaseReader(); + m_pMonitor = 0; + } + } +}; + +//---------------------------------------------------------------------------- + +typedef ReaderGuard<QueuedReaderWriterMonitor> QueuedReaderGuard; + +//---------------------------------------------------------------------------- + +template<class monitor_type> +class WriterGuard +{ + /** Representation. + */ + monitor_type *m_pMonitor; + + /** Not implemented. + */ + SALHELPER_COPYCTOR_API(WriterGuard<monitor_type>); + +public: + /** Construction. Acquire monitor write access. + */ + inline WriterGuard (monitor_type & rMonitor) : m_pMonitor (&rMonitor) + { + m_pMonitor->acquireWriter(); + } + + /** Construction. Acquire monitor write access. + */ + inline WriterGuard (monitor_type * pMonitor) : m_pMonitor (pMonitor) + { + OSL_PRECOND(m_pMonitor, "WriterGuard::WriterGuard(): No Monitor"); + m_pMonitor->acquireWriter(); + } + + /** Destruction. Release monitor write access. + */ + inline ~WriterGuard() + { + if (m_pMonitor) + m_pMonitor->releaseWriter(); + } + + /** Release monitor write access. + */ + inline void clear() + { + if (m_pMonitor) + { + m_pMonitor->releaseWriter(); + m_pMonitor = 0; + } + } +}; + +//---------------------------------------------------------------------------- + +typedef WriterGuard<QueuedReaderWriterMonitor> QueuedWriterGuard; + +//---------------------------------------------------------------------------- + +} // namespace salhelper + +#endif /* !_SALHELPER_MONITOR_HXX_ */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/inc/salhelper/queue.hxx b/salhelper/inc/salhelper/queue.hxx new file mode 100644 index 000000000000..f32fbcf73f93 --- /dev/null +++ b/salhelper/inc/salhelper/queue.hxx @@ -0,0 +1,187 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SALHELPER_QUEUE_HXX_ +#define _SALHELPER_QUEUE_HXX_ + +#include <sal/types.h> +#include <osl/diagnose.h> +#include <osl/mutex.hxx> +#include <osl/semaphor.hxx> + +#ifndef __LIST__ +#include <list> +#endif + +namespace salhelper +{ + +//---------------------------------------------------------------------------- + +#ifndef SALHELPER_COPYCTOR_API +#define SALHELPER_COPYCTOR_API(C) C (const C&); C& operator= (const C&) +#endif + +//---------------------------------------------------------------------------- + +template<class element_type> +class QueueBase : protected std::list<element_type> +{ + /** Representation. + */ + osl::Mutex m_aMutex; + + /** Not implemented. + */ + SALHELPER_COPYCTOR_API(QueueBase<element_type>); + +public: + inline QueueBase() + {} + + inline ~QueueBase() + { + erase (this->begin(), this->end()); + } + + inline void put (const element_type& element) + { + osl::MutexGuard aGuard (m_aMutex); + push_back (element); + } + + inline element_type get() + { + element_type element; + + osl::MutexGuard aGuard (m_aMutex); + if (!this->empty()) + { + element = this->front(); + this->pop_front(); + } + + return (element); + } +}; + +//---------------------------------------------------------------------------- + +/** Queue. + + @deprecated + Must not be used, as it internally uses unnamed semaphores, which are not + supported on Mac OS X. +*/ +template<class element_type> +class Queue : protected QueueBase<element_type> +{ + /** Representation. + */ + osl::Semaphore m_aNotEmpty; + + /** Not implemented. + */ + SALHELPER_COPYCTOR_API(Queue<element_type>); + +public: + inline Queue() : m_aNotEmpty (static_cast< sal_uInt32 >(0)) + {} + + inline ~Queue() + {} + + inline void put (const element_type& element) + { + QueueBase<element_type>::put (element); + m_aNotEmpty.release(); + } + + inline element_type get() + { + element_type element; + + m_aNotEmpty.acquire(); + element = QueueBase<element_type>::get(); + + return (element); + } +}; + +//---------------------------------------------------------------------------- + +/** Bounded queue. + + @deprecated + Must not be used, as it internally uses unnamed semaphores, which are not + supported on Mac OS X. +*/ +template<class element_type> +class BoundedQueue : protected Queue<element_type> +{ + /** Representation. + */ + osl::Semaphore m_aNotFull; + + /** Not implemented. + */ + SALHELPER_COPYCTOR_API(BoundedQueue<element_type>); + +public: + inline BoundedQueue (sal_uInt32 capacity) : m_aNotFull (capacity) + { + OSL_POSTCOND(capacity, "BoundedQueue:BoundedQueue(): no capacity"); + } + + inline ~BoundedQueue() + {} + + inline void put (const element_type& element) + { + m_aNotFull.acquire(); + Queue<element_type>::put (element); + } + + inline element_type get() + { + element_type element; + + element = Queue<element_type>::get(); + m_aNotFull.release(); + + return (element); + } +}; + +//---------------------------------------------------------------------------- + +} // namespace salhelper + +#endif /* !_SALHELPER_QUEUE_HXX_ */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/inc/salhelper/refobj.hxx b/salhelper/inc/salhelper/refobj.hxx new file mode 100644 index 000000000000..07ddfc90e0e9 --- /dev/null +++ b/salhelper/inc/salhelper/refobj.hxx @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SALHELPER_REFOBJ_HXX_ +#define _SALHELPER_REFOBJ_HXX_ + +#include <sal/types.h> +#include <rtl/alloc.h> +#include <rtl/ref.hxx> +#include <osl/diagnose.h> +#include <osl/interlck.h> + +namespace salhelper +{ + +//---------------------------------------------------------------------------- + +class ReferenceObject : public rtl::IReference +{ + /** Representation. + */ + oslInterlockedCount m_nReferenceCount; + + /** Not implemented. + */ + ReferenceObject (const ReferenceObject&); + ReferenceObject& operator= (const ReferenceObject&); + +public: + /** Allocation. + */ + static void* operator new (size_t n) SAL_THROW(()) + { + return ::rtl_allocateMemory (n); + } + static void operator delete (void* p) SAL_THROW(()) + { + ::rtl_freeMemory (p); + } + static void* operator new (size_t, void* p) SAL_THROW(()) + { + return (p); + } + static void operator delete (void*, void*) SAL_THROW(()) + {} + +public: + /** Construction. + */ + inline ReferenceObject() SAL_THROW(()) : m_nReferenceCount (0) + {} + + + /** IReference. + */ + virtual oslInterlockedCount SAL_CALL acquire() SAL_THROW(()) + { + return ::osl_incrementInterlockedCount (&m_nReferenceCount); + } + + virtual oslInterlockedCount SAL_CALL release() SAL_THROW(()) + { + oslInterlockedCount result; + result = ::osl_decrementInterlockedCount (&m_nReferenceCount); + if (result == 0) + { + // Last reference released. + delete this; + } + return (result); + } + +protected: + /** Destruction. + */ + virtual ~ReferenceObject() SAL_THROW(()) + { + OSL_ASSERT(m_nReferenceCount == 0); + } +}; + +//---------------------------------------------------------------------------- + +} // namespace salhelper + +#endif /* !_SALHELPER_REFOBJ_HXX_ */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/inc/salhelper/simplereferenceobject.hxx b/salhelper/inc/salhelper/simplereferenceobject.hxx new file mode 100644 index 000000000000..c5ef6dbbd070 --- /dev/null +++ b/salhelper/inc/salhelper/simplereferenceobject.hxx @@ -0,0 +1,145 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_ +#define _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_ + +#include "osl/interlck.h" +#include "sal/types.h" + +#ifndef INCLUDED_CSTDDEF +#include <cstddef> +#define INCLUDED_CSTDDEF +#endif +#ifndef INCLUDED_NEW +#include <new> +#define INCLUDED_NEW +#endif + +namespace salhelper { + +/** A simple base implementation for reference-counted objects. + + Classes that want to implement a reference-counting mechanism based on the + acquire()/release() interface should derive from this class. + + The reason to have class local operators new and delete here is technical. + Imagine a class D derived from SimpleReferenceObject, but implemented in + another shared library that happens to use different global operators new + and delete from those used in this shared library (which, sadly, seems to + be possible with shared libraries). Now, without the class local + operators new and delete here, a code sequence like "new D" would use the + global operator new as found in the other shared library, while the code + sequence "delete this" in release() would use the global operator delete + as found in this shared library---and these two operators would not be + guaranteed to match. + + There are no overloaded operators new and delete for placement new here, + because it is felt that the concept of placement new does not work well + with the concept of reference-counted objects; so it seems best to simply + leave those operators out. + + The same problem as with operators new and delete would also be there with + operators new[] and delete[]. But since arrays of reference-counted + objects are of no use, anyway, it seems best to simply declare and not + define (private) operators new[] and delete[]. + */ +class SimpleReferenceObject +{ +public: + inline SimpleReferenceObject() SAL_THROW(()): m_nCount(0) {} + + /** @ATTENTION + The results are undefined if, for any individual instance of + SimpleReferenceObject, the total number of calls to acquire() exceeds + the total number of calls to release() by a plattform dependent amount + (which, hopefully, is quite large). + */ + inline void acquire() SAL_THROW(()) + { osl_incrementInterlockedCount(&m_nCount); } + + inline void release() SAL_THROW(()) + { if (osl_decrementInterlockedCount(&m_nCount) == 0) delete this; } + + /** see general class documentation + */ + static void * operator new(std::size_t nSize) SAL_THROW((std::bad_alloc)); + + /** see general class documentation + */ + static void * operator new(std::size_t nSize, + std::nothrow_t const & rNothrow) + SAL_THROW(()); + + /** see general class documentation + */ + static void operator delete(void * pPtr) SAL_THROW(()); + + /** see general class documentation + */ + static void operator delete(void * pPtr, std::nothrow_t const & rNothrow) + SAL_THROW(()); + +protected: + virtual ~SimpleReferenceObject() SAL_THROW(()); + +private: + oslInterlockedCount m_nCount; + + /** not implemented + @internal + */ + SimpleReferenceObject(SimpleReferenceObject &); + + /** not implemented + @internal + */ + void operator =(SimpleReferenceObject); + +#ifdef _MSC_VER +/* We can't now have these private with MSVC2008 at least, it leads to + compilation errors in xmloff and other places. +*/ +protected: +#endif + /** not implemented (see general class documentation) + @internal + */ + static void * operator new[](std::size_t); + + /** not implemented (see general class documentation) + @internal + */ + static void operator delete[](void * pPtr); +}; + +} + +#endif // _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/inc/salhelper/singletonref.hxx b/salhelper/inc/salhelper/singletonref.hxx new file mode 100644 index 000000000000..bf9dc69f7f87 --- /dev/null +++ b/salhelper/inc/salhelper/singletonref.hxx @@ -0,0 +1,213 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SALHELPER_SINGLETONREF_HXX_ +#define _SALHELPER_SINGLETONREF_HXX_ + +//_______________________________________________ +// includes + +#include <osl/mutex.hxx> +#include "rtl/instance.hxx" +#include "osl/diagnose.h" +#include "osl/getglobalmutex.hxx" + +//_______________________________________________ +// namespace + +namespace salhelper{ + +//_______________________________________________ +// definitions + +/** @short template for implementing singleton classes. + + @descr Such classes can be instanciated everytimes they + are needed. But the internal wrapped object will + be created one times only. Of course its used + resources are referenced one times only too. + This template hold it alive till the last + reference is gone. Further all operations + on this reference are threadsafe. Only + calls directly to the internal object (which modify + its state) must be made threadsafe by the object itself + or from outside. + + @attention To prevent the code against race conditions, its not + allowed to start operations inside the ctor + of the internal wrapped object - especialy operations + which needs a reference to the same singleton too. + + The only chance to supress such strange constellations + is a lazy-init mechanism. + + <ul> + <li>a) The singleton class can provide a special init() + method, which must be called as first after creation.</li> + <li>b) The singleton class can call a special impl_init() + method implicit for every called interface method.</li> + </ul> + + Note further that this singleton pattern can work only, if + all user of such singleton are located inside the same library! + Because static values cant be exported - e.g. from windows libraries. + */ +template< class SingletonClass > +class SingletonRef +{ + //------------------------------------------- + // member + + private : + + /** @short pointer to the internal wrapped singleton. */ + static SingletonClass* m_pInstance; + + /** @short ref count, which regulate creation and removing of m_pInstance. */ + static sal_Int32 m_nRef; + + //------------------------------------------- + // interface + + public : + + //--------------------------------------- + + /** @short standard ctor. + + @descr The internal wrapped object is created only, + if its ref count was 0. Otherwhise this method + does nothing ... except increasing of the internal + ref count! + */ + SingletonRef() + { + // GLOBAL SAFE -> + ::osl::MutexGuard aLock(SingletonRef::ownStaticLock()); + + // must be increased before(!) the check is done. + // Otherwhise this check can fail inside the same thread ... + ++m_nRef; + if (m_nRef == 1) + m_pInstance = new SingletonClass(); + + OSL_ENSURE(m_nRef>0 && m_pInstance, "Race? Ref count of singleton >0, but instance is NULL!"); + // <- GLOBAL SAFE + } + + //--------------------------------------- + + /** @short standard dtor. + + @descr The internal wrapped object is removed only, + if its ref count wil be 0. Otherwhise this method + does nothing ... except decreasing of the internal + ref count! + */ + ~SingletonRef() + { + // GLOBAL SAFE -> + ::osl::MutexGuard aLock(SingletonRef::ownStaticLock()); + + // must be decreased before(!) the check is done. + // Otherwhise this check can fail inside the same thread ... + --m_nRef; + if (m_nRef == 0) + { + delete m_pInstance; + m_pInstance = 0; + } + // <- GLOBAL SAFE + } + + //--------------------------------------- + + /** @short Allows rSingle->someBodyOp(). + */ + SingletonClass* operator->() const + { + // GLOBAL SAFE -> + ::osl::MutexGuard aLock(SingletonRef::ownStaticLock()); + return m_pInstance; + // <- GLOBAL SAFE + } + + //--------------------------------------- + + /** @short Allows (*rSingle).someBodyOp(). + */ + SingletonClass& operator*() const + { + // GLOBAL SAFE -> + ::osl::MutexGuard aLock(SingletonRef::ownStaticLock()); + return *m_pInstance; + // <- GLOBAL SAFE + } + + //------------------------------------------- + // helper + + private : + + //--------------------------------------- + + /** @short creates an own mutex for guarding static contents. + + @descr The global mutex the osl library is used one times + only to create an own static mutex, which can be used + next time to guard own static member operations. + */ + struct SingletonLockInit + { + ::osl::Mutex* operator()() + { + static ::osl::Mutex aInstance; + return &aInstance; + } + }; + + ::osl::Mutex& ownStaticLock() const + { + return *rtl_Instance< ::osl::Mutex, + SingletonLockInit, + ::osl::MutexGuard, + ::osl::GetGlobalMutex >::create(SingletonLockInit(), ::osl::GetGlobalMutex()); + } +}; + +template< class SingletonClass > +SingletonClass* SingletonRef< SingletonClass >::m_pInstance = 0; + +template< class SingletonClass > +sal_Int32 SingletonRef< SingletonClass >::m_nRef = 0; + +} // namespace salhelper + +#endif // _SALHELPER_SINGLETONREF_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/inc/salhelper/timer.hxx b/salhelper/inc/salhelper/timer.hxx new file mode 100644 index 000000000000..7b94b11a4f00 --- /dev/null +++ b/salhelper/inc/salhelper/timer.hxx @@ -0,0 +1,238 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#ifndef _SALHELPER_TIMER_HXX_ +#define _SALHELPER_TIMER_HXX_ + +#include <salhelper/simplereferenceobject.hxx> +#include <osl/time.h> + +namespace salhelper +{ + +/** Helper class for easier manipulation with TimeValue. + * + * Times are seconds in UTC since 01.01.1970 + */ +struct TTimeValue : public TimeValue +{ + TTimeValue() + { + Seconds = 0; + Nanosec = 0; + } + + TTimeValue( sal_uInt32 Secs, sal_uInt32 Nano ) + { + Seconds = Secs; + Nanosec = Nano; + + normalize(); + } + + TTimeValue(sal_uInt32 MilliSecs) + { + Seconds = MilliSecs / 1000L; + Nanosec = (MilliSecs % 1000) * 1000000L; + + normalize(); + } + + TTimeValue( const TTimeValue& rTimeValue ) + { + Seconds = rTimeValue.Seconds; + Nanosec = rTimeValue.Nanosec; + + normalize(); + } + + TTimeValue( const TimeValue& rTimeValue ) + { + Seconds = rTimeValue.Seconds; + Nanosec = rTimeValue.Nanosec; + + normalize(); + } + + void SAL_CALL normalize() + { + if ( Nanosec > 1000000000 ) + { + Seconds += Nanosec / 1000000000; + Nanosec %= 1000000000; + } + } + + void SAL_CALL addTime( const TTimeValue& Delta ) + { + Seconds += Delta.Seconds; + Nanosec += Delta.Nanosec; + + normalize(); + } + + sal_Bool SAL_CALL isEmpty() const + { + return ( ( Seconds == 0 ) && ( Nanosec == 0 ) ); + } +}; + +inline sal_Bool operator<( const TTimeValue& rTimeA, const TTimeValue& rTimeB ) +{ + if ( rTimeA.Seconds < rTimeB.Seconds ) + return sal_True; + else if ( rTimeA.Seconds > rTimeB.Seconds ) + return sal_False; + else + return ( rTimeA.Nanosec < rTimeB.Nanosec ); +} + +inline sal_Bool operator>( const TTimeValue& rTimeA, const TTimeValue& rTimeB ) +{ + if ( rTimeA.Seconds > rTimeB.Seconds ) + return sal_True; + else if ( rTimeA.Seconds < rTimeB.Seconds ) + return sal_False; + else + return ( rTimeA.Nanosec > rTimeB.Nanosec ); +} + +inline sal_Bool operator==( const TTimeValue& rTimeA, const TTimeValue& rTimeB ) +{ + return ( ( rTimeA.Seconds == rTimeB.Seconds ) && + ( rTimeA.Nanosec == rTimeB.Nanosec ) ); +} + +class TimerManager; + +/** Interface for the Timer and handling the event +*/ +class Timer : public salhelper::SimpleReferenceObject +{ +public: + + /** Constructor. + */ + Timer(); + + /** Constructor. + */ + Timer( const TTimeValue& Time ); + + /** Constructor. + */ + Timer( const TTimeValue& Time, const TTimeValue& RepeatTime ); + + /** Start timer. + */ + void SAL_CALL start(); + + /** Abort timer prematurely. + */ + void SAL_CALL stop(); + + /** Returns sal_True if timer is running. + */ + sal_Bool SAL_CALL isTicking() const; + + /** Is the timer expired? + */ + sal_Bool SAL_CALL isExpired() const; + + /** Does pTimer expires before us? + */ + sal_Bool SAL_CALL expiresBefore( const Timer* pTimer ) const; + + /** Set the absolute time when the timer should fire. + */ + void SAL_CALL setAbsoluteTime( const TTimeValue& Time ); + + /** Set the time to fire to 'now' + Remaining. + */ + void SAL_CALL setRemainingTime( const TTimeValue& Remaining ); + + /** Set the time to fire to 'now' + Remaining with repeat interveal + * Repeat. + */ + void SAL_CALL setRemainingTime( const TTimeValue& Remaining, const TTimeValue& Repeat ); + + /** Adds Time to the 'fire time'. + */ + void SAL_CALL addTime( const TTimeValue& Time ); + + /** Returns the remaining time before timer expiration relative to now. + */ + TTimeValue SAL_CALL getRemainingTime() const; + +protected: + + /** Destructor. + */ + virtual ~Timer(); + + /** What should be done when the 'timer fires'. + */ + virtual void SAL_CALL onShot() = 0; + +protected: + + /** holds (initial) exparation time of this timer. + */ + TTimeValue m_aTimeOut; + + /** holds the time of exparation of this timer. + */ + TTimeValue m_aExpired; + + /** holds the time interveal of successive expirations. + */ + TTimeValue m_aRepeatDelta; + + /** Pointer to the next timer (to fire). + */ + Timer* m_pNext; + +private: + + /** Copy constructor disabled. + */ + Timer( const Timer& rTimer ); + + /** Assignment operator disabled. + */ + void SAL_CALL operator=( const Timer& rTimer ); + + friend class TimerManager; +}; + +} + +#endif //_SALHELPER_TIMER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/prj/build.lst b/salhelper/prj/build.lst new file mode 100644 index 000000000000..9a21849507ff --- /dev/null +++ b/salhelper/prj/build.lst @@ -0,0 +1,3 @@ +shp salhelper : sal NULL +shp salhelper usr1 - all shp_mkout NULL +shp salhelper\source nmake - all shp_source NULL diff --git a/salhelper/prj/d.lst b/salhelper/prj/d.lst new file mode 100644 index 000000000000..6f5df50693c1 --- /dev/null +++ b/salhelper/prj/d.lst @@ -0,0 +1,23 @@ +mkdir: %_DEST%\inc\salhelper + +..\inc\salhelper\condition.hxx %_DEST%\inc\salhelper\condition.hxx +..\inc\salhelper\dynload.hxx %_DEST%\inc\salhelper\dynload.hxx +..\inc\salhelper\future.hxx %_DEST%\inc\salhelper\future.hxx +..\inc\salhelper\futurequeue.hxx %_DEST%\inc\salhelper\futurequeue.hxx +..\inc\salhelper\monitor.hxx %_DEST%\inc\salhelper\monitor.hxx +..\inc\salhelper\queue.hxx %_DEST%\inc\salhelper\queue.hxx +..\inc\salhelper\linkhelper.hxx %_DEST%\inc\salhelper\linkhelper.hxx +..\inc\salhelper\refobj.hxx %_DEST%\inc\salhelper\refobj.hxx +..\inc\salhelper\simplereferenceobject.hxx %_DEST%\inc\salhelper\simplereferenceobject.hxx +..\inc\salhelper\singletonref.hxx %_DEST%\inc\salhelper\singletonref.hxx +..\inc\salhelper\timer.hxx %_DEST%\inc\salhelper\timer.hxx + +..\%__SRC%\bin\salhelp*.dll %_DEST%\bin\salhelp*.dll +..\%__SRC%\lib\*salhelper*.lib %_DEST%\lib\* + +..\%__SRC%\lib\libuno_salhelper*.* %_DEST%\lib\* + +..\%__SRC%\lib\libsalhelper*.a %_DEST%\lib\* +..\%__SRC%\lib\salhelper*.lib %_DEST%\lib\* + +linklib: libuno_salhelper*.*.* diff --git a/salhelper/qa/makefile.mk b/salhelper/qa/makefile.mk new file mode 100644 index 000000000000..fae96cfe6328 --- /dev/null +++ b/salhelper/qa/makefile.mk @@ -0,0 +1,52 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := .. +PRJNAME := salhelper +TARGET := qa + +ENABLE_EXCEPTIONS := TRUE + +.INCLUDE: settings.mk + +CFLAGSCXX += $(CPPUNIT_CFLAGS) + +SHL1TARGET = $(TARGET) +SHL1OBJS = $(SLO)$/test_api.obj +SHL1STDLIBS = $(CPPUNITLIB) $(SALLIB) $(SALHELPERLIB) +SHL1IMPLIB = i$(SHL1TARGET) +SHL1VERSIONMAP = version.map +DEF1NAME = $(SHL1TARGET) + +SLOFILES = $(SHL1OBJS) + +.INCLUDE: target.mk + +ALLTAR: test + +test .PHONY: $(SHL1TARGETN) + cd $(SHL1TARGETN:d) && $(TESTSHL2) $(SHL1TARGETN:f) diff --git a/salhelper/qa/test_api.cxx b/salhelper/qa/test_api.cxx new file mode 100644 index 000000000000..dfdbee59aa71 --- /dev/null +++ b/salhelper/qa/test_api.cxx @@ -0,0 +1,253 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "sal/config.h" + +#include <typeinfo> + +namespace salhelper { + class Condition; + class ConditionModifier; + class ConditionWaiter; + class ORealDynamicLoader; + class SimpleReferenceObject; +} + +namespace { + +std::type_info const & getConditionTypeInfo() +{ return typeid (salhelper::Condition *); } + +std::type_info const & getConditionModifierTypeInfo() +{ return typeid (salhelper::ConditionModifier *); } + +std::type_info const & getConditionWaiterTypeInfo() +{ return typeid (salhelper::ConditionWaiter *); } + +std::type_info const & getORealDynamicLoaderTypeInfo() +{ return typeid (salhelper::ORealDynamicLoader *); } + +std::type_info const & getSimpleReferenceObjectTypeInfo() +{ return typeid (salhelper::SimpleReferenceObject *); } + +} + +#include "testshl/simpleheader.hxx" +#include "osl/mutex.hxx" +#include "salhelper/condition.hxx" +#include "salhelper/dynload.hxx" +#include "salhelper/simplereferenceobject.hxx" + +#include <memory> + +namespace { + +class DerivedCondition: public salhelper::Condition { +public: + explicit DerivedCondition(osl::Mutex & mutex): Condition(mutex) {} + +protected: + virtual bool applies() const { return false; } +}; + +class DerivedConditionWaiterTimedout: + public salhelper::ConditionWaiter::timedout +{}; + +class DerivedSimpleReferenceObject: public salhelper::SimpleReferenceObject {}; + +class Test: public CppUnit::TestFixture { +public: + void testCondition(); + + void testConditionModifier(); + + void testConditionWaiter(); + + void testConditionWaiterTimedout(); + + void testORealDynamicLoader(); + + void testSimpleReferenceObject(); + + void testDerivedCondition(); + + void testDerivedConditionWaiterTimedout(); + + void testDerivedSimpleReferenceObject(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testCondition); + CPPUNIT_TEST(testConditionModifier); + CPPUNIT_TEST(testConditionWaiter); + CPPUNIT_TEST(testConditionWaiterTimedout); + CPPUNIT_TEST(testORealDynamicLoader); + CPPUNIT_TEST(testSimpleReferenceObject); + CPPUNIT_TEST(testDerivedCondition); + CPPUNIT_TEST(testDerivedConditionWaiterTimedout); + CPPUNIT_TEST(testDerivedSimpleReferenceObject); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::testCondition() { + osl::Mutex mutex; + std::auto_ptr< salhelper::Condition > p(new DerivedCondition(mutex)); + CPPUNIT_ASSERT(typeid (*p.get()) != typeid (salhelper::Condition)); + CPPUNIT_ASSERT(typeid (p.get()) == typeid (salhelper::Condition *)); + CPPUNIT_ASSERT( + typeid (const_cast< salhelper::Condition const * >(p.get())) + == typeid (salhelper::Condition const *)); + CPPUNIT_ASSERT( + typeid (const_cast< salhelper::Condition volatile * >(p.get())) + == typeid (salhelper::Condition volatile *)); + CPPUNIT_ASSERT(typeid (salhelper::Condition *) == getConditionTypeInfo()); +} + +void Test::testConditionModifier() { + salhelper::ConditionModifier * p = 0; + CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionModifier)); + CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionModifier *)); + CPPUNIT_ASSERT( + typeid (const_cast< salhelper::ConditionModifier const * >(p)) + == typeid (salhelper::ConditionModifier const *)); + CPPUNIT_ASSERT( + typeid (const_cast< salhelper::ConditionModifier volatile * >(p)) + == typeid (salhelper::ConditionModifier volatile *)); + CPPUNIT_ASSERT( + typeid (salhelper::ConditionModifier *) + == getConditionModifierTypeInfo()); +} + +void Test::testConditionWaiter() { + salhelper::ConditionWaiter * p = 0; + CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionWaiter)); + CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionWaiter *)); + CPPUNIT_ASSERT( + typeid (const_cast< salhelper::ConditionWaiter const * >(p)) + == typeid (salhelper::ConditionWaiter const *)); + CPPUNIT_ASSERT( + typeid (const_cast< salhelper::ConditionWaiter volatile * >(p)) + == typeid (salhelper::ConditionWaiter volatile *)); + CPPUNIT_ASSERT( + typeid (salhelper::ConditionWaiter *) == getConditionWaiterTypeInfo()); +} + +void Test::testConditionWaiterTimedout() { + salhelper::ConditionWaiter::timedout x; + CPPUNIT_ASSERT(typeid (x) == typeid (salhelper::ConditionWaiter::timedout)); + CPPUNIT_ASSERT( + typeid (&x) == typeid (salhelper::ConditionWaiter::timedout *)); + CPPUNIT_ASSERT( + typeid (const_cast< salhelper::ConditionWaiter::timedout const * >(&x)) + == typeid (salhelper::ConditionWaiter::timedout const *)); + CPPUNIT_ASSERT( + (typeid + (const_cast< salhelper::ConditionWaiter::timedout volatile * >(&x))) + == typeid (salhelper::ConditionWaiter::timedout volatile *)); + try { + throw salhelper::ConditionWaiter::timedout(); + } catch (salhelper::ConditionWaiter::timedout &) { + } catch (...) { + CPPUNIT_FAIL("not caught"); + } +} + +void Test::testORealDynamicLoader() { + salhelper::ORealDynamicLoader * p = 0; + CPPUNIT_ASSERT(typeid (p) != typeid (salhelper::ORealDynamicLoader)); + CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ORealDynamicLoader *)); + CPPUNIT_ASSERT( + typeid (const_cast< salhelper::ORealDynamicLoader const * >(p)) + == typeid (salhelper::ORealDynamicLoader const *)); + CPPUNIT_ASSERT( + typeid (const_cast< salhelper::ORealDynamicLoader volatile * >(p)) + == typeid (salhelper::ORealDynamicLoader volatile *)); + CPPUNIT_ASSERT( + typeid (salhelper::ORealDynamicLoader *) + == getORealDynamicLoaderTypeInfo()); +} + +void Test::testSimpleReferenceObject() { + salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject; + try { + CPPUNIT_ASSERT( + typeid (*p) != typeid (salhelper::SimpleReferenceObject)); + CPPUNIT_ASSERT( + typeid (p) == typeid (salhelper::SimpleReferenceObject *)); + CPPUNIT_ASSERT( + typeid (const_cast< salhelper::SimpleReferenceObject const * >(p)) + == typeid (salhelper::SimpleReferenceObject const *)); + CPPUNIT_ASSERT( + (typeid + (const_cast< salhelper::SimpleReferenceObject volatile * >(p))) + == typeid (salhelper::SimpleReferenceObject volatile *)); + CPPUNIT_ASSERT( + typeid (salhelper::SimpleReferenceObject *) + == getSimpleReferenceObjectTypeInfo()); + } catch (...) { + delete static_cast< DerivedSimpleReferenceObject * >(p); + throw; + } +} + +void Test::testDerivedCondition() { + osl::Mutex mutex; + std::auto_ptr< salhelper::Condition > p(new DerivedCondition(mutex)); + CPPUNIT_ASSERT(dynamic_cast< DerivedCondition * >(p.get()) != 0); +} + +void Test::testDerivedConditionWaiterTimedout() { + std::auto_ptr< salhelper::ConditionWaiter::timedout > p( + new DerivedConditionWaiterTimedout); + CPPUNIT_ASSERT( + dynamic_cast< DerivedConditionWaiterTimedout * >(p.get()) != 0); + try { + throw DerivedConditionWaiterTimedout(); + } catch (salhelper::ConditionWaiter::timedout &) { + } catch (...) { + CPPUNIT_FAIL("not caught"); + } +} + +void Test::testDerivedSimpleReferenceObject() { + salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject; + try { + CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject * >(p) != 0); + } catch (...) { + delete static_cast< DerivedSimpleReferenceObject * >(p); + throw; + } +} + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests"); + +} + +NOADDITIONAL; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/qa/version.map b/salhelper/qa/version.map new file mode 100755 index 000000000000..de41d83b562b --- /dev/null +++ b/salhelper/qa/version.map @@ -0,0 +1,6 @@ +UDK_3_0_0 { + global: + registerAllTestFunction; + local: + *; +}; diff --git a/salhelper/source/condition.cxx b/salhelper/source/condition.cxx new file mode 100644 index 000000000000..42e0676fbb96 --- /dev/null +++ b/salhelper/source/condition.cxx @@ -0,0 +1,145 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include <salhelper/condition.hxx> +#include <osl/time.h> + + +using namespace salhelper; + + +/****************************************************************** + * * + * Condition * + * * + ******************************************************************/ + +Condition::Condition(osl::Mutex& aMutex) + : m_aMutex(aMutex), + m_aCondition(osl_createCondition()) +{ +} + + +Condition::~Condition() +{ + osl_destroyCondition(m_aCondition); +} + + +/****************************************************************** + * * + * ConditionModifier * + * * + ******************************************************************/ + +ConditionModifier::ConditionModifier(Condition& aCond) + : m_aCond(aCond) +{ + m_aCond.m_aMutex.acquire(); +} + + +ConditionModifier::~ConditionModifier() +{ + if(m_aCond.applies()) + osl_setCondition(m_aCond.m_aCondition); + + m_aCond.m_aMutex.release(); +} + + + +/****************************************************************** + * * + * ConditionWaiter * + * * + ******************************************************************/ + +ConditionWaiter::timedout::timedout() {} + +ConditionWaiter::timedout::timedout(timedout const &) {} + +ConditionWaiter::timedout::~timedout() {} + +ConditionWaiter::timedout & +ConditionWaiter::timedout::operator =(timedout const &) { return *this; } + +ConditionWaiter::ConditionWaiter(Condition& aCond) + : m_aCond(aCond) +{ + while(true) { + osl_waitCondition(m_aCond.m_aCondition,0); + m_aCond.m_aMutex.acquire(); + + if(m_aCond.applies()) + break; + else { + osl_resetCondition(m_aCond.m_aCondition); + m_aCond.m_aMutex.release(); + } + } +} + + +ConditionWaiter::ConditionWaiter(Condition& aCond,sal_uInt32 milliSec) + throw( + ConditionWaiter::timedout + ) + : m_aCond(aCond) +{ + TimeValue aTime; + aTime.Seconds = milliSec / 1000; + aTime.Nanosec = 1000000 * ( milliSec % 1000 ); + + while(true) { + if( osl_waitCondition(m_aCond.m_aCondition,&aTime) == + osl_cond_result_timeout ) + throw timedout(); + + m_aCond.m_aMutex.acquire(); + + if(m_aCond.applies()) + break; + else { + osl_resetCondition(m_aCond.m_aCondition); + m_aCond.m_aMutex.release(); + } + } +} + + +ConditionWaiter::~ConditionWaiter() +{ + if(! m_aCond.applies()) + osl_resetCondition(m_aCond.m_aCondition); + m_aCond.m_aMutex.release(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/source/dynload.cxx b/salhelper/source/dynload.cxx new file mode 100644 index 000000000000..6db64f002de8 --- /dev/null +++ b/salhelper/source/dynload.cxx @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <salhelper/dynload.hxx> +#include <rtl/ustrbuf.hxx> + +namespace salhelper +{ + +typedef void* (SAL_CALL *ApiInitFunction) (void); + +ORealDynamicLoader::ORealDynamicLoader(ORealDynamicLoader ** ppSetToZeroInDestructor_, + const rtl::OUString& moduleName, + const rtl::OUString& initFunction, + void* pApi, + oslModule pModule) + : m_pApi(pApi) + , m_refCount(1) + , m_pModule(pModule) + , m_strModuleName(moduleName) + , m_strInitFunction(initFunction) + , ppSetToZeroInDestructor( ppSetToZeroInDestructor_ ) +{ +} + +ORealDynamicLoader* ORealDynamicLoader::newInstance(ORealDynamicLoader ** ppSetToZeroInDestructor, + const rtl::OUString& moduleName, + const rtl::OUString& initFunction) +{ + ApiInitFunction initFunc; + oslModule pModule = osl_loadModule(moduleName.pData, SAL_LOADMODULE_DEFAULT); + + if ( !pModule ) + { + return NULL; + } + + initFunc = (ApiInitFunction)osl_getFunctionSymbol( + pModule, initFunction.pData); + + if ( !initFunc ) + { + osl_unloadModule(pModule); + return NULL; + } + + return(new ORealDynamicLoader(ppSetToZeroInDestructor, moduleName, + initFunction, + initFunc(), + pModule)); +} + +ORealDynamicLoader::~ORealDynamicLoader() +{ + // set the address to zero + if( ppSetToZeroInDestructor ) + *ppSetToZeroInDestructor = 0; + + if (m_pModule) + { + osl_unloadModule(m_pModule); + m_pModule = NULL; + } +} + +sal_uInt32 ORealDynamicLoader::acquire() +{ + return ++m_refCount; +} + +sal_uInt32 ORealDynamicLoader::release() +{ + sal_uInt32 nRet = --m_refCount; + if( nRet == 0 ) + delete this; + return nRet; +} + + +void* ORealDynamicLoader::getApi() const +{ + return m_pApi; +} + +} // namespace salhelper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/source/gcc3.map b/salhelper/source/gcc3.map new file mode 100644 index 000000000000..7c63d5d9ee24 --- /dev/null +++ b/salhelper/source/gcc3.map @@ -0,0 +1,96 @@ +UDK_3_0_0 { # should have been UDK_3.0 + global: + GetVersionInfo; + _ZN9salhelper18ORealDynamicLoader11newInstanceEPPS0_RKN3rtl8OUStringES6_; + _ZN9salhelper18ORealDynamicLoader7acquireEv; + _ZN9salhelper18ORealDynamicLoader7releaseEv; + _ZN9salhelper18ORealDynamicLoaderC1EPPS0_RKN3rtl8OUStringES6_PvS7_; + _ZN9salhelper18ORealDynamicLoaderC2EPPS0_RKN3rtl8OUStringES6_PvS7_; + _ZN9salhelper18ORealDynamicLoaderD0Ev; + _ZN9salhelper18ORealDynamicLoaderD1Ev; + _ZN9salhelper18ORealDynamicLoaderD2Ev; + _ZN9salhelper21SimpleReferenceObjectD0Ev; + _ZN9salhelper21SimpleReferenceObjectD1Ev; + _ZN9salhelper21SimpleReferenceObjectD2Ev; + _ZN9salhelper21SimpleReferenceObjectdlEPv; + + # Introducing a question mark at the end because of + # marginal type discrepancy there is a difference in the + # mangled name between Linux and Mac OS X, see #i69351# + _ZN9salhelper21SimpleReferenceObjectnwE?; # salhelper::SimpleReferenceObject::operator new (std::size_t) + + _ZNK9salhelper18ORealDynamicLoader6getApiEv; + # _ZTIN9salhelper18ORealDynamicLoaderE; + # _ZTSN9salhelper18ORealDynamicLoaderE; + _ZTVN9salhelper18ORealDynamicLoaderE; + # _ZTIN9salhelper21SimpleReferenceObjectE; + # _ZTSN9salhelper21SimpleReferenceObjectE; + _ZTVN9salhelper21SimpleReferenceObjectE; + + local: + *; +}; + +UDK_3.1 { + global: + _ZN9salhelper21SimpleReferenceObjectdlEPvRKSt9nothrow_t; + + # Introducing a wildcard right in the middle because due to + # marginal type discrepancy there is a difference in the + # mangled name between Linux and Mac OS X see #i69351# + _ZN9salhelper21SimpleReferenceObjectnwE?RKSt9nothrow_t; # salhelper::SimpleReferenceObject::operator new (std::size_t, std::nothrow_t const&) + + _ZN9salhelper9ConditionC1ERN3osl5MutexE; + _ZN9salhelper9ConditionC2ERN3osl5MutexE; + _ZN9salhelper9ConditionD0Ev; + _ZN9salhelper9ConditionD1Ev; + _ZN9salhelper9ConditionD2Ev; + # _ZTIN9salhelper9ConditionE; + # _ZTIS9salhelper9ConditionE; + + _ZN9salhelper17ConditionModifierC1ERNS_9ConditionE; + _ZN9salhelper17ConditionModifierC2ERNS_9ConditionE; + _ZN9salhelper17ConditionModifierD1Ev; + _ZN9salhelper17ConditionModifierD2Ev; + + _ZN9salhelper15ConditionWaiterC1ERNS_9ConditionE; + _ZN9salhelper15ConditionWaiterC1ERNS_9ConditionE?; + _ZN9salhelper15ConditionWaiterC2ERNS_9ConditionE; + _ZN9salhelper15ConditionWaiterC2ERNS_9ConditionE?; + _ZN9salhelper15ConditionWaiterD1Ev; + _ZN9salhelper15ConditionWaiterD2Ev; + + _ZN9salhelper15ConditionWaiter8timedoutaSERKS1_; + _ZN9salhelper15ConditionWaiter8timedoutC1ERKS1_; + _ZN9salhelper15ConditionWaiter8timedoutC1Ev; + _ZN9salhelper15ConditionWaiter8timedoutC2ERKS1_; + _ZN9salhelper15ConditionWaiter8timedoutC2Ev; + _ZN9salhelper15ConditionWaiter8timedoutD0Ev; + _ZN9salhelper15ConditionWaiter8timedoutD1Ev; + _ZN9salhelper15ConditionWaiter8timedoutD2Ev; + # _ZTIN9salhelper15ConditionWaiter8timedoutE; + # _ZTSN9salhelper15ConditionWaiter8timedoutE; + + + _ZN9salhelper5TimerC1ERKNS_10TTimeValueE; + _ZN9salhelper5TimerC1ERKNS_10TTimeValueES3_; + _ZN9salhelper5TimerC1Ev; + _ZN9salhelper5TimerC2ERKNS_10TTimeValueE; + _ZN9salhelper5TimerC2ERKNS_10TTimeValueES3_; + _ZN9salhelper5TimerC2Ev; + _ZN9salhelper5TimerD0Ev; + _ZN9salhelper5TimerD1Ev; + _ZN9salhelper5TimerD2Ev; + _ZN9salhelper5Timer5startEv; + _ZN9salhelper5Timer4stopEv; + _ZNK9salhelper5Timer9isTickingEv; + _ZNK9salhelper5Timer9isExpiredEv; + _ZNK9salhelper5Timer13expiresBeforeEPKS0_; + _ZN9salhelper5Timer15setAbsoluteTimeERKNS_10TTimeValueE; + _ZN9salhelper5Timer16setRemainingTimeERKNS_10TTimeValueE; + _ZN9salhelper5Timer16setRemainingTimeERKNS_10TTimeValueES3_; + _ZN9salhelper5Timer7addTimeERKNS_10TTimeValueE; + _ZNK9salhelper5Timer16getRemainingTimeEv; + + +} UDK_3_0_0; diff --git a/salhelper/source/makefile.mk b/salhelper/source/makefile.mk new file mode 100644 index 000000000000..8c7d8a2c0963 --- /dev/null +++ b/salhelper/source/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=.. + +PRJNAME=salhelper +TARGET=salhelper + +ENABLE_EXCEPTIONS=TRUE +NO_BSYMBOLIC=TRUE +USE_DEFFILE=TRUE + +.IF "$(OS)" != "WNT" +UNIXVERSIONNAMES=UDK +.ENDIF # WNT + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/condition.obj \ + $(SLO)$/dynload.obj \ + $(SLO)$/simplereferenceobject.obj \ + $(SLO)$/timer.obj + +.IF "$(COM)" == "MSC" +SHL1TARGET= $(TARGET)$(UDK_MAJOR)$(COMID) +SHL1IMPLIB= i$(TARGET) +.ELSE +SHL1TARGET= uno_$(TARGET)$(COMID) +SHL1IMPLIB= $(SHL1TARGET) +.ENDIF + +SHL1STDLIBS=$(SALLIB) + +SHL1DEPN= +SHL1LIBS= $(SLB)$/$(TARGET).lib +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +SHL1RPATH= URELIB + +DEF1NAME= $(SHL1TARGET) + +.IF "$(COMNAME)"=="msci" +SHL1VERSIONMAP=msci.map +.ELIF "$(COMNAME)"=="mscx" +SHL1VERSIONMAP=mscx.map +.ELIF "$(COMNAME)"=="sunpro5" +SHL1VERSIONMAP=sols.map +.ELIF "$(COMNAME)"=="gcc3" +SHL1VERSIONMAP=gcc3.map +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/salhelper/source/msci.map b/salhelper/source/msci.map new file mode 100644 index 000000000000..b0359e0c7166 --- /dev/null +++ b/salhelper/source/msci.map @@ -0,0 +1,50 @@ +UDK_3_0_0 { + global: +GetVersionInfo +??0ORealDynamicLoader@salhelper@@IAE@PAPAV01@ABVOUString@rtl@@1PAX2@Z +??1ORealDynamicLoader@salhelper@@MAE@XZ +??_7ORealDynamicLoader@salhelper@@6B@ +?acquire@ORealDynamicLoader@salhelper@@QAAKXZ +?getApi@ORealDynamicLoader@salhelper@@QBAPAXXZ +?newInstance@ORealDynamicLoader@salhelper@@SAPAV12@PAPAV12@ABVOUString@rtl@@1@Z +?release@ORealDynamicLoader@salhelper@@QAAKXZ +??1SimpleReferenceObject@salhelper@@MAE@XZ +??2SimpleReferenceObject@salhelper@@SAPAXI@Z +??2SimpleReferenceObject@salhelper@@SAPAXIABUnothrow_t@std@@@Z +??3SimpleReferenceObject@salhelper@@SAXPAX@Z +??3SimpleReferenceObject@salhelper@@SAXPAXABUnothrow_t@std@@@Z + local: + *; +}; + +UDK_3.1 { + global: + ??_VSimpleReferenceObject@salhelper@@KAXPAX@Z; + ??_7SimpleReferenceObject@salhelper@@6B@; + + ??0Condition@salhelper@@QAE@AAVMutex@osl@@@Z; + ??1Condition@salhelper@@UAE@XZ; + + ??0ConditionModifier@salhelper@@QAE@AAVCondition@1@@Z; + ??1ConditionModifier@salhelper@@QAE@XZ; + + ??0ConditionWaiter@salhelper@@QAE@AAVCondition@1@@Z; + ??0ConditionWaiter@salhelper@@QAE@AAVCondition@1@K@Z; + ??1ConditionWaiter@salhelper@@QAE@XZ; + + ??0timedout@ConditionWaiter@salhelper@@QAE@XZ; + ??0timedout@ConditionWaiter@salhelper@@QAE@ABU012@@Z; + ??1timedout@ConditionWaiter@salhelper@@UAE@XZ; + ??4timedout@ConditionWaiter@salhelper@@QAEAAU012@ABU012@@Z; + + ??0Timer@salhelper@@QAE@XZ; + ??0Timer@salhelper@@QAE@ABUTTimeValue@1@@Z; + ??0Timer@salhelper@@QAE@ABUTTimeValue@1@0@Z; + ??1Timer@salhelper@@MAE@XZ; + + ?isExpired@Timer@salhelper@@QBAEXZ; + ?isTicking@Timer@salhelper@@QBAEXZ; + ?setRemainingTime@Timer@salhelper@@QAAXABUTTimeValue@2@@Z; + ?start@Timer@salhelper@@QAAXXZ; + ?stop@Timer@salhelper@@QAAXXZ; +} UDK_3_0_0; diff --git a/salhelper/source/mscx.map b/salhelper/source/mscx.map new file mode 100644 index 000000000000..58f26e9041ab --- /dev/null +++ b/salhelper/source/mscx.map @@ -0,0 +1,50 @@ +UDK_3_0_0 { + global: +GetVersionInfo +??0ORealDynamicLoader@salhelper@@IEAA@PEAPEAV01@AEBVOUString@rtl@@1PEAX2@Z +??1ORealDynamicLoader@salhelper@@MEAA@XZ +??_7ORealDynamicLoader@salhelper@@6B@ +?acquire@ORealDynamicLoader@salhelper@@QEAAKXZ +?getApi@ORealDynamicLoader@salhelper@@QEBAPEAXXZ +?newInstance@ORealDynamicLoader@salhelper@@SAPEAV12@PEAPEAV12@AEBVOUString@rtl@@1@Z +?release@ORealDynamicLoader@salhelper@@QEAAKXZ +??1SimpleReferenceObject@salhelper@@MEAA@XZ +??2SimpleReferenceObject@salhelper@@SAPEAX_K@Z +??2SimpleReferenceObject@salhelper@@SAPEAX_KAEBUnothrow_t@std@@@Z +??3SimpleReferenceObject@salhelper@@SAXPEAX@Z +??3SimpleReferenceObject@salhelper@@SAXPEAXAEBUnothrow_t@std@@@Z + local: + *; +}; + +UDK_3.1 { + global: + ??_VSimpleReferenceObject@salhelper@@KAXPEAX@Z; + ??_7SimpleReferenceObject@salhelper@@6B@; + + ??0Condition@salhelper@@QEAA@AEAVMutex@osl@@@Z; + ??1Condition@salhelper@@UEAA@XZ; + + ??0ConditionModifier@salhelper@@QEAA@AEAVCondition@1@@Z; + ??1ConditionModifier@salhelper@@QEAA@XZ; + + ??0ConditionWaiter@salhelper@@QEAA@AEAVCondition@1@@Z; + ??0ConditionWaiter@salhelper@@QEAA@AEAVCondition@1@K@Z; + ??1ConditionWaiter@salhelper@@QEAA@XZ; + + ??0timedout@ConditionWaiter@salhelper@@QEAA@XZ; + ??0timedout@ConditionWaiter@salhelper@@QEAA@AEBU012@@Z; + ??1timedout@ConditionWaiter@salhelper@@UEAA@XZ; + ??4timedout@ConditionWaiter@salhelper@@QEAAAEAU012@AEBU012@@Z; + + ??0Timer@salhelper@@QEAA@XZ; + ??0Timer@salhelper@@QEAA@AEBUTTimeValue@1@@Z; + ??0Timer@salhelper@@QEAA@AEBUTTimeValue@1@0@Z; + ??1Timer@salhelper@@MEAA@XZ; + + ?isExpired@Timer@salhelper@@QEBAEXZ; + ?isTicking@Timer@salhelper@@QEBAEXZ; + ?setRemainingTime@Timer@salhelper@@QEAAXAEBUTTimeValue@2@@Z; + ?start@Timer@salhelper@@QEAAXXZ; + ?stop@Timer@salhelper@@QEAAXXZ; +} UDK_3_0_0; diff --git a/salhelper/source/simplereferenceobject.cxx b/salhelper/source/simplereferenceobject.cxx new file mode 100644 index 000000000000..6df42cc1c930 --- /dev/null +++ b/salhelper/source/simplereferenceobject.cxx @@ -0,0 +1,92 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "salhelper/simplereferenceobject.hxx" +#include "osl/diagnose.h" + +#ifndef INCLUDED_NEW +#include <new> +#define INCLUDED_NEW +#endif + +using salhelper::SimpleReferenceObject; + +SimpleReferenceObject::~SimpleReferenceObject() SAL_THROW(()) +{ + OSL_ASSERT(m_nCount == 0); +} + +void * SimpleReferenceObject::operator new(std::size_t nSize) + SAL_THROW((std::bad_alloc)) +{ + return ::operator new(nSize); +} + +void * SimpleReferenceObject::operator new(std::size_t nSize, + std::nothrow_t const &) + SAL_THROW(()) +{ +#if defined WNT + return ::operator new(nSize); + // WNT lacks a global nothrow operator new... +#else // WNT + return ::operator new(nSize, std::nothrow); +#endif // WNT +} + +void SimpleReferenceObject::operator delete(void * pPtr) SAL_THROW(()) +{ + ::operator delete(pPtr); +} + +void SimpleReferenceObject::operator delete(void * pPtr, std::nothrow_t const &) + SAL_THROW(()) +{ +#if defined WNT + ::operator delete(pPtr); // WNT lacks a global nothrow operator delete... +#else // WNT + ::operator delete(pPtr, std::nothrow); +#endif // WNT +} + +#ifdef _MSC_VER + +/* This operator is supposed to be unimplemented, but that now leads + * to compilation and/or linking errors with MSVC2008. (Don't know + * about MSVC2010.) As it can be left unimplemented just fine with + * gcc, presumably it is never called. So do implement it then to + * avoid the compilation and/or linking errors, but make it crash + * intentionally if called. + */ +void SimpleReferenceObject::operator delete[](void * /* pPtr */) +{ + free(NULL); +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/source/sols.map b/salhelper/source/sols.map new file mode 100644 index 000000000000..69454b71089b --- /dev/null +++ b/salhelper/source/sols.map @@ -0,0 +1,76 @@ +UDK_3.1 { # OOo 1.1.2 SDK + global: + __1cJsalhelperJCondition2t6MrnDoslFMutex__v_; + __1cJsalhelperJCondition2t5B6MrnDoslFMutex__v_; + __1cJsalhelperJCondition2T6M_v_; + __1cJsalhelperJCondition2T5B6M_v_; + __1cJsalhelperbF__RTTI__1nJsalhelperJCondition__; + __1cJsalhelperbH__RTTI__1CpnJsalhelperJCondition__; + __1cJsalhelperbI__RTTI__1CpknJsalhelperJCondition__; + + __1cJsalhelperRConditionModifier2t6Mrn0AJCondition__v_; + __1cJsalhelperRConditionModifier2t5B6Mrn0AJCondition__v_; + __1cJsalhelperRConditionModifier2T6M_v_; + __1cJsalhelperRConditionModifier2T5B6M_v_; + + __1cJsalhelperPConditionWaiter2t6Mrn0AJCondition__v_; + __1cJsalhelperPConditionWaiter2t5B6Mrn0AJCondition__v_; + __1cJsalhelperPConditionWaiter2t6Mrn0AJCondition_L_v_; #S-ILP32 + __1cJsalhelperPConditionWaiter2t6Mrn0AJCondition_I_v_; #S-LP64 + __1cJsalhelperPConditionWaiter2t5B6Mrn0AJCondition_L_v_; #S-ILP32 + __1cJsalhelperPConditionWaiter2t5B6Mrn0AJCondition_I_v_; #S-LP64 + __1cJsalhelperPConditionWaiter2T6M_v_; + __1cJsalhelperPConditionWaiter2T5B6M_v_; + + __1cJsalhelperPConditionWaiterItimedout2t6M_v_; + __1cJsalhelperPConditionWaiterItimedout2t5B6M_v_; + __1cJsalhelperPConditionWaiterItimedout2t6Mrk2_v_; + __1cJsalhelperPConditionWaiterItimedout2t5B6Mrk2_v_; + __1cJsalhelperPConditionWaiterItimedout2T6M_v_; + __1cJsalhelperPConditionWaiterItimedout2T5B6M_v_; + __1cJsalhelperPConditionWaiterItimedout2G6Mrk2_r2_; + __1cJsalhelperbU__RTTI__1nJsalhelperPConditionWaiterItimedout__; + __1cJsalhelperbW__RTTI__1CpnJsalhelperPConditionWaiterItimedout__; + __1cJsalhelperbX__RTTI__1CpknJsalhelperPConditionWaiterItimedout__; +} UDK_3.0; + +UDK_3.0 { + global: +GetVersionInfo; +__1cJsalhelperSORealDynamicLoaderLnewInstance6Fpp1rknDrtlIOUString_7_2_; +__1cJsalhelperSORealDynamicLoader2t5B6Mpp1rknDrtlIOUString_7pv8_v_; +__1cJsalhelperSORealDynamicLoader2t6Mpp1rknDrtlIOUString_7pv8_v_; +__1cJsalhelperSORealDynamicLoaderG__vtbl_; +__1cJsalhelperSORealDynamicLoader2T5B6M_v_; +__1cJsalhelperSORealDynamicLoader2T6M_v_; +__1cJsalhelperbR__RTTI__1CpknJsalhelperSORealDynamicLoader__; +__1cJsalhelperbQ__RTTI__1CpnJsalhelperSORealDynamicLoader__; +__1cJsalhelperbO__RTTI__1nJsalhelperSORealDynamicLoader__; +__1cJsalhelperSORealDynamicLoaderHacquire6M_L_; #S-ILP32 +__1cJsalhelperSORealDynamicLoaderHacquire6M_I_; #S-LP64 +__1cJsalhelperSORealDynamicLoaderHrelease6M_L_; #S-ILP32 +__1cJsalhelperSORealDynamicLoaderHrelease6M_I_; #S-LP64 +__1cJsalhelperSORealDynamicLoaderGgetApi6kM_pv_; +__1cJsalhelperVSimpleReferenceObject2T5B6M_v_; +__1cJsalhelperVSimpleReferenceObject2T6M_v_; +__1cJsalhelperVSimpleReferenceObject2k6Fpv_v_; +__1cJsalhelperVSimpleReferenceObject2k6FpvrknDstdJnothrow_t__v_; +__1cJsalhelperVSimpleReferenceObject2n6FI_pv_; #S-ILP32 +__1cJsalhelperVSimpleReferenceObject2n6FL_pv_; #S-LP64 +__1cJsalhelperVSimpleReferenceObject2n6FIrknDstdJnothrow_t__pv_; #S-ILP32 +__1cJsalhelperVSimpleReferenceObject2n6FLrknDstdJnothrow_t__pv_; #S-LP64 +__1cJsalhelperVSimpleReferenceObjectG__vtbl_; +__1cJsalhelperbR__RTTI__1nJsalhelperVSimpleReferenceObject__; +__1cJsalhelperbT__RTTI__1CpnJsalhelperVSimpleReferenceObject__; +__1cJsalhelperbU__RTTI__1CpknJsalhelperVSimpleReferenceObject__; + local: + *; +} SALHLP_1_0; + +SALHLP_1_0 { # WEAK (backward compatibility, should have been UDK_3.0) +}; + +{ # BASE +_init; +_fini; +}; diff --git a/salhelper/source/timer.cxx b/salhelper/source/timer.cxx new file mode 100644 index 000000000000..aff006c95e8b --- /dev/null +++ b/salhelper/source/timer.cxx @@ -0,0 +1,488 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <salhelper/timer.hxx> + +#include <osl/diagnose.h> +#include <salhelper/simplereferenceobject.hxx> +#include <osl/thread.hxx> +#include <osl/conditn.hxx> +#include <osl/mutex.hxx> + +using namespace salhelper; + +class salhelper::TimerManager : public osl::Thread +{ + +public: + + /// + TimerManager(); + + /// + ~TimerManager(); + + /// register timer + sal_Bool SAL_CALL registerTimer(salhelper::Timer* pTimer); + + /// unregister timer + sal_Bool SAL_CALL unregisterTimer(salhelper::Timer* pTimer); + + /// lookup timer + sal_Bool SAL_CALL lookupTimer(const salhelper::Timer* pTimer); + + /// retrieves the "Singleton" TimerManager Instance + static TimerManager* SAL_CALL getTimerManager(); + + +protected: + + /// worker-function of thread + virtual void SAL_CALL run(); + + // Checking and triggering of a timer event + void SAL_CALL checkForTimeout(); + + // cleanup Method + virtual void SAL_CALL onTerminated(); + + // sorted-queue data + salhelper::Timer* m_pHead; + // List Protection + osl::Mutex m_Lock; + // Signal the insertion of a timer + osl::Condition m_notEmpty; + + // Synchronize access to TimerManager + static osl::Mutex m_Access; + + // "Singleton Pattern" + static salhelper::TimerManager* m_pManager; + + friend class TimerManagerCleanup; + +}; + +using namespace salhelper; + +///////////////////////////////////////////////////////////////////////////// +// +// Timer class +// + +Timer::Timer() + : m_aTimeOut( 0 ), + m_aExpired( 0 ), + m_aRepeatDelta( 0 ), + m_pNext( NULL ) +{ +} + +Timer::Timer( const TTimeValue& Time ) + : m_aTimeOut( Time ), + m_aExpired( 0 ), + m_aRepeatDelta( 0 ), + m_pNext( NULL ) +{ +} + +Timer::Timer( const TTimeValue& Time, const TTimeValue& Repeat ) + : m_aTimeOut( Time ), + m_aExpired( 0 ), + m_aRepeatDelta( Repeat ), + m_pNext( NULL ) +{ +} + +Timer::~Timer() +{ + stop(); +} + +void Timer::start() +{ + if (! isTicking()) + { + if (! m_aTimeOut.isEmpty()) + setRemainingTime(m_aTimeOut); + + TimerManager *pManager = TimerManager::getTimerManager(); + + OSL_ASSERT(pManager); + + if ( pManager != 0 ) + { + pManager->registerTimer(this); + } + } +} + +void Timer::stop() +{ + TimerManager *pManager = TimerManager::getTimerManager(); + + OSL_ASSERT(pManager); + + if ( pManager != 0 ) + { + pManager->unregisterTimer(this); + } +} + +sal_Bool Timer::isTicking() const +{ + TimerManager *pManager = TimerManager::getTimerManager(); + + OSL_ASSERT(pManager); + + if (pManager) + return pManager->lookupTimer(this); + else + return sal_False; + +} + +sal_Bool Timer::isExpired() const +{ + TTimeValue Now; + + osl_getSystemTime(&Now); + + return !(Now < m_aExpired); +} + +sal_Bool Timer::expiresBefore(const Timer* pTimer) const +{ + OSL_ASSERT(pTimer); + + if ( pTimer != 0 ) + { + return m_aExpired < pTimer->m_aExpired; + } + else + { + return sal_False; + } +} + +void Timer::setAbsoluteTime(const TTimeValue& Time) +{ + m_aTimeOut = 0; + m_aExpired = Time; + m_aRepeatDelta = 0; + + m_aExpired.normalize(); +} + +void Timer::setRemainingTime(const TTimeValue& Remaining) +{ + osl_getSystemTime(&m_aExpired); + + m_aExpired.addTime(Remaining); +} + +void Timer::setRemainingTime(const TTimeValue& Remaining, const TTimeValue& Repeat) +{ + osl_getSystemTime(&m_aExpired); + + m_aExpired.addTime(Remaining); + + m_aRepeatDelta = Repeat; +} + +void Timer::addTime(const TTimeValue& Delta) +{ + m_aExpired.addTime(Delta); +} + +TTimeValue Timer::getRemainingTime() const +{ + TTimeValue Now; + + osl_getSystemTime(&Now); + + sal_Int32 secs = m_aExpired.Seconds - Now.Seconds; + + if (secs < 0) + return TTimeValue(0, 0); + + sal_Int32 nsecs = m_aExpired.Nanosec - Now.Nanosec; + + if (nsecs < 0) + { + if (secs > 0) + { + secs -= 1; + nsecs += 1000000000L; + } + else + return TTimeValue(0, 0); + } + + return TTimeValue(secs, nsecs); +} + + +///////////////////////////////////////////////////////////////////////////// +// +// Timer manager +// + +osl::Mutex salhelper::TimerManager::m_Access; +TimerManager* salhelper::TimerManager::m_pManager = NULL; + +TimerManager::TimerManager() +{ + osl::MutexGuard Guard(&m_Access); + + OSL_ASSERT(m_pManager == 0); + + m_pManager = this; + + m_pHead= 0; + + m_notEmpty.reset(); + + // start thread + create(); +} + +TimerManager::~TimerManager() +{ + osl::MutexGuard Guard(&m_Access); + + if ( m_pManager == this ) + m_pManager = 0; +} + +void TimerManager::onTerminated() +{ + delete this; // mfe: AAARRRGGGHHH!!! +} + +TimerManager* TimerManager::getTimerManager() +{ + osl::MutexGuard Guard(&m_Access); + + if (! m_pManager) + new TimerManager; + + return (m_pManager); +} + +sal_Bool TimerManager::registerTimer(Timer* pTimer) +{ + OSL_ASSERT(pTimer); + + if ( pTimer == 0 ) + { + return sal_False; + } + + osl::MutexGuard Guard(&m_Lock); + + // try to find one with equal or lower remaining time. + Timer** ppIter = &m_pHead; + + while (*ppIter) + { + if (pTimer->expiresBefore(*ppIter)) + { + // next element has higher remaining time, + // => insert new timer before + break; + } + ppIter= &((*ppIter)->m_pNext); + } + + // next element has higher remaining time, + // => insert new timer before + pTimer->m_pNext= *ppIter; + *ppIter = pTimer; + + + if (pTimer == m_pHead) + { + // it was inserted as new head + // signal it to TimerManager Thread + m_notEmpty.set(); + } + + return sal_True; +} + +sal_Bool TimerManager::unregisterTimer(Timer* pTimer) +{ + OSL_ASSERT(pTimer); + + if ( pTimer == 0 ) + { + return sal_False; + } + + // lock access + osl::MutexGuard Guard(&m_Lock); + + Timer** ppIter = &m_pHead; + + while (*ppIter) + { + if (pTimer == (*ppIter)) + { + // remove timer from list + *ppIter = (*ppIter)->m_pNext; + return sal_True; + } + ppIter= &((*ppIter)->m_pNext); + } + + return sal_False; +} + +sal_Bool TimerManager::lookupTimer(const Timer* pTimer) +{ + OSL_ASSERT(pTimer); + + if ( pTimer == 0 ) + { + return sal_False; + } + + // lock access + osl::MutexGuard Guard(&m_Lock); + + // check the list + for (Timer* pIter = m_pHead; pIter != 0; pIter= pIter->m_pNext) + { + if (pIter == pTimer) + { + return sal_True; + } + } + + return sal_False; +} + +void TimerManager::checkForTimeout() +{ + + m_Lock.acquire(); + + if ( m_pHead == 0 ) + { + m_Lock.release(); + return; + } + + Timer* pTimer = m_pHead; + + if (pTimer->isExpired()) + { + // remove expired timer + m_pHead = pTimer->m_pNext; + + pTimer->acquire(); + + m_Lock.release(); + + pTimer->onShot(); + + // restart timer if specified + if ( ! pTimer->m_aRepeatDelta.isEmpty() ) + { + TTimeValue Now; + + osl_getSystemTime(&Now); + + Now.Seconds += pTimer->m_aRepeatDelta.Seconds; + Now.Nanosec += pTimer->m_aRepeatDelta.Nanosec; + + pTimer->m_aExpired = Now; + + registerTimer(pTimer); + } + pTimer->release(); + } + else + { + m_Lock.release(); + } + + + return; +} + +void TimerManager::run() +{ + setPriority( osl_Thread_PriorityBelowNormal ); + + while (schedule()) + { + TTimeValue delay; + TTimeValue* pDelay=0; + + + m_Lock.acquire(); + + if (m_pHead != 0) + { + delay = m_pHead->getRemainingTime(); + pDelay=&delay; + } + else + { + pDelay=0; + } + + + m_notEmpty.reset(); + + m_Lock.release(); + + + m_notEmpty.wait(pDelay); + + checkForTimeout(); + } + +} + + +///////////////////////////////////////////////////////////////////////////// +// +// Timer manager cleanup +// + +// jbu: +// The timer manager cleanup has been removed (no thread is killed anymore). +// So the thread leaks. +// This will result in a GPF in case the salhelper-library gets unloaded before +// process termination. +// -> TODO : rewrite this file, so that the timerManager thread gets destroyed, +// when there are no timers anymore ! + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/test/Symbols/loader.cxx b/salhelper/test/Symbols/loader.cxx new file mode 100644 index 000000000000..f6c862eda3f2 --- /dev/null +++ b/salhelper/test/Symbols/loader.cxx @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +#include <salhelper/dynload.hxx> +#include <rtl/ustring> +#include <stdio.h> +#include "samplelib.hxx" + + +using namespace salhelper; + +using ::rtl::OUString; + + +class SampleLibLoader + : public ::salhelper::ODynamicLoader<SampleLib_Api> +{ +public: + SampleLibLoader(): + ::salhelper::ODynamicLoader<SampleLib_Api> + (::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SAL_MODULENAME( "samplelib") ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(SAMPLELIB_INIT_FUNCTION_NAME) )) + {} + +}; + + +int main( int argc, char *argv[ ], char *envp[ ] ) +{ + SampleLibLoader Loader; + SampleLibLoader Loader2; + Loader= Loader2; + SampleLib_Api *pApi= Loader.getApi(); + + sal_Int32 retint= pApi->funcA( 10); + double retdouble= pApi->funcB( 3.14); + + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/test/Symbols/makefile.mk b/salhelper/test/Symbols/makefile.mk new file mode 100644 index 000000000000..e91066670601 --- /dev/null +++ b/salhelper/test/Symbols/makefile.mk @@ -0,0 +1,95 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/ + +PRJNAME=salhelper +TARGET=dynloader +TARGET1=samplelib +TARGETTYPE=CUI +LIBTARGET=NO + +NO_BSYMBOLIC= TRUE +ENABLE_EXCEPTIONS=TRUE + +# --- Settings --- + +.INCLUDE : settings.mk + +# --- Files --- + +#RTTI on +.IF "$(OS)" == "WNT" +CFLAGS+= -GR +.ENDIF + + +#--------------------------------------------------------------------------- +# Build the test library which is loaded by the +# RealDynamicLoader + +SLOFILES= $(SLO)$/samplelib.obj + +LIB1TARGET= $(SLB)$/$(TARGET1).lib +LIB1OBJFILES= $(SLOFILES) + + +SHL1TARGET= $(TARGET1) + +SHL1STDLIBS= \ + $(SALLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(TARGET1) +SHL1LIBS= $(SLB)$/$(TARGET1).lib +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEFLIB1NAME= $(TARGET1) +DEF1DEPN= $(MISC)$/$(SHL1TARGET).flt + +# ------------------------------------------------------------------------------ + +OBJFILES= $(OBJ)$/loader.obj + +APP1TARGET= $(TARGET) +APP1OBJS= $(OBJFILES) + +APP1STDLIBS= \ + $(SALHELPERLIB) \ + $(SALLIB) + +APP1DEF= $(MISC)\$(APP1TARGET).def + +# --- Targets --- + +.INCLUDE : target.mk + +$(MISC)$/$(SHL1TARGET).flt: makefile.mk + @echo ------------------------------ + @echo Making: $@ + @echo __CT>>$@ diff --git a/salhelper/test/Symbols/samplelib.cxx b/salhelper/test/Symbols/samplelib.cxx new file mode 100644 index 000000000000..6f66aa73f324 --- /dev/null +++ b/salhelper/test/Symbols/samplelib.cxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#include "samplelib.hxx" +#include <sal/types.h> +/* + + +*/ + +extern "C" +SampleLib_Api* SAL_CALL initSampleLibApi(void) +{ + static SampleLib_Api aApi= {0,0}; + if (!aApi.funcA) + { + aApi.funcA= &funcA; + aApi.funcB= &funcB; + return (&aApi); + } + else + { + return (&aApi); + } + +} + + +sal_Int32 SAL_CALL funcA( sal_Int32 a) +{ + return a; +} + + +double SAL_CALL funcB( double a) +{ + return a; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/test/Symbols/samplelib.hxx b/salhelper/test/Symbols/samplelib.hxx new file mode 100644 index 000000000000..fbe96c372a84 --- /dev/null +++ b/salhelper/test/Symbols/samplelib.hxx @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#ifndef __SAMPLELIB_HXX_ +#define __SAMPLELIB_HXX_ + +#include <sal/types.h> + +struct SampleLib_Api +{ + sal_Int32 (SAL_CALL *funcA)( sal_Int32 ); + double (SAL_CALL *funcB)( double ); +}; + + +typedef SampleLib_Api* (SAL_CALL *InitSampleLib_Api)(void); + +#define SAMPLELIB_INIT_FUNCTION_NAME "initSampleLibApi" + + +sal_Int32 SAL_CALL funcA( sal_Int32 a); +double SAL_CALL funcB( double a); + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/test/dynamicloader/loader.cxx b/salhelper/test/dynamicloader/loader.cxx new file mode 100644 index 000000000000..f6c862eda3f2 --- /dev/null +++ b/salhelper/test/dynamicloader/loader.cxx @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +#include <salhelper/dynload.hxx> +#include <rtl/ustring> +#include <stdio.h> +#include "samplelib.hxx" + + +using namespace salhelper; + +using ::rtl::OUString; + + +class SampleLibLoader + : public ::salhelper::ODynamicLoader<SampleLib_Api> +{ +public: + SampleLibLoader(): + ::salhelper::ODynamicLoader<SampleLib_Api> + (::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SAL_MODULENAME( "samplelib") ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(SAMPLELIB_INIT_FUNCTION_NAME) )) + {} + +}; + + +int main( int argc, char *argv[ ], char *envp[ ] ) +{ + SampleLibLoader Loader; + SampleLibLoader Loader2; + Loader= Loader2; + SampleLib_Api *pApi= Loader.getApi(); + + sal_Int32 retint= pApi->funcA( 10); + double retdouble= pApi->funcB( 3.14); + + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/test/dynamicloader/makefile.mk b/salhelper/test/dynamicloader/makefile.mk new file mode 100644 index 000000000000..d786692cb551 --- /dev/null +++ b/salhelper/test/dynamicloader/makefile.mk @@ -0,0 +1,109 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/ + +PRJNAME=salhelper +TARGET=dynloader +TARGET1=samplelib +TARGETTYPE=CUI +LIBTARGET=NO + +NO_BSYMBOLIC= TRUE +ENABLE_EXCEPTIONS=TRUE +BOOTSTRAP_SERVICE=FALSE + +# --- Settings --- + +.INCLUDE : settings.mk + +# --- Files --- + +#RTTI on +.IF "$(OS)" == "WNT" +CFLAGS+= -GR +.ENDIF + +#--------------------------------------------------------------------------- +# Build the test library which is loaded by the +# RealDynamicLoader + +SLOFILES= \ + $(SLO)$/samplelib.obj + +LIB1TARGET=$(SLB)$/$(TARGET1).lib +LIB1OBJFILES= \ + $(SLO)$/samplelib.obj + + +SHL1TARGET= $(TARGET1) + +SHL1STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(TARGET1) +SHL1LIBS= $(SLB)$/$(TARGET1).lib +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEFLIB1NAME =$(TARGET1) +DEF1DEPN= $(MISC)$/$(SHL1TARGET).flt + +# ------------------------------------------------------------------------------ + +APP1NOSAL=TRUE + +APP1TARGET= $(TARGET) + +APP1OBJS= $(OBJ)$/loader.obj + +APP1STDLIBS= \ + $(SALLIB) \ + $(CPPUHELPERLIB) \ + $(CPPULIB) + +.IF "$(OS)" == "WNT" +APP1STDLIBS+= $(LB)$/isalhelper.lib +.ELSE +APP1STDLIBS+= -lsalhelper$(UDK_MAJOR)$(COM) +.ENDIF + +APP1DEF= $(MISC)\$(APP1TARGET).def + +# --- Targets --- + +.INCLUDE : target.mk + + +$(MISC)$/$(SHL1TARGET).flt: makefile.mk + @echo ------------------------------ + @echo Making: $@ + @echo __CT>>$@ + diff --git a/salhelper/test/dynamicloader/samplelib.cxx b/salhelper/test/dynamicloader/samplelib.cxx new file mode 100644 index 000000000000..6f66aa73f324 --- /dev/null +++ b/salhelper/test/dynamicloader/samplelib.cxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#include "samplelib.hxx" +#include <sal/types.h> +/* + + +*/ + +extern "C" +SampleLib_Api* SAL_CALL initSampleLibApi(void) +{ + static SampleLib_Api aApi= {0,0}; + if (!aApi.funcA) + { + aApi.funcA= &funcA; + aApi.funcB= &funcB; + return (&aApi); + } + else + { + return (&aApi); + } + +} + + +sal_Int32 SAL_CALL funcA( sal_Int32 a) +{ + return a; +} + + +double SAL_CALL funcB( double a) +{ + return a; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/test/dynamicloader/samplelib.hxx b/salhelper/test/dynamicloader/samplelib.hxx new file mode 100644 index 000000000000..fbe96c372a84 --- /dev/null +++ b/salhelper/test/dynamicloader/samplelib.hxx @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#ifndef __SAMPLELIB_HXX_ +#define __SAMPLELIB_HXX_ + +#include <sal/types.h> + +struct SampleLib_Api +{ + sal_Int32 (SAL_CALL *funcA)( sal_Int32 ); + double (SAL_CALL *funcB)( double ); +}; + + +typedef SampleLib_Api* (SAL_CALL *InitSampleLib_Api)(void); + +#define SAMPLELIB_INIT_FUNCTION_NAME "initSampleLibApi" + + +sal_Int32 SAL_CALL funcA( sal_Int32 a); +double SAL_CALL funcB( double a); + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/test/rtti/exports.dxp b/salhelper/test/rtti/exports.dxp new file mode 100644 index 000000000000..beafa6a1c40f --- /dev/null +++ b/salhelper/test/rtti/exports.dxp @@ -0,0 +1,6 @@ +?funcA@MyClassA@@UAEXXZ +?funcB@MyClassA@@UAEXXZ +?funcC@MyClassA@@MAEXXZ +?funcA@MyClassB@@UAEXXZ +?funcB@MyClassB@@UAEXXZ +?funcC@MyClassB@@MAEXXZ diff --git a/salhelper/test/rtti/makefile.mk b/salhelper/test/rtti/makefile.mk new file mode 100644 index 000000000000..704454f49851 --- /dev/null +++ b/salhelper/test/rtti/makefile.mk @@ -0,0 +1,107 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME= salhelper +TARGET= rtti +TARGET1=samplelibrtti +LIBTARGET=NO +TARGETTYPE=CUI + + +ENABLE_EXCEPTIONS=TRUE + +USE_DEFFILE= TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +#RTTI on +.IF "$(OS)" == "WNT" +CFLAGS+= -GR +.ENDIF + +SLOFILES= \ + $(SLO)$/samplelibrtti.obj + +LIB1TARGET=$(SLB)$/$(TARGET1).lib +LIB1OBJFILES= \ + $(SLO)$/samplelibrtti.obj + +SHL1TARGET= $(TARGET1) + +SHL1STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + + +SHL1DEPN= +SHL1IMPLIB= i$(TARGET1) +SHL1LIBS= $(SLB)$/$(TARGET1).lib +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1EXPORTFILE= exports.dxp + +DEF1NAME= $(SHL1TARGET) + +.IF "$(OS)$(CPU)"=="SOLARISS" +SHL1VERSIONMAP= sols.map +.ELIF "$(OS)$(CPU)"=="LINUXI" +SHL1VERSIONMAP= lngi.map +.ELIF "$(OS)$(CPU)$(COMNAME)" == "GCCFREEBSDIgcc2" +SHL1VERSIONMAP= gcc2_freebsd_intel.map +.ELIF "$(OS)$(CPU)$(COMNAME)" == "GCCFREEBSDIgcc3" +SHL1VERSIONMAP= gcc3_freebsd_intel.map +.ENDIF + + +# ------------------------------------------------------------------ + +APP1NOSAL=TRUE + +APP1TARGET= $(TARGET) + +APP1OBJS= $(OBJ)$/rttitest.obj + +APP1STDLIBS= \ + $(SALLIB) \ + $(CPPUHELPERLIB) \ + $(CPPULIB) + +.IF "$(OS)" == "WNT" +APP1STDLIBS+= $(LB)$/isamplelibrtti.lib +.ELSE +APP1STDLIBS+= -lsamplelibrtti +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/salhelper/test/rtti/rttitest.cxx b/salhelper/test/rtti/rttitest.cxx new file mode 100644 index 000000000000..c44cb9ead34a --- /dev/null +++ b/salhelper/test/rtti/rttitest.cxx @@ -0,0 +1,21 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#include <stdio.h> +#include <typeinfo> +#include "samplelibrtti.hxx" + +int main( void ) +{ + MyClassB b; + MyClassA* pA= &b; + // test the virtual function + pA->funcA(); + + if( typeid( b) == typeid( pA)) + printf("\nsame types"); + + MyClassB* pB= dynamic_cast<MyClassB* >( pA); + pB->funcA(); + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/test/rtti/samplelibrtti.cxx b/salhelper/test/rtti/samplelibrtti.cxx new file mode 100644 index 000000000000..e3cec911865e --- /dev/null +++ b/salhelper/test/rtti/samplelibrtti.cxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#include "samplelibrtti.hxx" +#include <stdio.h> + +// MyClassA ============================================================= +void MyClassA::funcA() +{ + printf("MyClassA::funcA \n"); +} + +void MyClassA::funcB() +{ +} + +void MyClassA::funcC() +{ +} + +// MyClassB =============================================================== +void MyClassB::funcA() +{ + + printf("MyClassA::funcB \n"); +} + +void MyClassB::funcB() +{ +} + +void MyClassB::funcC() +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/test/rtti/samplelibrtti.hxx b/salhelper/test/rtti/samplelibrtti.hxx new file mode 100644 index 000000000000..dd6a87052c6d --- /dev/null +++ b/salhelper/test/rtti/samplelibrtti.hxx @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#ifndef __SAMPLELIBRTTI_HXX_ +#define __SAMPLELIBRTTI_HXX_ + +class MyClassA +{ +public: + virtual void funcA(); + virtual void funcB(); +protected: + virtual void funcC(); +}; + + +class MyClassB: public MyClassA +{ +public: + virtual void funcA(); + virtual void funcB(); +protected: + virtual void funcC(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/test/rtti/sols.map b/salhelper/test/rtti/sols.map new file mode 100644 index 000000000000..aa778d405666 --- /dev/null +++ b/salhelper/test/rtti/sols.map @@ -0,0 +1,32 @@ +UDK_3_0_0 { + global: +GetVersionInfo; +_fini; +_init; + +__1cIMyClassAFfuncA6M_v_; +__1cIMyClassAFfuncB6M_v_; +__1cIMyClassAFfuncC6M_v_; +__1cIMyClassAG__vtbl_; +__1cIMyClassBFfuncA6M_v_; +__1cIMyClassBFfuncB6M_v_; +__1cIMyClassBFfuncC6M_v_; +__1cIMyClassBG__vtbl_; +__RTTI__1CpknIMyClassA_; +__RTTI__1CpknIMyClassB_; +__RTTI__1CpnIMyClassA_; +__RTTI__1CpnIMyClassB_; +__RTTI__1nIMyClassA_; +__RTTI__1nIMyClassB_; + +local: + *; +}; + + + + + + + + diff --git a/salhelper/version.mk b/salhelper/version.mk new file mode 100644 index 000000000000..76f67022677e --- /dev/null +++ b/salhelper/version.mk @@ -0,0 +1,44 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +# target +SALHELPER_TARGET=salhelper + +# the major +SALHELPER_MAJOR=2 +# the minor +SALHELPER_MINOR=0 +# the micro +SALHELPER_MICRO=0 + +# this is a c++ compatible library +SALHELPER_CPP=1 + +SALHELPER=$(SALHELPER_TARGET)_$(CMPEXT) + +LIBSALHELPER_UNX=lib$(SALHELPER).a.$(SALHELPER_MAJOR) +LIBSALHELPER_WIN=$(SALHELPER_TARGET)$(SALHELPER_MAJOR)$(CMPEXT).dll |