AGX Dynamics  2.35.0.1
ComponentManager.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_COMPONENTMANAGER_H
18 #define AGX_COMPONENTMANAGER_H
19 
20 
21 #include <agx/Referenced.h>
22 #include <agx/Vector.h>
23 #include <agx/HashTable.h>
24 #include <agx/Callback.h>
25 #include <agx/Component.h>
26 #include <agx/Device.h>
27 #include <agxIO/FileState.h>
28 #include <agxIO/ResourceManager.h>
29 #include <agx/Logger.h>
31 
33 namespace agx
34 {
35  typedef Component* ( *ComponentConstructor )( Device *device );
36  typedef void ( *ComponentDestructor )( Component * );
37  typedef const char* ( *ComponentNameFunction )();
38 
39  AGX_DECLARE_POINTER_TYPES(AbstractComponentPlugin);
40  AGX_DECLARE_VECTOR_TYPES(AbstractComponentPlugin);
41 
42  class AGXCORE_EXPORT AbstractComponentPlugin
43  {
44  public:
45  AbstractComponentPlugin(const String& path);
46  virtual ~AbstractComponentPlugin();
47 
48  const String& getPath() const;
49 
50  virtual Component *create(Device *device) = 0;
51  virtual void destroy(Component *component) = 0;
52  // void reload();
53 
54 
55  private:
56  #if 0
57  template <typename T>
58  void loadSymbol(T& function, const char *symbol);
59 
60  PluginHandle m_handle;
61 
62  ComponentConstructor m_constructor;
63  ComponentDestructor m_destructor;
64  ComponentNameFunction m_nameFunction;
65  #endif
66 
67  private:
68  String m_path;
69  // String m_name;
70  // bool m_initialized;
71  // ComponentRefVector m_instances;
72  // agxIO::FileState m_fileState;
73  };
74 
75 
76  template <typename T>
77  class ComponentPlugin : public AbstractComponentPlugin
78  {
79  public:
80  ComponentPlugin(const String& path);
81  virtual Component *create(Device *device);
82  virtual void destroy(Component *component);
83 
84  private:
85  };
86 
87  template <typename T>
88  ComponentPlugin<T>::ComponentPlugin(const String& path) : AbstractComponentPlugin(path)
89  {
90  }
91 
92  template <typename T>
93  Component *ComponentPlugin<T>::create(Device *device)
94  {
95  return new T(device);
96  }
97 
98  template <typename T>
99  void ComponentPlugin<T>::destroy(Component * /*component*/)
100  {
101  LOGGER_DEBUG() << "TODO?" << LOGGER_ENDL();
102  }
103 
104  typedef HashTable<String, AbstractComponentPlugin*> ComponentPluginTable;
105 
106  class AGXCORE_EXPORT ComponentManager : public agx::Singleton
107  {
108  public:
109  static ComponentManager *instance();
110 
111  Component *create(const Path& path, const Name& implementation = Name(), Device *device = CpuDevice::instance());
112 
113  // void scan(const String& path);
114  // void rescan();
115 
116  SINGLETON_CLASSNAME_METHOD();
117 
118  private:
119  virtual ~ComponentManager();
120  friend class AbstractComponentPlugin;
121  void registerPlugin(AbstractComponentPlugin *plugin);
122  void unregisterPlugin(AbstractComponentPlugin *plugin);
123  virtual void shutdown() override;
124 
125  agx::String getFileSystemPath(const agx::String& resourcePath, const agx::String& extension);
126  agx::String getPluginFileSystemPath(const agx::String& resourcePath);
127 
128 
129  private:
130  ComponentManager();
131  #if 0
132  typedef Callback1<const String&> ScanCallback;
133  void scan(const String& path, ScanCallback callback);
134  void load(const String& path);
135  void scanComponents(const String& baseDir);
136  #endif
137 
138  private:
139  ComponentPluginTable m_pluginTable;
140  ReentrantMutex m_mutex;
141  };
142 
143 
144 
145  /* Implementation */
146 
147 }
149 
150 
151 #endif /* _AGX_COMPONENTMANAGER_H_ */
#define LOGGER_DEBUG()
Definition: Logger.h:25
#define LOGGER_ENDL()
Definition: Logger.h:27
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXCORE_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition: Singleton.h:31
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
void * PluginHandle
Definition: PluginMacros.h:25
AgXString< std::string > String
Definition: String.h:423
void AGXPHYSICS_EXPORT shutdown()
Shutdown agx.
std::recursive_mutex ReentrantMutex
Definition: Object.h:49