Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes

ACE_DLL_Singleton_T< TYPE, ACE_LOCK > Class Template Reference

Same as ACE_Singleton, except that it registers for destruction with the ACE_Framework_Repository instead of with the ACE_Object_Manager directly. More...

#include <Singleton.h>

Collaboration diagram for ACE_DLL_Singleton_T< TYPE, ACE_LOCK >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

const ACE_TCHARdll_name (void)
const ACE_TCHARname (void)

Static Public Member Functions

static TYPE * instance (void)
 Global access point to the Singleton.
static void close (void)
 Explicitly delete the Singleton instance.
static void close_singleton (void)
static void dump (void)
 Dump the state of the object.

Protected Member Functions

 ACE_DLL_Singleton_T (void)
 Default constructor.
 ~ACE_DLL_Singleton_T (void)
 Destructor.

Static Protected Member Functions

static ACE_DLL_Singleton_T
< TYPE, ACE_LOCK > *& 
instance_i (void)
 Get pointer to the singleton instance.

Protected Attributes

TYPE instance_
 Contained instance.

Static Protected Attributes

static ACE_DLL_Singleton_T
< TYPE, ACE_LOCK > * 
singleton_ = 0
 Pointer to the Singleton instance.

Detailed Description

template<class TYPE, class ACE_LOCK>
class ACE_DLL_Singleton_T< TYPE, ACE_LOCK >

Same as ACE_Singleton, except that it registers for destruction with the ACE_Framework_Repository instead of with the ACE_Object_Manager directly.

This version of ACE_Singleton should be used for singletons that live in a dll loaded either directly by ACE_DLL or indirectly by the ACE Service Configuration framework. Whenever ACE_DLL is ready to actually unload the dll, ACE_DLL_Singleton based dlls associated with that dll will be destroyed first. In fact, any singleton can safely use ACE_DLL_Singleton, even those that don't live in dlls. In that case, the singleton will be destroyed at normal program shutdown.

The only additional requirement is that the contained class export name() and dll_name() methods. See ACE_DLL_Singleton_Adapter_T below for a convenient example of how to satisfy this requirement for the dll_name().

Usage is the same as for ACE_Singleton, but note that if you you declare a friend, the friend class must still be an *ACE_Singleton*<T, [ACE_LOCK]>, not an ACE_Unmanaged_Singleton.

Definition at line 269 of file Singleton.h.


Constructor & Destructor Documentation

template<class TYPE , class ACE_LOCK >
ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::ACE_DLL_Singleton_T ( void   )  [protected]

Default constructor.

Definition at line 33 of file Singleton.inl.

{
}

template<class TYPE , class ACE_LOCK >
ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::~ACE_DLL_Singleton_T ( void   )  [protected]

Destructor.

Definition at line 38 of file Singleton.inl.

{
}


Member Function Documentation

template<class TYPE , class ACE_LOCK >
void ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::close ( void   )  [static]

Explicitly delete the Singleton instance.

Definition at line 505 of file Singleton.cpp.

{
  ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close");

  ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *&singleton =
    ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i ();

  delete singleton;
  singleton = 0;
}

template<class TYPE , class ACE_LOCK >
void ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::close_singleton ( void   )  [static]

Definition at line 517 of file Singleton.cpp.

{
  ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close_singleton");
  ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close ();
}

template<class TYPE , class ACE_LOCK >
const ACE_TCHAR * ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::dll_name ( void   ) 

Definition at line 524 of file Singleton.cpp.

{
  return this->instance ()->dll_name ();
}

template<class TYPE , class ACE_LOCK >
void ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::dump ( void   )  [static]

Dump the state of the object.

Definition at line 423 of file Singleton.cpp.

{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::dump");

#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
  ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("instance_ = %x"),
              ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i ()));
  ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
#endif /* ACE_HAS_DUMP */
}

template<class TYPE , class ACE_LOCK >
TYPE * ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance ( void   )  [static]

Global access point to the Singleton.

Definition at line 454 of file Singleton.cpp.

{
  ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance");

  ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *&singleton =
    ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i ();

  // Perform the Double-Check pattern...
  if (singleton == 0)
    {
      if (ACE_Object_Manager::starting_up () ||
          ACE_Object_Manager::shutting_down ())
        {
          // The program is still starting up, and therefore assumed
          // to be single threaded.  There's no need to double-check.
          // Or, the ACE_Object_Manager instance has been destroyed,
          // so the preallocated lock is not available.  Either way,
          // don't register for destruction with the
          // ACE_Object_Manager:  we'll have to leak this instance.

          ACE_NEW_RETURN (singleton, (ACE_DLL_Singleton_T<TYPE, ACE_LOCK>),
                          0);
        }
      else
        {
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
          // Obtain a lock from the ACE_Object_Manager.  The pointer
          // is static, so we only obtain one per
          // ACE_Unmanaged_Singleton instantiation.
          static ACE_LOCK *lock = 0;
          if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
            // Failed to acquire the lock!
            return 0;

          ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
#endif /* ACE_MT_SAFE */

          if (singleton == 0)
            ACE_NEW_RETURN (singleton,
                            (ACE_DLL_Singleton_T<TYPE, ACE_LOCK>),
                            0);
        }
      //ACE_REGISTER_FRAMEWORK_COMPONENT(ACE_DLL_Singleton<TYPE,ACE_LOCK>, singleton);
      ACE_Framework_Repository::instance ()->register_component
        (new ACE_Framework_Component_T<ACE_DLL_Singleton_T<TYPE, ACE_LOCK> > (singleton));
    }

  return &singleton->instance_;
}

template<class TYPE , class ACE_LOCK >
ACE_DLL_Singleton_T< TYPE, ACE_LOCK > *& ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance_i ( void   )  [static, protected]

Get pointer to the singleton instance.

Definition at line 438 of file Singleton.cpp.

{
  ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i");

#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
  // Pointer to the Singleton instance.  This works around a bug with
  // G++ and it's (mis-)handling of templates and statics...
  static ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *singleton_ = 0;

  return singleton_;
#else
  return ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::singleton_;
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
}

template<class TYPE , class ACE_LOCK >
const ACE_TCHAR * ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::name ( void   ) 

Definition at line 530 of file Singleton.cpp.

{
  return this->instance ()->name ();
}


Member Data Documentation

template<class TYPE, class ACE_LOCK>
TYPE ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance_ [protected]

Contained instance.

Definition at line 297 of file Singleton.h.

template<class TYPE, class ACE_LOCK>
ACE_DLL_Singleton_T< TYPE, ACE_LOCK > * ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::singleton_ = 0 [static, protected]

Pointer to the Singleton instance.

Definition at line 301 of file Singleton.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines