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 fbxemitter.h |
13 | #ifndef _FBXSDK_CORE_EMITTER_H_ |
14 | #define _FBXSDK_CORE_EMITTER_H_ |
15 | |
16 | #include <fbxsdk/fbxsdk_def.h> |
17 | |
18 | #include <fbxsdk/core/base/fbxintrusivelist.h> |
19 | #include <fbxsdk/core/fbxeventhandler.h> |
20 | |
21 | #include <fbxsdk/fbxsdk_nsbegin.h> |
22 | |
23 | class FbxListener; |
24 | |
25 | /** Base class to emit event with the specified event type. |
26 | * The event type could be a specific class which derived from FbxEvent. Please read FbxEmitter::Emit() for more details. |
27 | * Event emitter contains a list of event handlers. |
28 | * FBX object could be used as emitter, since FbxObject is derived from FbxEmitter. |
29 | * Before using emitter to emit an event, one or more event handlers must be added to the handlers list of current emitter. |
30 | * In other words, it's "bind event handlers to emitter". |
31 | * There are two ways to bind event handlers to emitter. |
32 | * \li 1. If you already got an event handler and would like to bind it to current emitter, please call FbxEmitter::AddListener(). |
33 | * \li 2. Or you can create an event listener first and then call FbxListener::Bind(). |
34 | * It will create an event handler automatically and bind the handler to the specified emitter. |
35 | * It's similar to unbind or remove an even handler. For more details, |
36 | * \see FbxEmitter::RemoveListener() |
37 | * \see FbxListener::Unbind() |
38 | * \remarks An object(emitter) can emit a certain type of event, the plug-in(listener) who are listening to that type of event, |
39 | * will receive a signal and take action to process the event data. |
40 | * \par The whole process of event is: |
41 | * \li 1. Create an emitter and a listener, then bind them together via the same event handler. |
42 | * \li 2. Emitter can emit an event at certain conditions. The event could be handled by event handler. |
43 | * \li 3. Once an event is emitted, the listener to this event will receive a signal. |
44 | * \li 4. And then the listener could process the event data according to the types of event, by calling event handler. |
45 | * \note The event data is process by the callback function of event handler. |
46 | * \nosubgrouping |
47 | * \see FbxListener FbxEventHandler FbxEvent FbxEventBase |
48 | */ |
49 | class FBXSDK_DLL FbxEmitter |
50 | { |
51 | public: |
52 | /** Add the specified event handler to current emitter list. |
53 | * \param pHandler The event handler will be added to the handlers list of current emitter. */ |
54 | void AddListener(FbxEventHandler& pHandler); |
55 | |
56 | /** Remove the specified event handler from current emitter list. |
57 | * \param pHandler The event handler will be removed from the handlers list of current emitter. */ |
58 | void RemoveListener(FbxEventHandler& pHandler); |
59 | |
60 | /** Emit an event with the specified the event type. One the event is emitted, the listener to this event will receive a signal. |
61 | * \param pEvent Specify the event type to emit. Could be a specific class which derived from FbxEvent, such as FbxObjectPropertyChanged. |
62 | * \see FbxEventBase FbxObjectPropertyChanged FbxEventReferencedDocument FbxEventPostExport |
63 | * \see FbxEventPostImport FbxEventPreExport FbxEventPreImport FbxEventPopulateSystemLibrary */ |
64 | template <typename EventType> void Emit(const EventType& pEvent) const |
65 | { |
66 | if( !mData ) return; |
67 | EventHandlerList::iterator itBegin = mData->mEventHandlerList.Begin(); |
68 | EventHandlerList::iterator itEnd = mData->mEventHandlerList.End(); |
69 | for( EventHandlerList::iterator it = itBegin; it != itEnd; ++it ) |
70 | { |
71 | if ((*it).GetHandlerEventType() == pEvent.GetTypeId()) |
72 | { |
73 | (*it).FunctionCall(pEvent); |
74 | } |
75 | } |
76 | } |
77 | |
78 | /***************************************************************************************************************************** |
79 | ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! ** |
80 | *****************************************************************************************************************************/ |
81 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
82 | FbxEmitter(); |
83 | ~FbxEmitter(); |
84 | |
85 | protected: |
86 | typedef FbxIntrusiveList<FbxEventHandler, FbxEventHandler::eEmitter> EventHandlerList; |
87 | struct EventData { EventHandlerList mEventHandlerList; }; |
88 | EventData* mData; |
89 | #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/ |
90 | }; |
91 | |
92 | #include <fbxsdk/fbxsdk_nsend.h> |
93 | |
94 | #endif /* _FBXSDK_CORE_EMITTER_H_ */ |
95 | |