Difference between revisions of "Singleton Listener"

From The Foundry MODO SDK wiki
Jump to: navigation, search
(Created page with "Global [listener]s, that is objects that watch for global events rather than events on a specific object, are generally created once and exist as long as they are needed. The ...")
 
Line 1: Line 1:
Global [listener]s, that is objects that watch for global events rather than events on a specific object, are generally created once and exist as long as they are needed. The [CLxSingletonListener | Listener_%28lx-listener.hpp%29] class makes it easy to manage a global listener from C++.
+
[[Global Listener Object | Global listeners]], that is objects that watch for global events rather than events on a specific object, are generally created once and exist as long as they are needed. The [[Listener_%28lx-listener.hpp%29 | CLxSingletonListener]] class makes it easy to manage a global listener from C++.
  
You start by creating a singleton listener class. The full text of the class can be found with the example of how to uses. Once declared, the CLxSingletonListener template can create your listener as a static object.
+
You start by declaring a listener class as a singleton. Once declared, the CLxSingletonListener template wraps your listener class as a static object.
  
 
  class CListener :
 
  class CListener :
Line 8: Line 8:
 
  {
 
  {
 
     public:
 
     public:
  ... (see [Singleton Polymorph] for the full text)
+
  ... ''(see [[Singleton Polymorph]] for the full text)''
 
  };
 
  };
 
   
 
   
 
  static CLxSingletonListener<CListener> listener;
 
  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 called release() in the destructor will cause the listener to be removed when the last instance is destroyed.
+
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.
  
 
  class CInstance :
 
  class CInstance :

Revision as of 02:06, 28 February 2014

Global listeners, that is objects that watch for global events rather than events on a specific object, are generally created once and exist as long as they are needed. The CLxSingletonListener 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.

class CListener :
		public CLxImpl_SceneItemListener,
		public CLxSingletonPolymorph
{
    public:
	... (see Singleton Polymorph for the full text)
};

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.

class CInstance :

public CLxImpl_PackageInstance

{
    public:
	CInstance ()
	{
		listener.acquire ();
	}

	~CInstance ()
	{
		listener.release ();
	}
};