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 : #include "Control.h"
21 : #include "IControlIpc.h"
22 : #include "RialtoClientLogging.h"
23 : #include <utility>
24 :
25 : namespace firebolt::rialto
26 : {
27 1 : std::shared_ptr<IControlFactory> IControlFactory::createFactory()
28 : {
29 1 : return client::ControlFactory::createFactory();
30 : }
31 : }; // namespace firebolt::rialto
32 :
33 : namespace firebolt::rialto::client
34 : {
35 1 : std::shared_ptr<ControlFactory> ControlFactory::createFactory()
36 : {
37 1 : std::shared_ptr<ControlFactory> factory;
38 : try
39 : {
40 1 : factory = std::make_shared<client::ControlFactory>();
41 : }
42 0 : catch (const std::exception &e)
43 : {
44 0 : RIALTO_CLIENT_LOG_ERROR("Failed to create the rialto control factory, reason: %s", e.what());
45 : }
46 :
47 1 : return factory;
48 : }
49 :
50 1 : std::shared_ptr<IControl> ControlFactory::createControl() const
51 : try
52 : {
53 1 : return std::make_shared<Control>(IClientControllerAccessor::instance().getClientController());
54 : }
55 1 : catch (const std::exception &e)
56 : {
57 1 : RIALTO_CLIENT_LOG_ERROR("Failed to create the rialto control, reason: %s", e.what());
58 1 : return nullptr;
59 : }
60 :
61 1 : Control::Control(IClientController &clientController) : m_clientController(clientController)
62 : {
63 1 : RIALTO_CLIENT_LOG_DEBUG("entry:");
64 : }
65 :
66 2 : Control::~Control()
67 : {
68 1 : RIALTO_CLIENT_LOG_DEBUG("entry:");
69 1 : for (const auto &client : m_clientsToUnregister)
70 : {
71 0 : m_clientController.unregisterClient(client);
72 : }
73 2 : }
74 :
75 0 : bool Control::registerClient(std::weak_ptr<IControlClient> client, ApplicationState &appState)
76 : {
77 0 : std::shared_ptr<IControlClient> lockedClient = client.lock();
78 0 : if (lockedClient && m_clientController.registerClient(lockedClient, appState))
79 : {
80 0 : m_clientsToUnregister.push_back(std::move(lockedClient));
81 0 : return true;
82 : }
83 0 : RIALTO_CLIENT_LOG_WARN("Unable to register client");
84 0 : return false;
85 : }
86 :
87 : }; // namespace firebolt::rialto::client
|