Singleton Listener

Global Listener Object class makes it easy to manage a global listener from C++.

You start by declaring a listener class as a singleton. Once declared, the CLxSingletonListener template wraps your listener class as a static object.

1
2
3
4
5
6
7
 class CListener :
                public CLxImpl_SceneItemListener,
                public CLxSingletonPolymorph
 {
     public:
        ... ''(see [[Singleton Polymorph]] for complete description)''
 };
1
 static CLxSingletonListener<CListener>  listener;

This static object is only a container that is empty to start with. The listener will be created as soon as it’s needed, for example during the constructor for a package instance. This is called when a plug-in item is created, which can be when the listener is first required, and the acquire() method will allocate and register the listener the first time it’s called. Likewise calling release() in the destructor will cause the listener to be removed when the last instance is destroyed.

1
2
3
4
5
6
7
8
 class CInstance :
                public CLxImpl_PackageInstance
 {
     public:
        CInstance ()
        {
                listener.acquire ();
        }
1
2
3
4
5
        ~CInstance ()
        {
                listener.release ();
        }
 };