summaryrefslogtreecommitdiff
path: root/odk
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-06-03 08:55:08 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-06-03 08:55:08 +0100
commita74f430a1a5436c35b3528a9510f53973d13e013 (patch)
treec29ce4e2a56466793825aea2f82c57cdf2d58971 /odk
parentd6fb1ee8a92da521e2ce783bdc1b3029ef1c0ea5 (diff)
tweak the odk example to be equivalent to the standard template
Diffstat (limited to 'odk')
-rw-r--r--odk/examples/DevelopersGuide/Components/CppComponent/service1_impl.cxx39
1 files changed, 25 insertions, 14 deletions
diff --git a/odk/examples/DevelopersGuide/Components/CppComponent/service1_impl.cxx b/odk/examples/DevelopersGuide/Components/CppComponent/service1_impl.cxx
index c5cb74f5c3b2..5b973342bdf7 100644
--- a/odk/examples/DevelopersGuide/Components/CppComponent/service1_impl.cxx
+++ b/odk/examples/DevelopersGuide/Components/CppComponent/service1_impl.cxx
@@ -36,6 +36,7 @@
#include <osl/interlck.h>
#include <osl/mutex.hxx>
#include <rtl/uuid.h>
+#include <rtl/instance.hpp>
#include <cppuhelper/factory.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
@@ -172,24 +173,34 @@ Sequence< Type > MyService1Impl::getTypes()
seq[ 2 ] = ::cppu::UnoType< Reference< ::my_module::XSomething > >::get();
return seq;
}
-Sequence< sal_Int8 > MyService1Impl::getImplementationId()
- throw (RuntimeException)
+namespace
{
- static Sequence< sal_Int8 > * s_pId = 0;
- if (! s_pId)
+ // class to create an unique id
+ class UniqueIdInit
{
- // create unique id
- Sequence< sal_Int8 > id( 16 );
- ::rtl_createUuid( (sal_uInt8 *)id.getArray(), 0, sal_True );
- // guard initialization with some mutex
- ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
- if (! s_pId)
+ private:
+ ::com::sun::star::uno::Sequence< sal_Int8 > m_aSeq;
+ public:
+ UniqueIdInitIdInit() : m_aSeq(16)
{
- static Sequence< sal_Int8 > s_id( id );
- s_pId = &s_id;
+ rtl_createUuid( (sal_uInt8*)m_aSeq.getArray(), 0, sal_True );
}
- }
- return *s_pId;
+ const ::com::sun::star::uno::Sequence< sal_Int8 >& getSeq() const { return m_aSeq; }
+ };
+ //A multi-thread safe UniqueIdInitIdInit singleton wrapper
+ class theService1ImplImplementationId
+ : public rtl::Static< UniqueIdInitIdInit,
+ theService1ImplImplementationId >
+ {
+ };
+}
+Sequence< sal_Int8 > MyService1Impl::getImplementationId()
+ throw (RuntimeException)
+{
+ //create a singleton that generates a unique id on
+ //first initialization and returns the same one
+ //on subsequent calls.
+ return theService1ImplImplementationId::get().getSeq();
}
// XSomething implementation