HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_SubSystem.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_SubSystem.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __UT_SUBSYSTEM_H__
14 #define __UT_SUBSYSTEM_H__
15 
16 #include "UT_API.h"
17 
18 #define UT_ENABLE_SUBSYSTEMS
19 
20 #include "UT_NonCopyable.h"
21 #include "UT_UniquePtr.h"
22 
23 #include <SYS/SYS_StaticInit.h>
24 
25 #include <type_traits>
26 
27 class UT_ThreadIOPool;
29 
30 /// All subsystems should derive from this interface. Each subsystem then
31 /// defines how to initialize and shutdown its components.
32 /// All components of a subsystem should be lazy initialized.
34 {
35 public:
36  enum Type
37  {
42  MAX_SUBSYSTEMS
43  };
44 
46 
47  virtual ~UT_ISubSystem() = default;
48 
49  /// The type of the subsystem.
50  virtual Type type() const = 0;
51 
52  template <typename SubSystemT>
53  static bool registerSubSystem(SubSystemT& subsys)
54  {
55  static_assert(
56  std::is_base_of_v<UT_ISubSystem, SubSystemT>
57  && std::is_default_constructible_v<SubSystemT>);
58  return registerSubSystem_(std::addressof(subsys));
59  }
60 
61 protected:
62  UT_ISubSystem() = default;
63 
64  /// Initialize this subsystem
65  virtual void initialize_() = 0;
66  /// Shutdown this subsystem
67  virtual void shutdown_() = 0;
68 private:
69  friend class ut_SubSystemRegistry;
70 
71  static bool registerSubSystem_(UT_ISubSystem* subsys);
72 };
73 
74 #define UT_SUBSYSTEM_CLASS(sub_type) \
75 public: \
76  static constexpr Type subsystem_type = UT_ISubSystem::Type::sub_type; \
77  Type type() const override \
78  { \
79  return subsystem_type; \
80  } \
81  \
82 private: \
83  static bool theIsRegistered;
84 
85 #define UT_SUBSYSTEM_IMPL_INNER(cls) \
86  static SYS_StaticInit<cls> theSubSystem; \
87  static void cls##Init() \
88  { \
89  UT_ISubSystem::registerSubSystem<cls>(*theSubSystem); \
90  } \
91  static void cls##CleanUp() \
92  { \
93  }
94 
95 #define UT_SUBSYSTEM_IMPL(cls) \
96  namespace cls_Namespace \
97  { \
98  UT_SUBSYSTEM_IMPL_INNER(cls) \
99  SYSimplementStaticInit(cls); \
100  }
101 
102 #define UT_SUBSYSTEM_DECLARE(api, cls) \
103  namespace cls_Namespace \
104  { \
105  SYSdeclareStaticInit(api, cls) \
106  }
107 
108 /// The subsystem to initialize and cleanup UT.
109 class UT_API UT_SubSystem final : public UT_ISubSystem
110 {
111  UT_SUBSYSTEM_CLASS(UT_SUBSYSTEM);
112 public:
113  UT_SubSystem();
114  ~UT_SubSystem() override;
115 
116 protected:
117 
118  void initialize_() override;
119  void shutdown_() override;
120 
121 private:
122  friend class ut_SubSystemAccessor;
123 
124  class Impl;
125  UT_UniquePtr<Impl> myImpl;
126 };
127 
128 /// The general purpose thread pool. Any work can be done on this pool. The
129 /// exception to this is licensing work. We must not do any licensing work on
130 /// this thread as license checks will end up blocking the thread causing a hang
131 /// waiting for licensing work to be processed.
133 
134 /// Initialize all subsystems
136 /// Shutdown all subsystems. initialize() must be called prior to this
137 /// function.
139 
140 namespace UT_SubSystemImpl
141 {
142 SYSdeclareStaticObject(UT_API, theRegistry);
143 
145 } // namespace UT_SubSystemImpl
146 
147 template <typename T>
148 T*
150 {
151  static_assert(std::is_base_of_v<UT_ISubSystem, T>);
152  return static_cast<T*>(UT_SubSystemImpl::utGetSubSystem(T::subsystem_type));
153 }
154 
156 
157 #endif // __UT_SUBSYSTEM_H__
The subsystem to initialize and cleanup UT.
Definition: UT_SubSystem.h:109
#define UT_API
Definition: UT_API.h:14
virtual void shutdown_()=0
Shutdown this subsystem.
T * UTgetSubSystem()
Definition: UT_SubSystem.h:149
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UT_API void UTsubSystemShutdown()
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLdouble t
Definition: glad.h:2397
UT_API UT_ThreadIOPool & UThoudiniIOPool()
#define UT_SUBSYSTEM_CLASS(sub_type)
Definition: UT_SubSystem.h:74
static bool registerSubSystem(SubSystemT &subsys)
Definition: UT_SubSystem.h:53
#define UT_SUBSYSTEM_DECLARE(api, cls)
Definition: UT_SubSystem.h:102
SYSdeclareStaticObject(UT_API, theRegistry)
virtual void initialize_()=0
Initialize this subsystem.
UT_API void UTsubSystemInitialize()
Initialize all subsystems.
UT_API UT_ISubSystem * utGetSubSystem(UT_SubSystem::Type t)
type
Definition: core.h:1059