AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
TaskManager.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGX_TASKMANAGER_H
18#define AGX_TASKMANAGER_H
19
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
35namespace 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
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;
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:33
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 ParameterTable & getParameterList()
const String & getPath() const
const Device * getDevice() const
TaskLoadError(const String &path, const String &implementation, const ParameterTable &parameterList, Device *device, const char *message)
Definition TaskManager.h:43
const String & getImplementation() const
Task * create(const Path &path, const Name &implementation, agx::ParameterBindingVector &parameterList, bool allowFormatPromotions, Device *device)
virtual ~TaskManager()
static TaskManager * instance()
virtual void shutdown() override
Implement this method to cleanup your Singleton class.
Task * create(const Path &path, Device *device, const Name &implementation)
Task * create(const Path &path, Device *device, const ParameterTable &parameterList, const Name &implementation=Name())
virtual Task * create(Device *device)
TaskPluginImplementationT(TaskPlugin *plugin, const char *name="")
virtual void destroy(Task *task)
const char * getName() const
virtual void destroy(Task *task)=0
virtual Task * create(Device *device)=0
TaskPluginImplementation(TaskPlugin *plugin, const char *name="")
size_t getNumImplementations() const
const char * getPath() const
Task * create(Device *device, const ParameterTable &parameterList, const Name &implementation=Name())
Device::Type getDeviceType() const
TaskPlugin(const char *modelPath, Device::Type deviceType)
Task * create(Device *device, const Name &implementation)
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:48
STL namespace.