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 #include <SYS/SYS_TypeTraits.h>
25 
26 #include <type_traits>
27 
28 class UT_ThreadIOPool;
30 
31 /// All subsystems should derive from this interface. Each subsystem then
32 /// defines how to initialize and shutdown its components.
33 /// All components of a subsystem should be lazy initialized.
35 {
36 public:
37  enum Type
38  {
43  MAX_SUBSYSTEMS
44  };
45 
47 
48  virtual ~UT_ISubSystem() = default;
49 
50  /// The type of the subsystem.
51  virtual Type type() const = 0;
52 
53  template <typename SubSystemT>
54  static bool registerSubSystem(SubSystemT& subsys)
55  {
56  static_assert(
57  std::is_base_of_v<UT_ISubSystem, SubSystemT>
58  && std::is_default_constructible_v<SubSystemT>);
59  return registerSubSystem_(SYSaddressof(subsys));
60  }
61 
62 protected:
63  UT_ISubSystem() = default;
64 
65  /// Initialize this subsystem
66  virtual void initialize_() = 0;
67  /// Shutdown this subsystem
68  virtual void shutdown_() = 0;
69 private:
70  friend class ut_SubSystemRegistry;
71 
72  static bool registerSubSystem_(UT_ISubSystem* subsys);
73 };
74 
75 #define UT_SUBSYSTEM_CLASS(sub_type) \
76 public: \
77  static constexpr Type subsystem_type = UT_ISubSystem::Type::sub_type; \
78  Type type() const override \
79  { \
80  return subsystem_type; \
81  } \
82  \
83 private: \
84  static bool theIsRegistered;
85 
86 #define UT_SUBSYSTEM_IMPL_INNER(cls) \
87  static SYS_StaticInit<cls> theSubSystem; \
88  static void cls##Init() \
89  { \
90  UT_ISubSystem::registerSubSystem<cls>(*theSubSystem); \
91  } \
92  static void cls##CleanUp() \
93  { \
94  }
95 
96 #define UT_SUBSYSTEM_IMPL(cls) \
97  namespace cls_Namespace \
98  { \
99  UT_SUBSYSTEM_IMPL_INNER(cls) \
100  SYSimplementStaticInit(cls); \
101  }
102 
103 #define UT_SUBSYSTEM_DECLARE(api, cls) \
104  namespace cls_Namespace \
105  { \
106  SYSdeclareStaticInit(api, cls) \
107  }
108 
109 /// The subsystem to initialize and cleanup UT.
110 class UT_API UT_SubSystem final : public UT_ISubSystem
111 {
112  UT_SUBSYSTEM_CLASS(UT_SUBSYSTEM);
113 public:
114  UT_SubSystem();
115  ~UT_SubSystem() override;
116 
117 protected:
118 
119  void initialize_() override;
120  void shutdown_() override;
121 
122 private:
123  friend class ut_SubSystemAccessor;
124 
125  class Impl;
126  UT_UniquePtr<Impl> myImpl;
127 };
128 
129 /// The general purpose thread pool. Any work can be done on this pool. The
130 /// exception to this is licensing work. We must not do any licensing work on
131 /// this thread as license checks will end up blocking the thread causing a hang
132 /// waiting for licensing work to be processed.
134 
135 /// Initialize all subsystems
137 /// Shutdown all subsystems. initialize() must be called prior to this
138 /// function.
140 
141 namespace UT_SubSystemImpl
142 {
143 SYSdeclareStaticObject(UT_API, theRegistry);
144 
146 } // namespace UT_SubSystemImpl
147 
148 template <typename T>
149 T*
151 {
152  static_assert(std::is_base_of_v<UT_ISubSystem, T>);
153  return static_cast<T*>(UT_SubSystemImpl::utGetSubSystem(T::subsystem_type));
154 }
155 
157 
158 #endif // __UT_SUBSYSTEM_H__
type
Definition: core.h:556
The subsystem to initialize and cleanup UT.
Definition: UT_SubSystem.h:110
#define UT_API
Definition: UT_API.h:14
virtual void shutdown_()=0
Shutdown this subsystem.
T * UTgetSubSystem()
Definition: UT_SubSystem.h:150
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE constexpr T * SYSaddressof(T &val) noexcept
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:75
static bool registerSubSystem(SubSystemT &subsys)
Definition: UT_SubSystem.h:54
#define UT_SUBSYSTEM_DECLARE(api, cls)
Definition: UT_SubSystem.h:103
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)