VTK  9.7.1
vtkObjectManager.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
19 #ifndef vtkObjectManager_h
20 #define vtkObjectManager_h
21 
22 #include "vtkObject.h"
23 
24 #include "vtkSerializationManagerModule.h" // for export macro
25 
26 #include "vtkDeserializer.h" // for vtkDeserializer
27 #include "vtkInvoker.h" // for vtkInvoker
28 #include "vtkLogger.h" // for vtkLogger::Verbosity enum
29 #include "vtkNew.h" // for vtkNew
30 #include "vtkSerializer.h" // for vtkSerializer
31 #include "vtkSession.h" // for vtkSessionObjectManagerRegistrarFunc
32 #include "vtkSmartPointer.h" // for vtkSmartPointer
33 #include "vtkTypeUInt32Array.h" // for vtkTypeUInt32Array
34 
35 #include <string> // for string
36 #include <vector> // for vector
37 
38 VTK_ABI_NAMESPACE_BEGIN
39 class vtkMarshalContext;
40 class vtkTypeUInt8Array;
41 
42 class VTKSERIALIZATIONMANAGER_EXPORT vtkObjectManager : public vtkObject
43 {
44 public:
45  static vtkObjectManager* New();
46  vtkTypeMacro(vtkObjectManager, vtkObject);
47  void PrintSelf(ostream& os, vtkIndent indent) override;
48 
50 
53  virtual bool Initialize();
54  bool InitializeDefaultHandlers();
56 
60  bool InitializeExtensionModuleHandlers(
61  const std::vector<vtkSessionObjectManagerRegistrarFunc>& registrars);
62  bool InitializeExtensionModuleHandlers(
63  const vtkSessionObjectManagerRegistrarFunc* registrars, std::size_t count);
64 
69  vtkTypeUInt32 RegisterObject(vtkSmartPointer<vtkObjectBase> objectBase);
70 
75  bool UnRegisterObject(vtkTypeUInt32 identifier);
76 
78 
84  bool RegisterState(const std::string& state);
85  bool RegisterState(const nlohmann::json& state);
87 
91  bool UnRegisterState(vtkTypeUInt32 identifier);
92 
98  vtkTypeUInt32 GetId(vtkSmartPointer<vtkObjectBase> objectBase);
99 
105  std::string GetState(vtkTypeUInt32 id);
106 
111  vtkSmartPointer<vtkObjectBase> GetObjectAtId(vtkTypeUInt32 id);
112 
114 
122  std::vector<vtkTypeUInt32> GetAllDependencies(vtkTypeUInt32 identifier);
123  vtkSmartPointer<vtkTypeUInt32Array> GetAllDependenciesAsVTKDataArray(vtkTypeUInt32 identifier);
125 
130  std::vector<std::string> GetBlobHashes(const std::vector<vtkTypeUInt32>& ids);
131 
142  vtkSmartPointer<vtkTypeUInt8Array> GetBlob(const std::string& hash, bool copy = true) const;
143 
148  bool RegisterBlob(const std::string& hash, vtkSmartPointer<vtkTypeUInt8Array> blob);
149 
153  bool UnRegisterBlob(const std::string& hash);
154 
159  void PruneUnusedBlobs();
160 
164  void UpdateObjectsFromStates();
165 
169  void UpdateStatesFromObjects();
170 
180  void UpdateStatesFromObjects(const std::vector<vtkTypeUInt32>& identifiers);
181 
183 
186  bool UpdateObjectFromState(const std::string& state);
187  bool UpdateObjectFromState(const nlohmann::json& state);
189 
193  void UpdateStateFromObject(vtkTypeUInt32 identifier);
194 
201  void Clear();
202 
203  std::string Invoke(
204  vtkTypeUInt32 identifier, const std::string& methodName, const std::string& args);
205  nlohmann::json Invoke(
206  vtkTypeUInt32 identifier, const std::string& methodName, const nlohmann::json& args);
207 
208  std::size_t GetTotalBlobMemoryUsage();
209  std::size_t GetTotalVTKDataObjectMemoryUsage();
210 
215  void Export(const std::string& filename, int indentLevel = -1, char indentChar = ' ');
216 
222  void Import(const std::string& stateFileName, const std::string& blobFileName);
223 
229 
234  std::vector<vtkSmartPointer<vtkObjectBase>> ImportFromBytes(
236 
240  void PruneUnusedStates();
241 
245  void PruneUnusedObjects();
246 
247  static vtkTypeUInt32 ROOT() { return 0; }
248 
249  vtkGetSmartPointerMacro(Serializer, vtkSerializer);
250  vtkGetSmartPointerMacro(Deserializer, vtkDeserializer);
251  vtkGetSmartPointerMacro(Invoker, vtkInvoker);
252 
254 
266  void SetObjectManagerLogVerbosity(vtkLogger::Verbosity verbosity);
267  vtkLogger::Verbosity GetObjectManagerLogVerbosity();
269 
270 protected:
272  ~vtkObjectManager() override;
273 
279 
280  static const char* OWNERSHIP_KEY() { return "manager"; }
281 
282 private:
283  vtkObjectManager(const vtkObjectManager&) = delete;
284  void operator=(const vtkObjectManager&) = delete;
285 
286  std::vector<vtkTypeUInt32> ImportFromJSON(const nlohmann::json& json);
287 
297  static const char* KEPT_ALIVE_KEY() { return "vtk-object-manager-kept-alive"; }
298 
306  bool IsKeptAlive(vtkObjectBase* object);
307 
314  void MarkKeptAlive(vtkObjectBase* object, vtkTypeUInt32 identifier);
315 };
316 VTK_ABI_NAMESPACE_END
317 #endif
Deserialize VTK objects from JSON.
Definition: vtkInvoker.h:30
Deserialize VTK objects from JSON.
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static const char * OWNERSHIP_KEY()
vtkNew< vtkDeserializer > Deserializer
This header file provides the C API for working with standalone/remote visualization applications...
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
vtkSmartPointer< vtkMarshalContext > Context
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkNew< vtkSerializer > Serializer
abstract base class for most VTK objects
Definition: vtkObjectBase.h:68
static vtkTypeUInt32 ROOT()
vtkObjectManager maintains internal instances of vtkSerializer and a vtkDeserializer to serialize and...
Shared context used by vtkSerializer and vtkDeserializer
vtkNew< vtkInvoker > Invoker
int(* vtkSessionObjectManagerRegistrarFunc)(void *ser, void *deser, void *invoker, const char **error)
Definition: vtkSession.h:99
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
Serialize VTK objects to JSON.
Definition: vtkSerializer.h:30