Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2024 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #ifndef FIREBOLT_RIALTO_CLIENT_I_CLIENT_CONTROLLER_H_
21 : #define FIREBOLT_RIALTO_CLIENT_I_CLIENT_CONTROLLER_H_
22 :
23 : #include <functional>
24 : #include <memory>
25 : #include <stdint.h>
26 :
27 : #include "IClientLogHandler.h"
28 : #include "IControlClient.h"
29 : #include "ISharedMemoryHandle.h"
30 :
31 : namespace firebolt::rialto::client
32 : {
33 : class IClientController;
34 :
35 : /**
36 : * @brief IClientController accessor class definition.
37 : */
38 : class IClientControllerAccessor
39 : {
40 : public:
41 1 : virtual ~IClientControllerAccessor() = default;
42 : IClientControllerAccessor(const IClientControllerAccessor &) = delete;
43 : IClientControllerAccessor &operator=(const IClientControllerAccessor &) = delete;
44 : IClientControllerAccessor(IClientControllerAccessor &&) = delete;
45 : IClientControllerAccessor &operator=(IClientControllerAccessor &&) = delete;
46 :
47 : /**
48 : * @brief Get a IClientControllerAccessor instance.
49 : *
50 : * @retval the accessor instance
51 : */
52 : static IClientControllerAccessor &instance();
53 :
54 : /**
55 : * @brief Get ClientController object.
56 : *
57 : * @retval the reference to ClientController singleton object
58 : */
59 : virtual IClientController &getClientController() const = 0;
60 :
61 : protected:
62 : IClientControllerAccessor() = default;
63 : };
64 :
65 : /**
66 : * @brief The definition of the IClientController interface.
67 : *
68 : * This interface defines the internal API querying shared memory.
69 : */
70 : class IClientController
71 : {
72 : public:
73 188 : IClientController() = default;
74 188 : virtual ~IClientController() = default;
75 :
76 : IClientController(const IClientController &) = delete;
77 : IClientController &operator=(const IClientController &) = delete;
78 : IClientController(IClientController &&) = delete;
79 : IClientController &operator=(IClientController &&) = delete;
80 :
81 : /**
82 : * @brief Callback invoked with the current/new shared memory handle, on (re)map/unmap.
83 : */
84 : using SharedMemoryHandleObserver = std::function<void(const std::shared_ptr<ISharedMemoryHandle> &)>;
85 :
86 : /**
87 : * @brief Subscribe to shared memory handle (re)map/unmap notifications.
88 : *
89 : * The observer is invoked immediately with the current handle, and again whenever it changes.
90 : *
91 : * @param[in] observer : Callback to invoke with the current/new shared memory handle.
92 : *
93 : * @retval token to pass to unsubscribeSharedMemoryHandle().
94 : */
95 : virtual int subscribeSharedMemoryHandle(SharedMemoryHandleObserver observer) = 0;
96 :
97 : /**
98 : * @brief Unsubscribe a previously registered shared memory handle observer.
99 : *
100 : * @param[in] token : Token returned by subscribeSharedMemoryHandle().
101 : */
102 : virtual void unsubscribeSharedMemoryHandle(int token) = 0;
103 :
104 : /**
105 : * @brief Register a client notify when the shared buffer changes.
106 : *
107 : * @param[in] client : Client to register.
108 : * @param[out] appState : Current application state
109 : *
110 : * @retval true on success, false otherwise.
111 : */
112 : virtual bool registerClient(std::weak_ptr<IControlClient> client, ApplicationState &appState) = 0;
113 :
114 : /**
115 : * @brief Unregister a client.
116 : *
117 : * @param[in] client : Client to unregister.
118 : *
119 : * @retval true on success, false otherwise.
120 : */
121 : virtual bool unregisterClient(std::weak_ptr<IControlClient> client) = 0;
122 : };
123 :
124 : }; // namespace firebolt::rialto::client
125 :
126 : #endif // FIREBOLT_RIALTO_CLIENT_I_CLIENT_CONTROLLER_H_
|