Ocean
Loading...
Searching...
No Matches
OceanManager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_BASE_OCEAN_MANAGER_H
9#define META_OCEAN_BASE_OCEAN_MANAGER_H
10
11#include "ocean/base/Base.h"
12#include "ocean/base/Lock.h"
13
14namespace Ocean
15{
16
17/**
18 * This class implements the basic manager for the Ocean framework.
19 * The manager is implemented as singleton while it is not derived from the Singleton class of the Ocean framework.<br>
20 * This manager allows to explicitly release all resources that are connected with objects derived by the Singleton class.<br>
21 * However, normally there is no need to release the resources explicitly as all resources will be released automatically during the call of std::atexit.<br>
22 * Therefore, use the shutdown function of this manager only if there is the explicit need for releasing all existing Ocean framework resources at a specific moment in your application.<br>
23 * @see Singleton
24 * @ingroup base
25 */
26class OCEAN_BASE_EXPORT OceanManager
27{
28 public:
29
30 /**
31 * Definition of a function pointer that releases a singleton object.
32 */
33 typedef void (*SingletonDestroyFunction)();
34
35 private:
36
37 /**
38 * Definition of a vector holding functions to release singleton objects.
39 */
40 typedef std::vector<SingletonDestroyFunction> SingletonDestroyFunctions;
41
42 public:
43
44 /**
45 * Returns a reference to the OceanManager object.
46 * @return Reference to the manager
47 */
48 static OceanManager& get();
49
50 /**
51 * Registers a new singleton object.
52 * Every registered singleton object is released by this manager if:<br>
53 * a) the std::atexit function invokes the default shutdown of this manager<br>
54 * b) the shutdown() function of this manager object (and all other manager objects in the remaining standalone dynamic libraries) are invoked explicitly<br>
55 * @param singletonDestroyFunction The function pointer that can be invoked to release the singleton, must be valid
56 */
57 void registerSingleton(const SingletonDestroyFunction& singletonDestroyFunction);
58
59 /**
60 * Explicit shutdown of all Ocean framework resources that are handled by the Singleton class implementation.
61 * Beware: Do not call this shutdown function unless all Singletons must be released at a specific moment in the application.
62 */
63 void shutdown();
64
65 private:
66
67 /**
68 * Creates a new manager object.
69 * This constructor is protected as it must not be created by a constructor directly.
70 */
72
73 /**
74 * Disabled copy constructor.
75 * @param oceanManager The manager object that would be copied
76 */
77 OceanManager(const OceanManager& oceanManager) = delete;
78
79 /**
80 * Destructs this manager object.
81 */
83
84 /**
85 * Internal callback function for a std::atexit call.
86 */
87 static void internalRelease();
88
89 /**
90 * Disabled assign operator.
91 * @param oceanManager The manager object that would be copied
92 */
93 OceanManager& operator=(const OceanManager& oceanManager) = delete;
94
95 private:
96
97 /// Lock of this manager.
99
100 /// The pointers to release functions for all registered singletons.
102};
103
104}
105
106#endif // META_OCEAN_BASE_OCEAN_MANAGER_H
This class implements a recursive lock object.
Definition Lock.h:31
This class implements the basic manager for the Ocean framework.
Definition OceanManager.h:27
void registerSingleton(const SingletonDestroyFunction &singletonDestroyFunction)
Registers a new singleton object.
std::vector< SingletonDestroyFunction > SingletonDestroyFunctions
Definition of a vector holding functions to release singleton objects.
Definition OceanManager.h:40
OceanManager(const OceanManager &oceanManager)=delete
Disabled copy constructor.
OceanManager()
Creates a new manager object.
SingletonDestroyFunctions singletonDestroyFunctions_
The pointers to release functions for all registered singletons.
Definition OceanManager.h:101
static OceanManager & get()
Returns a reference to the OceanManager object.
~OceanManager()
Destructs this manager object.
static void internalRelease()
Internal callback function for a std::atexit call.
Lock lock_
Lock of this manager.
Definition OceanManager.h:98
OceanManager & operator=(const OceanManager &oceanManager)=delete
Disabled assign operator.
void shutdown()
Explicit shutdown of all Ocean framework resources that are handled by the Singleton class implementa...
The namespace covering the entire Ocean framework.
Definition Accessor.h:15