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 2022 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_CONTROL_IPC_H_
21 : #define FIREBOLT_RIALTO_CLIENT_CONTROL_IPC_H_
22 :
23 : #include "IConnectionObserver.h"
24 : #include "IControlClient.h"
25 : #include "IControlIpc.h"
26 : #include "IEventThread.h"
27 : #include "IpcModule.h"
28 : #include <memory>
29 :
30 : #include "controlmodule.pb.h"
31 :
32 : namespace firebolt::rialto::client
33 : {
34 : class ControlIpc;
35 :
36 : /**
37 : * @brief IControlIpc factory class definition.
38 : */
39 : class ControlIpcFactory : public IControlIpcFactory
40 : {
41 : public:
42 1 : ControlIpcFactory() = default;
43 1 : ~ControlIpcFactory() override = default;
44 :
45 : std::shared_ptr<IControlIpc> createControlIpc(IControlClient *controlClient) override;
46 :
47 : /**
48 : * @brief Create the generic control factory object.
49 : *
50 : * @retval the generic control factory instance or null on error.
51 : */
52 : static std::shared_ptr<ControlIpcFactory> createFactory();
53 : };
54 :
55 : /**
56 : * @brief The definition of the ControlIpc.
57 : */
58 : class ControlIpc : public IControlIpc, public IpcModule, public IConnectionObserver
59 : {
60 : public:
61 : /**
62 : * @brief The constructor.
63 : */
64 : ControlIpc(IControlClient *controlClient, IIpcClient &ipcClient,
65 : const std::shared_ptr<common::IEventThreadFactory> &eventThreadFactory);
66 :
67 : /**
68 : * @brief Virtual destructor.
69 : */
70 : virtual ~ControlIpc();
71 :
72 : bool getSharedMemory(int32_t &fd, uint32_t &size) override;
73 : bool registerClient() override;
74 :
75 : private:
76 : bool createRpcStubs(const std::shared_ptr<ipc::IChannel> &ipcChannel) override;
77 : bool subscribeToEvents(const std::shared_ptr<ipc::IChannel> &ipcChannel) override;
78 : void onConnectionBroken() override;
79 :
80 : /**
81 : * @brief Handler for a application state update from the server.
82 : *
83 : * @param[in] event : The app state changed event structure.
84 : */
85 : void onApplicationStateUpdated(const std::shared_ptr<firebolt::rialto::ApplicationStateChangeEvent> &event);
86 :
87 : /**
88 : * @brief Handler for a ping from the server.
89 : *
90 : * @param[in] event : The ping event structure.
91 : */
92 : void onPing(const std::shared_ptr<firebolt::rialto::PingEvent> &event);
93 :
94 : private:
95 : /**
96 : * @brief Control client for handling messages from server
97 : */
98 : IControlClient *m_controlClient;
99 :
100 : /**
101 : * @brief The control handle for the current instance.
102 : */
103 : std::atomic<int> m_controlHandle;
104 :
105 : /**
106 : * @brief Thread for handling media player events from the server.
107 : */
108 : std::unique_ptr<common::IEventThread> m_eventThread;
109 :
110 : /**
111 : * @brief RPC stubs for the Control APIs.
112 : */
113 : std::shared_ptr<::firebolt::rialto::ControlModule_Stub> m_controlStub;
114 : };
115 :
116 : }; // namespace firebolt::rialto::client
117 :
118 : #endif // FIREBOLT_RIALTO_CLIENT_CONTROL_IPC_H_
|