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