summaryrefslogtreecommitdiff
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
commitd5dfd654863461219cb1928ef65e788c69ca17af (patch)
tree3509c40d2a3172e517ff922388c14a19f3b629db
parentc446251474c1bf11253ace6081aa8ffc68d18668 (diff)
tweak the odk example to be equivalent to the standard template
-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 1c5e49a0..80be3361 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