| 1 | /**************************************************************************************** |
| 2 | |
| 3 | Copyright (C) 2015 Autodesk, Inc. |
| 4 | All rights reserved. |
| 5 | |
| 6 | Use of this software is subject to the terms of the Autodesk license agreement |
| 7 | provided at the time of installation or download, or which otherwise accompanies |
| 8 | this software in either electronic or hard copy form. |
| 9 | |
| 10 | ****************************************************************************************/ |
| 11 | |
| 12 | //! \file fbxlistener.h |
| 13 | #ifndef _FBXSDK_CORE_LISTENER_H_ |
| 14 | #define _FBXSDK_CORE_LISTENER_H_ |
| 15 | |
| 16 | #include <fbxsdk/fbxsdk_def.h> |
| 17 | |
| 18 | #include <fbxsdk/core/fbxemitter.h> |
| 19 | #include <fbxsdk/core/fbxeventhandler.h> |
| 20 | #include <fbxsdk/core/base/fbxintrusivelist.h> |
| 21 | |
| 22 | #include <fbxsdk/fbxsdk_nsbegin.h> |
| 23 | |
| 24 | /**FBX SDK listener class. Once an event is emitted by an emitter, a listener should be created to listen to the event. |
| 25 | * The listener could receive a signal and take action to process the event data. |
| 26 | * \note The data will be process by the callback function of FbxListener::Bind(). |
| 27 | * Plug-in could be used as listener, since FbxPlugin is derived from FbxListener. |
| 28 | * To emit event, you could create an emitter and a listener, and then bind them together via event handler. |
| 29 | * To listen to an event which is emitted by an emitter, you should bind current listener to the emitter by calling FbxListener::Bind(). |
| 30 | * Event listener contains a list of event handlers. |
| 31 | * \remarks An object(emitter) can emit a certain type of event, the plug-in(listener) who are listening to that type of event, |
| 32 | * will receive a signal and take action to process the event data. |
| 33 | * \par The whole process of event is: |
| 34 | * \li 1. Create an emitter and a listener, then bind them together via the same event handler. |
| 35 | * \li 2. Emitter can emit an event at certain conditions. The event could be handled by event handler. |
| 36 | * \li 3. Once an event is emitted, the listener to this event will receive a signal. |
| 37 | * \li 4. And then the listener could process the event data according to the types of event, by calling event handler. |
| 38 | * \note The event data is process by the callback function of event handler. |
| 39 | * \see FbxEmitter FbxEventHandler FbxEvent FbxEventBase |
| 40 | */ |
| 41 | class FBXSDK_DLL FbxListener |
| 42 | { |
| 43 | public: |
| 44 | /** |
| 45 | * \name Constructor and Destructor |
| 46 | */ |
| 47 | //@{ |
| 48 | //!Destructor. |
| 49 | ~FbxListener(); |
| 50 | //!Constructor. |
| 51 | FbxListener(){} |
| 52 | //@} |
| 53 | |
| 54 | //////////////////////////////////////////////////////////////////////////////////////// |
| 55 | /** |
| 56 | * \name Bind and unbind methods |
| 57 | */ |
| 58 | //@{ |
| 59 | |
| 60 | /**Bind current listener and the specified emitter together via an automatically created event handler. |
| 61 | * An event handler will be created automatically and added to the handlers list of current listener and the specified emitter. |
| 62 | * After that, the listener can listen to the event which is emitted by the specified emitter. |
| 63 | * \param pEmitter Event emitter to bind. Current listener can listen to the event which is emitted by pEmitter. |
| 64 | * \param pFunc The callback function to process event date. |
| 65 | * \return The automatically created event handler. |
| 66 | */ |
| 67 | template <typename EventType,typename ListenerType> FbxEventHandler* Bind(FbxEmitter& pEmitter, void (ListenerType::*pFunc)(const EventType*)) |
| 68 | { |
| 69 | FbxMemberFuncEventHandler<EventType,ListenerType>* eventHandler = |
| 70 | FbxNew< FbxMemberFuncEventHandler<EventType,ListenerType> >(static_cast<ListenerType*>(this),pFunc); |
| 71 | pEmitter.AddListener(*eventHandler); |
| 72 | mEventHandler.PushBack(*eventHandler); |
| 73 | return eventHandler; |
| 74 | } |
| 75 | |
| 76 | /**Bind current listener and the specified emitter together via an automatically created event handler. |
| 77 | * An event handler will be created automatically and added to the handlers list of current listener and the specified emitter. |
| 78 | * After that, the listener can listen to the event which is emitted by the specified emitter. |
| 79 | * \param pEmitter Event emitter to bind. Current listener can listen to the event which is emitted by pEmitter. |
| 80 | * \param pFunc The callback function to process event date. |
| 81 | * \return The automatically created event handler. |
| 82 | */ |
| 83 | template <typename EventType,typename ListenerType> FbxEventHandler* Bind(FbxEmitter& pEmitter, void (ListenerType::*pFunc)(const EventType*)const) |
| 84 | { |
| 85 | FbxConstMemberFuncEventHandler<EventType,ListenerType>* eventHandler = |
| 86 | FbxNew< FbxConstMemberFuncEventHandler<EventType,ListenerType> >(static_cast<ListenerType*>(this),pFunc); |
| 87 | pEmitter.AddListener(*eventHandler); |
| 88 | mEventHandler.PushBack(*eventHandler); |
| 89 | return eventHandler; |
| 90 | } |
| 91 | |
| 92 | /**Bind current listener and the specified emitter together via an automatically created event handler. |
| 93 | * An event handler will be created automatically and added to the handlers list of current listener and the specified emitter. |
| 94 | * After that, the listener can listen to the event which is emitted by the specified emitter. |
| 95 | * \param pEmitter Event emitter to bind. Current listener can listen to the event which is emitted by pEmitter. |
| 96 | * \param pFunc The callback function to process event date. |
| 97 | * \return The automatically created event handler. |
| 98 | */ |
| 99 | template <typename EventType> FbxEventHandler* Bind(FbxEmitter& pEmitter, void (*pFunc)(const EventType*,FbxListener*)) |
| 100 | { |
| 101 | FbxFuncEventHandler<EventType>* eventHandler = |
| 102 | FbxNew< FbxFuncEventHandler<EventType> >(this, pFunc); |
| 103 | pEmitter.AddListener(*eventHandler); |
| 104 | mEventHandler.PushBack(*eventHandler); |
| 105 | return eventHandler; |
| 106 | } |
| 107 | |
| 108 | /**Unbind an event handler. The specified event handler will be removed from the handlers list of current listener. |
| 109 | * \param aBindId The event handler to unbind. |
| 110 | */ |
| 111 | void Unbind(const FbxEventHandler* aBindId); |
| 112 | //@} |
| 113 | |
| 114 | private: |
| 115 | typedef FbxIntrusiveList<FbxEventHandler, FbxEventHandler::eListener> EventHandlerList; |
| 116 | EventHandlerList mEventHandler; |
| 117 | }; |
| 118 | |
| 119 | #include <fbxsdk/fbxsdk_nsend.h> |
| 120 | |
| 121 | #endif /* _FBXSDK_CORE_LISTENER_H_ */ |
| 122 | |