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 2023 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_CLIENT_CONTROLLER_H_
21 : #define FIREBOLT_RIALTO_CLIENT_CLIENT_CONTROLLER_H_
22 :
23 : #include <list>
24 : #include <memory>
25 : #include <mutex>
26 : #include <string>
27 :
28 : #include "IClientController.h"
29 : #include "IControlClient.h"
30 : #include "IControlIpc.h"
31 :
32 : namespace firebolt::rialto::client
33 : {
34 : class ClientControllerAccessor : public IClientControllerAccessor
35 : {
36 : public:
37 1 : ~ClientControllerAccessor() override = default;
38 : IClientController &getClientController() const override;
39 : };
40 :
41 : class ClientController : public IClientController, public IControlClient
42 : {
43 : public:
44 : explicit ClientController(const std::shared_ptr<IControlIpcFactory> &ControlIpcFactory);
45 : ~ClientController() override;
46 :
47 : std::shared_ptr<ISharedMemoryHandle> getSharedMemoryHandle() override;
48 : bool registerClient(std::weak_ptr<IControlClient> client, ApplicationState &appState) override;
49 : bool unregisterClient(std::weak_ptr<IControlClient> client) override;
50 :
51 : private:
52 : void notifyApplicationState(ApplicationState state) override;
53 :
54 : /**
55 : * @brief Initalised the shared memory for media playback.
56 : *
57 : * @retval true on success, false otherwise.
58 : */
59 : bool initSharedMemory();
60 :
61 : /**
62 : * @brief Terminates the shared memory.
63 : */
64 : void termSharedMemory();
65 :
66 : /**
67 : * @brief Coverts a ApplicationState to string.
68 : *
69 : * @param[in] state : The application state.
70 : *
71 : * @retval the application state string, or "" on error.
72 : */
73 : std::string stateToString(ApplicationState state);
74 :
75 : /**
76 : * @brief Forwards new ApplicationState to subscribed clients
77 : *
78 : * @param[in] state : The new application state.
79 : *
80 : */
81 : void changeStateAndNotifyClients(ApplicationState state);
82 :
83 : private:
84 : /**
85 : * @brief Mutex protection for class attributes.
86 : */
87 : std::mutex m_mutex;
88 :
89 : /**
90 : * @brief The current application state
91 : */
92 : ApplicationState m_currentState;
93 :
94 : /**
95 : * @brief Flag indicating if registerRequest has to be sent to Rialto Server
96 : */
97 : bool m_registrationRequired;
98 :
99 : /**
100 : * @brief The shared memory buffer handle.
101 : */
102 : std::shared_ptr<ISharedMemoryHandle> m_shmHandle;
103 :
104 : /**
105 : * @brief The rialto control ipc factory.
106 : */
107 : std::shared_ptr<IControlIpc> m_controlIpc;
108 :
109 : /**
110 : * @brief List of clients to notify.
111 : */
112 : std::list<std::weak_ptr<IControlClient>> m_clients;
113 : };
114 : } // namespace firebolt::rialto::client
115 :
116 : #endif // FIREBOLT_RIALTO_CLIENT_CLIENT_CONTROLLER_H_
|