This is the foundation class of the signal and slots. This class is a marker for a collection of slots, allowing them to connect to any internal or external CYISignal. This class serves as a life-tracker of the object, and as a connection manager for the CYISignal connected to it. If the CYISignalHandler goes out of scope, or is deleted, all of its connection will be automatically disconnected in a thread-safe manner.
If a CYISignalHandler (or a class that derives from CYISignalHandler) is copied, all existing signal connections are copied as well. If this is undesirable, call DisconnectFromAllSignals() on the copy.
Here is an example of how to use the CYISignal and CYISignalHandler to mark a class:
When instantiating a CYISignalHandler, it will automatically bind itself to the thread that created it in the first place. Every time we connect a CYISignal to this CYISignalHanlder using the default EYIConnectionType::Auto connection type, the signal will compare its calling thread against the CYISignalHandler thread. If they are different, then the signal will be queued onto the thread's CYIEventDispatcher if the CYIThread and the CYIEventDispatcher is running.
Here is an code example:
#include <signal/YiSignalHandler.h>
Public Member Functions | |
CYISignalHandler () | |
CYISignalHandler (const CYISignalHandler &signalHandler) | |
virtual | ~CYISignalHandler () |
CYISignalHandler & | operator= (const CYISignalHandler &signalHandler) |
void | MoveToThread (CYIThread *pThread) |
This function allows the user to override the default thread affinity to any CYIThread that may or may not be running. More... | |
CYIThreadHandle | GetThreadAffinity () const |
void | SetThreadAffinity (const CYIThreadHandle &threadAffinity) |
virtual bool | IsConnected () const |
virtual bool | IsConnected (const CYISignalBase &signal) const |
void | Disconnect (CYISignalBase &signal) |
void | DisconnectFromAllSignals () |
![]() | |
Listener () | |
virtual | ~Listener () |
virtual void | OnThreadStarted (CYIThread *) |
virtual void | OnThreadTerminated (CYIThread *) |
virtual void | OnThreadFinished (CYIThread *) |
Friends | |
class | CYISignalBase |
CYISignalHandler::CYISignalHandler | ( | ) |
CYISignalHandler::CYISignalHandler | ( | const CYISignalHandler & | signalHandler | ) |
|
virtual |
void CYISignalHandler::Disconnect | ( | CYISignalBase & | signal | ) |
void CYISignalHandler::DisconnectFromAllSignals | ( | ) |
Disconnects every connection from every CYISignal.
CYIThreadHandle CYISignalHandler::GetThreadAffinity | ( | ) | const |
Returns the thread affinity of the object.
Usually, it will return the CYIThreadHandle of the thread that instantiated our CYISignalHandler, but if the CYISignalHandler has been moved to a different thread using MoveToThread(CYIThread *pThread) and if the CYIThread is running, it will return the CYIThreadHandle of that CYIThread instead. If the thread is not running or stopped running, it will default back to the thread that instantiated it.
|
virtual |
Checks if at least one connection has been established with any CYISignal.
Reimplemented in CYISignalBase.
|
virtual |
Checks if this CYISignalHandler is connected to a specific CYISignal.
Example:
Reimplemented in CYISignalBase.
void CYISignalHandler::MoveToThread | ( | CYIThread * | pThread | ) |
This function allows the user to override the default thread affinity to any CYIThread that may or may not be running.
Here is an example:
CYISignalHandler& CYISignalHandler::operator= | ( | const CYISignalHandler & | signalHandler | ) |
void CYISignalHandler::SetThreadAffinity | ( | const CYIThreadHandle & | threadAffinity | ) |
Sets the thread affinity to threadAffinity.
This function is very similar to MoveToThread(CYIThread *pThread), but it will overwrite the creation thread affinity instead. If a CYIThread has previously been assigned using MoveToThread(CYIThread *pThread), it will be automatically be disassociated from this CYIThread. The CYIThreadHandle can be created from any thread from any thread API. It does not require to be from a CYIThread.
|
friend |