DataDirector API
DDD_AssetBase.h
Go to the documentation of this file.
1 #ifndef _DDD_AssetBase_h_
2 #define _DDD_AssetBase_h_
3 
4 /*! \file DDD_AssetBase.h
5  \brief The DDD_AssetBase class. Base class for Data Director assets.
6 
7  \par Copyright Information
8 
9  Copyright (c) 2012 The DiSTI Corporation.<br>
10  11301 Corporate Blvd; Suite 100<br>
11  Orlando, Florida 32817<br>
12  USA<br>
13  <br>
14  All rights reserved.<br>
15 
16  This Software contains proprietary trade secrets of DiSTI and may not be
17 reproduced, in whole or part, in any form, or by any means of electronic,
18 mechanical, or otherwise, without the written permission of DiSTI. Said
19 permission may be derived through the purchase of applicable DiSTI product
20 licenses which detail the distribution rights of this content and any
21 Derivative Works based on this or other copyrighted DiSTI Software.
22 
23  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
24 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
25 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
26 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
27 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
28 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
29 
30  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
31 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
32 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
33 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
34 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
35 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBLITY
36 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
37 EXCEED FIVE DOLLARS (US$5.00).
38 
39  The aforementioned terms and restrictions are governed by the laws of the
40 State of Florida and the United States of America.
41 
42 */
43 
44 #include "DDD_Base.h"
45 #include "DDD_AttributeBase.h"
47 #include "dynamic_array.h"
48 #include <string>
49 
50 namespace disti
51 {
52 class DDD_LogFacade;
53 class DDD_AssetBase;
54 class DDD_AssetList;
55 class DDD_ObjectEvent;
56 class DDD_ObjectEventSubscriber;
57 
58 /** \brief A virtual interface class for observers of assets.
59  AssetObservers are able to be notified when an asset deletes and readds its attribute list.
60  */
61 class DDD_EXPORT DDD_AssetObserver
62 {
63 public:
64  /** A callback method that will be called when the asset being observed deletes its attributes
65  * if this observer has registered to be notified on asset change
66  * \param attribute A pointer to the asset that changed
67  */
68  virtual void OnAssetAttributeListDeleted(DDD_AssetBase *asset) = 0;
69 
70  /** A callback method that will be called when the asset being observed added its attributes
71  * if this observer has registered to be notified on asset change
72  * \param attribute A pointer to the asset that changed
73  */
74  virtual void OnAssetAttributeListAdded(DDD_AssetBase *asset) = 0;
75 };
76 
77 /** \brief A virtual interface class for containers of assets.
78  Allows assets to find each other, exchange events and update attributes of each other
79  */
80 class DDD_EXPORT DDD_AssetContainer
81 {
82 public:
83 
84  /** Add a new event subscriber to subscriber list
85  * \param subscriber The event subscriber to add
86  */
87  virtual void AddEventSubscriber(DDD_ObjectEventSubscriber *subscriber) = 0;
88 
89  /** Remove an event subscriber from the subscriber list
90  * \param subscriber The event subscriber to remove
91  */
92  virtual void RemoveEventSubscriber(DDD_ObjectEventSubscriber *subscriber) = 0;
93 
94  /** Post a new event that will be received by all event subscribers
95  * \param event The object event to post
96  */
97  virtual void PostEvent(DDD_ObjectEvent *event) = 0;
98 
99  /** Searches the asset list for an asset with the specified instance name
100  * \param assetName The instance name of the asset to find
101  * \return Returns a pointer to the asset or NULL if not found
102  */
103  virtual DDD_AssetBase* FindAsset(const std::string &assetName) = 0;
104 
105  /** Searches all instantiated assets for the attribute.
106  * \param name The fully qualified name of the attribute to find (e.g. assetName.attribName)
107  * \return Returns a pointer to the attribute or NULL if not found
108  */
109  virtual DDD_AttributeBase *FindAttribute(const std::string &name) = 0;
110 };
111 
112 
113 /** \brief A virtual interface class for all DataDirector assets.
114  */
115 class DDD_EXPORT DDD_AssetBase : public DDD_AttributeContainer, public DDD_Base
116 {
117 protected:
118 
119  DDD_AttributeList _attributes; /**< This list contains all attributes that have been requested of this asset,
120  not necessarily all of the attributes the asset supports. In the DataDirector
121  editor this list is populated by PopulateAttributeList and generally contains
122  all of the supported attributes of the asset. At runtime this list will typically
123  contain the names of attributes that are connected. */
124 
125  bool _refreshAttributeList; /**< Flag indicating whether or not the attribute list needs to be refreshed.
126  This is intended only for use by the DataDirector Producer GUI for updating
127  GUI elements and is not used in the runtime. */
128 
129  DDD_AssetContainer *_container; /**< Container that owns this asset. Allows this asset to access siblings. */
130 
131 public:
132  /** Constructor */
133  DDD_AssetBase(DDD_AssetContainer *container);
134 
135  /** Destructor */
136  virtual ~DDD_AssetBase();
137 
138  /** \return Returns string identifying which version of DataDirector this asset was built against
139  */
140  const char* DataDirectorVersion();
141 
142  /** \return Returns a pointer the attribute with the given name. This will first search the _attributes list
143  * for the object. If an attribute is found there, it will be returned. Otherwise if no matching attribute
144  * is found there, then the asset's internal dictionary will be searched. NULL is returned if no matching
145  * attribute is found.
146  * \param name The name of the attribute to find
147  */
148  DDD_AttributeBase* GetAttribute(const char *attributeName);
149 
150  /** \return Returns a pointer the attribute with the given index. It returns NULL if the index
151  * is out of range
152  * \param name The name of the attribute to find
153  */
154  DDD_AttributeBase* GetAttribute(int index);
155 
156  /** \return Returns a string listing attribute names (from the _attributes list), delimited by a ";" */
157  const char* GetAttributeNames();
158 
159  /** \return A pointer to this asset's container
160  */
161  DDD_AssetContainer *GetContainer() { return _container; }
162 
163  /** \return Returns number of times each of its attributes are referenced in connections
164  */
165  int NumberOfConnections();
166 
167  /** \return Returns the total number of attributes in the _attributes list for this asset
168  * This is not necessarily the total number of attributes supported by the asset, but just
169  * the total number of attributes that have been requested by the data director.
170  */
171  int NumberOfAttributes();
172 
173  /** Adds a dynamic attribute to the asset's _attributes structure. This is called by the framework.
174  */
175  virtual void AddDynamicAttribute(DDD_AttributeBase *attrib);
176 
177  /** Called every time the editor needs an update on the current attributes. Some Assets
178  * can change their Attribute lists dynamically. By default, it simply populates them the first time
179  * and leaves it. Assets with dynamically changing lists of attributes may reallocate their attribute list
180  */
181  virtual void RefreshAttributesList();
182 
183  // For DDD_AssetObserver
184  /** Adds an observer to this asset that will be notified whenever this asset changes
185  * \param observer The observer to add. The observer to add must not already be observing this asset.
186  * \return True if the observer was successfully added, false otherwise
187  * \pre The observer to add must not already be observing this asset.
188  */
189  bool AddAssetObserver(DDD_AssetObserver *observer);
190 
191  /** Removes an observer from the observer list
192  * \param observer The observer to remove.
193  * \return True if the observer was found and removed, false if it wasn't found
194  */
195  bool RemoveAssetObserver(DDD_AssetObserver *observer);
196 
197 protected:
198  /** Notifies all observers of this asset that its attribute list has been deleted */
199  void NotifyAttributeListAdded();
200 
201  /** Notifies all observers of this asset that its attribute list has been added or readded */
202  void NotifyAttributeListDeleted();
203 public:
204 
205  //////////////////// Required overrides ////////////////////
206 
207  /** Describes the Asset (for UI) */
208  virtual const char *Description() = 0;
209 
210  /** Is this asset currently running? */
211  virtual bool Live() = 0;
212 
213  /** Returns asset type (class) name */
214  virtual const char* ClassName() = 0;
215 
216  /** Start asset. Do allocations, initializations that should only happen once. */
217  virtual void Start();
218 
219  /** Stop asset. Do deallocations, cleanups that should only happen once. */
220  virtual void Stop();
221 
222  /** Pause asset. Do cleanup that should happen when the asset is paused. */
223  virtual void Pause();
224 
225  /** Resume asset. Do allocations, initializations that should happen when the asset is resumed */
226  virtual void Resume();
227 
228  /** calculate to pump the asset */
229  virtual void Calculate(double time) = 0;
230 
231  /** Checks for illegal characters in asset name
232  * \param The asset name to check
233  * \return True if the asset name is legal
234  */
235  static bool IsAssetNameLegal(const std::string& assetName);
236 
237 
238  /** Reverts all of the attributes in this list that are marked with the "Revertable" flag
239  */
240  void RevertAttributes();
241 
242  // From DDD_AttributeContainer interface
243  virtual const char* GetName() {return GetInstanceName();}
244 
245  /** Searches this assets for the attribute. Not pure virtual. Child classes can override if
246  * they need to provide their own specialized local scoping of attribute names
247  * \param name The fully qualified name of the attribute to find (e.g. assetName.attribName)
248  * \param userData Data to be used by asset for local scoping of attribute names
249  * \return Returns a pointer to the attribute or NULL if not found
250  */
251  virtual DDD_AttributeBase *FindAttributeLocalScope(const std::string &name,void *userData) { return NULL; }
252 
253  /** Executes a LUA script.
254  * \param script A string containing the script
255  * \param userData User data passed to the script by the invoking asset
256  */
257  virtual void ExecuteLuaScript(const char *script,void *userData);
258 
259  /** Executes a LUA script and returns true if the script set the variable "DDD_Result" to true
260  * \param script A string containing the script
261  * \param userData User data passed to the script by the invoking asset
262  * \return true if the script set the variable "DDD_Result" to true
263  */
264  virtual bool EvaluateLuaScript(const char *script,void *userData);
265 
266 protected:
267 
268  /** Create a LUA parser instance for use by this asset */
269  void CreateLua();
270 
271  /** Destroy the LUA parser instance for this asset */
272  void DestroyLua();
273 
274  void *_luaState; /**< Stores the context for the LUA script engine */
275 
277 
278  AssetObserverList _assetObserverList; /**< The list of observers to notify when this asset changes */
279 
280  /** Poll asset, put all "discovered" assets into _attributList
281  * \pre _attributeList is empty
282  * \post _attributeList will contain the list of attributes discovered from the asset
283  */
284  virtual void PopulateAttributeList() = 0;
285 
286  /** Gets an attribute from the assets internal dictionary and add it to the list of
287  * published attributes for the asset.
288  * \param attributeName The name of the attribute to get
289  * \return A pointer to the attribute or NULL if it doesn't exist.
290  */
291  virtual DDD_AttributeBase* GetDictionaryAttribute(const char *attributeName) = 0;
292 
293  /** Generates unique asset instance name
294  * \param assetList List of assets used to check uniqueness of name
295  * \post _instanceName will have a unique identifier string
296  */
297  virtual void GenerateInstanceName(const DDD_AssetList& assetList);
298 };
299 
300 } // end namespace disti
301 #endif
302 
DDD_AttributeContainer. A virtual interface class for containers of attributes.
Definition: DDD_AttributeBase.h:57
A virtual interface class for subscribers to object events.
Definition: DDD_ObjectEventSubscriber.h:52
virtual DDD_AttributeBase * FindAttributeLocalScope(const std::string &name, void *userData)
Definition: DDD_AssetBase.h:251
A virtual interface class for all DataDirector attribute types.
Definition: DDD_AttributeBase.h:87
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
A virtual interface class for all DataDirector assets.
Definition: DDD_AssetBase.h:115
AssetObserverList _assetObserverList
Definition: DDD_AssetBase.h:278
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
bool _refreshAttributeList
Definition: DDD_AssetBase.h:125
void * _luaState
Definition: DDD_AssetBase.h:274
The DDD_RevertableAttribute class. Container for.
DDD_AttributeList _attributes
Definition: DDD_AssetBase.h:119
DDD_AssetContainer * GetContainer()
Definition: DDD_AssetBase.h:161
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_Base class. Base class for Data Director objects.
Definition: DDD_Base.h:53
DDD_AssetContainer * _container
Definition: DDD_AssetBase.h:129
Definition: AttributeChangedEmitter.h:46
The DDD_ObjectEvent class. A Data Director class for GL Studio object events.
Definition: DDD_ObjectEvent.h:51