DataDirector API
DDD_DataDirector.h
Go to the documentation of this file.
1 #ifndef _DDD_DataDirector_h_
2 #define _DDD_DataDirector_h_
3 
4 /*! \file DDD_DataDirector.h
5 
6  \par Copyright Information
7 
8  Copyright (c) 2012 The DiSTI Corporation.<br>
9  11301 Corporate Blvd; Suite 100<br>
10  Orlando, Florida 32817<br>
11  USA<br>
12  <br>
13  All rights reserved.<br>
14 
15  This Software contains proprietary trade secrets of DiSTI and may not be
16 reproduced, in whole or part, in any form, or by any means of electronic,
17 mechanical, or otherwise, without the written permission of DiSTI. Said
18 permission may be derived through the purchase of applicable DiSTI product
19 licenses which detail the distribution rights of this content and any
20 Derivative Works based on this or other copyrighted DiSTI Software.
21 
22  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
23 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
24 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
25 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
26 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
27 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
28 
29  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
30 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
31 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
32 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
33 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
34 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBLITY
35 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
36 EXCEED FIVE DOLLARS (US$5.00).
37 
38  The aforementioned terms and restrictions are governed by the laws of the
39 State of Florida and the United States of America.
40 
41 */
42 
43 #include "DDD_AssetBase.h"
44 #include "DDD_Connection.h"
45 #include "DDD_XMLConfigMgr.h"
46 #include "DDD_LogFacade.h"
48 #include <string>
49 
50 #define MAX_PERF_BUFFER_COUNT 16
51 #define MAX_PERF_BUFFER_SIZE 64
52 
53 /** \namespace disti
54  * Contains DataDirector classes and other DiSTI code.
55  */
56 
57 namespace disti
58 {
59 class DDD_DataDirector;
60 
61 typedef DDD_AssetBase* (*AssetCreateCallback)(void*,const std::string& instance, const std::string& className, const DDD_AttributeList& params,DDD_DataDirector *director);
62 
64 {
65 public:
66  AssetCreateCallback _assetCreateCb;
67  void *_cbData;
68  std::string _className;
69 };
70 
71 /** Lsit of AssetCreateCallbacks */
73 
75 
76 /** \brief DDD_DataDirector. Main interface to DataDirector core that encapsulates all Assets, Connections and core logic.
77  */
78 class DDD_EXPORT DDD_DataDirector : public XMLConfigTarget, public DDD_AssetObserver, public DDD_AssetContainer
79 {
80  // callbacks from DDD_AssetObserver
81  virtual void OnAssetAttributeListDeleted(DDD_AssetBase *asset);
82  virtual void OnAssetAttributeListAdded(DDD_AssetBase *asset);
83 
84 public:
85  /** Constructor */
87 
88  /** Destructor */
90 
91  /** Load the Data Director state from an XML configuration file
92  * \param filename The name of the configuration file to load
93  * \return Returns True if the configuration was successfully loaded
94  */
95  bool LoadXML(const std::string &filename);
96 
97  /** Save the Data Director state to an XML configuration file
98  * \param filename The name of the configuration file to save to
99  * \return Returns True if the configuration was successfully saved
100  */
101  bool SaveXML(const std::string &filename);
102 
103  // XMLConfigTarget Overrides //////////////////////////////
104  /** Instantiate an asset and add it to the asset list
105  * \param instanceName The intance name of the new asset
106  * \param className The class name of the new asset
107  * \param libName The library file name of the new asset
108  * \param params A list of initialization parameters for the asset
109  * \return A pointer to the newly added asset or NULL on failure
110  */
111  DDD_AssetBase* AddAsset(const std::string &instanceName, const std::string &className, const std::string &libName, const DDD_AttributeList& params);
112 
113  /** Add a Connection to the connection list
114  * \param connection A connection to add to the connection list
115  */
116  virtual void AddConnection(DDD_Connection *connection);
117 
118  /** \return Returns the connections list */
119  virtual DDD_ConnectionList &GetConnectionList();
120 
121  /** Remove asset from asset list and also check each connection and invalidates ones that referenced that Asset
122  * \param asset A pointer to the asset to remove
123  */
124  void RemoveAsset(DDD_AssetBase* asset);
125 
126  /** Changes asset instance name and also checks connections to make sure any connections that
127  * referenced the asset are updated
128  * \param oldAssetName The old instance name of the asset
129  * \param newAssetName The new instance name of the asset
130  * \return true If an asset with the old name was found and if the new name is legal
131  */
132  bool ChangeAssetInstanceName(const std::string& oldAssetName, const std::string& newAssetName);
133 
134  /** Removes a connection from the Director
135  * \param connection The connection to remove
136  */
137  void RemoveConnection(DDD_Connection *connection);
138 
139  /** Registers an asset creation callback for "special" assets (i.e.- RSOs)
140  * This callback will be called whenever a new asset is instantiated by the director
141  * \param assetCreatorCb Function pointer to the callback
142  * \param data Data to pass to callback
143  */
144  void RegisterAssetCreateCallback(std::string className, AssetCreateCallback assetCreatorCb, void *data);
145 
146  /** Runs the Data Director engine--iterates the assets and pumps connections */
147  void Process();
148 
149  /** Runs the Data Director engine--iterates the assets and pumps connections
150  * \param time Elapsed time since last call (for when calling process inside of calculate)
151  */
152  void Process(double time);
153 
154  /** Clears all Assets and Connections- revert to empty configuration */
155  void ClearAll();
156 
157  /** Starts all assets */
158  void StartAllAssets();
159 
160  /** stops all assets */
161  void StopAllAssets();
162 
163  /** Resumes all assets */
164  void ResumeAllAssets();
165 
166  /** Pauses all assets */
167  void PauseAllAssets();
168 
169  /** \return Returns true if there are no assets or connections in the director
170  */
171  bool Empty();
172 
173  /** \return Returns version string for compatibility checking of plugins
174  */
175  static const char* Version();
176 
177  /** Moves a connection "UP" in the list, which means it gets moved further towards
178  * the end of the list.
179  * \param connection The connection to reorder
180  * \return True if if the connection was moved, false otherwise
181  */
182  bool MoveConnectionUp(DDD_Connection* connection);
183 
184  /** Moves a connection "DOWN" in the list, which means it gets moved towards the
185  * beginning of the list.
186  * \param connection The connection to reorder
187  * \return True if if the connection was moved, false otherwise
188  */
189  bool MoveConnectionDown(DDD_Connection* connection);
190 
191  /** Moves a asset "UP" in the list, which means it gets moved further towards
192  * the end of the list.
193  * \param asset The asset to reorder
194  * \return True if if the asset was moved, false otherwise
195  */
196  bool MoveAssetUp(DDD_AssetBase* asset);
197 
198  /** Moves a asset "DOWN" in the list, which means it gets moved towards the
199  * beginning of the list.
200  * \param asset The asset to reorder
201  * \return True if if the asset was moved, false otherwise
202  */
203  bool MoveAssetDown(DDD_AssetBase* asset);
204 
205  /** This method will force every connection to be added to pending connections to be
206  * processed regardless whether they had any changed attributes.
207  */
208  void ForceProcessConnections();
209 
210  /** \return Returns the asset list */
211  virtual DDD_AssetList &GetAssetList();
212 
213  /** Add a new event subscriber to subscriber list
214  * \param subscriber The event subscriber to add
215  */
216  void AddEventSubscriber(DDD_ObjectEventSubscriber *subscriber);
217 
218  /** Remove an event subscriber from the subscriber list
219  * \param subscriber The event subscriber to remove
220  */
221  void RemoveEventSubscriber(DDD_ObjectEventSubscriber *subscriber);
222 
223  /** Post a new event that will be received by all event subscribers
224  * \param event The object event to post
225  */
226  void PostEvent(DDD_ObjectEvent *event);
227 
228  /** Searches the asset list for an asset with the specified instance name
229  * \param assetName The instance name of the asset to find
230  * \return Returns a pointer to the asset or NULL if not found
231  */
232  DDD_AssetBase* FindAsset(const std::string &assetName);
233 
234  /** Searches all instantiated assets for the attribute
235  * \param name The fully qualified name of the attribute to find (e.g. assetName.attribName)
236  * \return Returns a pointer to the attribute or NULL if not found
237  */
238  DDD_AttributeBase *FindAttribute(const std::string &name);
239 
240  // End of From DDD_AssetContainer
241 
242  static void InitializeGlsLibrary();
243 
244 private:
245  /** called whenever connection orders change */
246  void UpdateConnectionNumbers();
247 
248 private:
249  DDD_AssetList _assets; /**< The list of assets for this DataDirector instance */
250  DDD_ConnectionList _connections; /**< The list of assets for this DataDirector instance */
251  AssetCreateCallbackList _assetCreatorCbs; /**< Callback function to be called when an asset is created */
252 // CallbackDataList _cbData; /**< Data to pass to callback function when called */
253  DDD_PerformanceMonitor *_processProfiler; /**< Profiler for tracking "Process" performance */
254  DDD_ObjectEventSubscriberList _eventSubscribers; /**< List of objects that have subscribed to ObjectEvents */
255  bool _paused; /**< True if the Data Director is paused */
256 
257  static bool _libraryInitialized;
258 };
259 
260 } // end namespace disti
261 #endif
262 
A virtual interface class for subscribers to object events.
Definition: DDD_ObjectEventSubscriber.h:52
A virtual interface class for all DataDirector attribute types.
Definition: DDD_AttributeBase.h:87
The DDD_Connection class. Base class for connections between assets.
A virtual interface class for all DataDirector assets.
Definition: DDD_AssetBase.h:115
The DDD_AttributeList class. Maintains a list of Data Director attributes.
Definition: DDD_AttributeList.h:52
The DDD_AssetList class. Maintains a list of Data Director assets.
Definition: DDD_AssetList.h:51
A virtual interface class for observers of assets. AssetObservers are able to be notified when an ass...
Definition: DDD_AssetBase.h:61
DynamicPtrArray< AssetCallbackContainer * > AssetCreateCallbackList
Definition: DDD_DataDirector.h:72
DDD_DataDirector. Main interface to DataDirector core that encapsulates all Assets, Connections and core logic.
Definition: DDD_DataDirector.h:78
The DDD_AssetBase class. Base class for Data Director assets.
A virtual interface class for containers of assets. Allows assets to find each other, exchange events and update attributes of each other.
Definition: DDD_AssetBase.h:80
The DDD_Connection class. Base class for connections between assets.
Definition: DDD_Connection.h:54
Definition: DDD_DataDirector.h:63
Performance monitor class; profiles an individual task.
Definition: DDD_PerformanceMonitor.h:55
Abstract base class for any object that uses DDD_XMLConfigMgr.
Definition: DDD_XMLConfigMgr.h:74
Definition: AttributeChangedEmitter.h:46
The DDD_ObjectEvent class. A Data Director class for GL Studio object events.
Definition: DDD_ObjectEvent.h:51