AGX Dynamics  2.35.0.1
TaskManager.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_TASKMANAGER_H
18 #define AGX_TASKMANAGER_H
19 
20 #include <agxIO/ResourceManager.h>
21 #include <agx/Vector.h>
22 #include <agx/HashTable.h>
23 #include <agx/Task.h>
24 #include <agx/PluginMacros.h>
26 #include <exception>
27 #include <stdexcept>
28 
29 #ifdef _MSC_VER
30 # pragma warning(push)
31 # pragma warning( disable : 4275 ) // warning C4275: non dll-interface class
32 # pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
33 #endif
34 
35 namespace agx
36 {
37  class TaskPluginImplementation;
38  class TiXmlElement;
39 
40  class AGXCORE_EXPORT TaskLoadError : public std::runtime_error
41  {
42  public:
43  TaskLoadError(const String& path, const String& implementation, const ParameterTable& parameterList, Device *device, const char* message) : std::runtime_error(message), m_path(path), m_implementation(implementation), m_parameterList(parameterList), m_device(device) {}
44  virtual ~TaskLoadError() throw() {}
45 
46  const String& getPath() const;
47  const String& getImplementation() const;
48  const Device *getDevice() const;
50 
51  private:
52  TaskLoadError& operator = ( const TaskLoadError& ) { agxAbort(); return *this; }
53 
54  String m_path;
55  String m_implementation;
56  const ParameterTable& m_parameterList;
57  Device *m_device;
58  };
59 
60 
62  {
63  public:
64  TaskPlugin(const char* modelPath, Device::Type deviceType);
66 
67  const char *getPath() const;
69 
70  Task* create(Device* device, const Name& implementation);
71  Task* create(Device* device, const ParameterTable& parameterList, const Name& implementation = Name());
72 
74 
75  size_t getNumImplementations() const;
76  private:
78  friend class TaskManager;
79  //PluginHandle m_handle;
80  const char *m_path;
81  Device::Type m_deviceType;
82  size_t m_numImplementations;
83  TaskPluginImplementation *m_implementationList;
84  };
85 
87 
88 
90  {
91  public:
92  TaskPluginImplementation(TaskPlugin *plugin, const char *name = "");
93 
95  const char *getName() const;
96 
97  void registerModel();
98 
99  virtual Task *create(Device *device) = 0;
100  virtual void destroy(Task *task) = 0;
101 
103 
104  private:
105  friend class TaskPlugin;
106  TaskPlugin *m_plugin;
107  const char *m_name;
108  TaskPluginImplementation *m_next;
109  };
110 
111  template <typename T>
113  {
114  public:
115  TaskPluginImplementationT(TaskPlugin *plugin, const char *name = "") : TaskPluginImplementation(plugin, name) {}
117 
118  // TaskPluginImplementation(const String& filePath, const String& name) : TaskPluginImplementation(filePath, name) {}
119 
120  virtual Task *create(Device *device) { return new T(device); }
121  virtual void destroy(Task *task) { agxAssert(dynamic_cast<T *>(task)); static_cast<T *>(task)->~T(); }
122  private:
123  };
124 
125 
127  {
128  public:
130 
131  Task *create(const Path& path, Device *device, const Name& implementation);
132  Task *create(const Path& path, Device *device, const ParameterTable& parameterList, const Name& implementation = Name());
133  Task *create(const Path& path, const Name& implementation, agx::ParameterBindingVector& parameterList, bool allowFormatPromotions, Device *device);
134 
135  // void scan(const String& path);
136  // void rescan();
137 
138  SINGLETON_CLASSNAME_METHOD();
139 
140  protected:
141  virtual ~TaskManager();
142  virtual void shutdown() override;
143 
144  private:
145  friend class TaskPlugin;
146  friend class UnresolvedTask;
147  TaskManager();
148 
149  String getFileSystemPath(const String& resourcePath, const agx::String& extension);
150  String getPluginPath(Path resourcePath);
151 
152  void loadCallback(TiXmlElement *eKernel);
153 
154  #if 0
155  typedef Callback1<const String&> ScanCallback;
156  void scan(const String& path, ScanCallback callback);
157  void load(const String& path);
158  void scanComponents(const String& baseDir);
159  private:
161 
162  TaskPluginTable m_taskPathPluginTable;
163  TaskPluginTable m_taskNamePluginTable;
164  StringVector m_taskDirectories;
165  #endif
166 
167  private:
168  // Load callback communication
169  Device *m_loadDevice;
170  Name m_loadImplementation;
171  const ParameterTable *m_loadParameters;
172  Task *m_loadResult;
173  static ReentrantMutex s_mutex;
174  agx::Vector< PluginHandle > m_pluginHandles;
175  };
176  /* Implementation */
177 }
178 
179 #ifdef _MSC_VER
180 # pragma warning(pop)
181 #endif
182 
183 #endif /* _AGX_TASKMANAGER_H_ */
#define AGXCORE_EXPORT
Templated callback with one argument.
Definition: Callback.h:101
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition: Device.h:58
Type
Explicit list of device types.
Definition: Device.h:76
Inheritance with partial specialization due to bug with ref_ptr containers.
Representation of a name string.
Definition: Name.h:33
Representation of a path, a list of name components.
Definition: Path.h:34
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition: Singleton.h:31
virtual ~TaskLoadError()
Definition: TaskManager.h:44
const String & getImplementation() const
TaskLoadError(const String &path, const String &implementation, const ParameterTable &parameterList, Device *device, const char *message)
Definition: TaskManager.h:43
const String & getPath() const
const ParameterTable & getParameterList()
const Device * getDevice() const
Task * create(const Path &path, Device *device, const Name &implementation)
virtual ~TaskManager()
Task * create(const Path &path, const Name &implementation, agx::ParameterBindingVector &parameterList, bool allowFormatPromotions, Device *device)
virtual void shutdown() override
Implement this method to cleanup your Singleton class.
Task * create(const Path &path, Device *device, const ParameterTable &parameterList, const Name &implementation=Name())
static TaskManager * instance()
TaskPluginImplementationT(TaskPlugin *plugin, const char *name="")
Definition: TaskManager.h:115
virtual void destroy(Task *task)
Definition: TaskManager.h:121
virtual Task * create(Device *device)
Definition: TaskManager.h:120
virtual void destroy(Task *task)=0
virtual Task * create(Device *device)=0
TaskPluginImplementation(TaskPlugin *plugin, const char *name="")
const char * getName() const
const char * getPath() const
Task * create(Device *device, const ParameterTable &parameterList, const Name &implementation=Name())
Task * create(Device *device, const Name &implementation)
size_t getNumImplementations() const
Device::Type getDeviceType() const
TaskPlugin(const char *modelPath, Device::Type deviceType)
void registerModels()
A representation of a generic task.
Definition: Task.h:58
Vector containing 'raw' data.
Definition: agx/Vector.h:246
#define agxAbort()
Definition: debug.h:164
#define agxAssert(expr)
Definition: debug.h:143
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
HashTable< const char *, TaskPlugin * > TaskPluginTable
Definition: TaskManager.h:86
std::recursive_mutex ReentrantMutex
Definition: Object.h:49