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 : #include "ControlClientServerInternal.h"
21 : #include "RialtoServerLogging.h"
22 : #include "controlmodule.pb.h"
23 : #include <IIpcServer.h>
24 :
25 : namespace
26 : {
27 : firebolt::rialto::ApplicationStateChangeEvent_ApplicationState
28 3 : convertApplicationState(const firebolt::rialto::ApplicationState &state)
29 : {
30 3 : switch (state)
31 : {
32 1 : case firebolt::rialto::ApplicationState::RUNNING:
33 1 : return firebolt::rialto::ApplicationStateChangeEvent_ApplicationState_RUNNING;
34 1 : case firebolt::rialto::ApplicationState::INACTIVE:
35 1 : return firebolt::rialto::ApplicationStateChangeEvent_ApplicationState_INACTIVE;
36 1 : case firebolt::rialto::ApplicationState::UNKNOWN:
37 1 : break;
38 : // do nothing
39 : }
40 1 : return firebolt::rialto::ApplicationStateChangeEvent_ApplicationState_UNKNOWN;
41 : }
42 : } // namespace
43 :
44 : namespace firebolt::rialto::server::ipc
45 : {
46 7 : ControlClientServerInternal::ControlClientServerInternal(int controlId,
47 7 : const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
48 7 : : m_kControlId{controlId}, m_ipcClient{ipcClient}
49 : {
50 : }
51 :
52 3 : void ControlClientServerInternal::notifyApplicationState(ApplicationState state)
53 : {
54 3 : RIALTO_SERVER_LOG_DEBUG("Sending ApplicationStateChangeEvent");
55 :
56 3 : auto event = std::make_shared<firebolt::rialto::ApplicationStateChangeEvent>();
57 3 : event->set_control_handle(m_kControlId);
58 3 : event->set_application_state(convertApplicationState(state));
59 :
60 3 : m_ipcClient->sendEvent(event);
61 : }
62 :
63 1 : void ControlClientServerInternal::ping(uint32_t id)
64 : {
65 1 : RIALTO_SERVER_LOG_DEBUG("Sending PingEvent with id: %d", id);
66 :
67 1 : auto event = std::make_shared<firebolt::rialto::PingEvent>();
68 1 : event->set_control_handle(m_kControlId);
69 1 : event->set_id(id);
70 :
71 1 : m_ipcClient->sendEvent(event);
72 : }
73 : } // namespace firebolt::rialto::server::ipc
|