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 "Controller.h"
21 : #include "RialtoServerManagerLogging.h"
22 : #include <algorithm>
23 : #include <string>
24 : #include <utility>
25 :
26 : namespace rialto::servermanager::ipc
27 : {
28 19 : Controller::Controller(std::unique_ptr<common::ISessionServerAppManager> &sessionServerAppManager)
29 19 : : m_sessionServerAppManager{sessionServerAppManager}
30 : {
31 : }
32 :
33 18 : bool Controller::createClient(int serverId, int appMgmtSocket)
34 : {
35 18 : std::unique_lock<std::mutex> lock{m_clientMutex};
36 18 : if (m_clients.find(serverId) == m_clients.end())
37 : {
38 17 : auto newClient = std::make_unique<Client>(m_sessionServerAppManager, serverId, appMgmtSocket);
39 17 : if (newClient->connect())
40 : {
41 16 : m_clients.emplace(std::make_pair(serverId, std::move(newClient)));
42 16 : return true;
43 : }
44 1 : return false;
45 17 : }
46 1 : return false;
47 18 : }
48 :
49 1 : void Controller::removeClient(int serverId)
50 : {
51 1 : std::unique_lock<std::mutex> lock{m_clientMutex};
52 1 : m_clients.erase(serverId);
53 : }
54 :
55 4 : bool Controller::performSetState(int serverId, const firebolt::rialto::common::SessionServerState &state)
56 : {
57 4 : std::unique_lock<std::mutex> lock{m_clientMutex};
58 4 : auto client = m_clients.find(serverId);
59 4 : if (client != m_clients.end())
60 : {
61 2 : return client->second->performSetState(state);
62 : }
63 2 : return false;
64 4 : }
65 :
66 2 : bool Controller::performSetConfiguration(int serverId, const firebolt::rialto::common::SessionServerState &initialState,
67 : const std::string &socketName, const std::string &clientDisplayName,
68 : const firebolt::rialto::common::MaxResourceCapabilitites &maxResource,
69 : const unsigned int socketPermissions, const std::string &socketOwner,
70 : const std::string &socketGroup, const std::string &appName)
71 : {
72 2 : std::unique_lock<std::mutex> lock{m_clientMutex};
73 2 : auto client = m_clients.find(serverId);
74 2 : if (client != m_clients.end())
75 : {
76 2 : return client->second->performSetConfiguration(initialState, socketName, clientDisplayName, maxResource,
77 2 : socketPermissions, socketOwner, socketGroup, appName);
78 : }
79 0 : return false;
80 2 : }
81 :
82 2 : bool Controller::performSetConfiguration(int serverId, const firebolt::rialto::common::SessionServerState &initialState,
83 : int socketFd, const std::string &clientDisplayName,
84 : const firebolt::rialto::common::MaxResourceCapabilitites &maxResource,
85 : const std::string &appName)
86 : {
87 2 : std::unique_lock<std::mutex> lock{m_clientMutex};
88 2 : auto client = m_clients.find(serverId);
89 2 : if (client != m_clients.end())
90 : {
91 2 : return client->second->performSetConfiguration(initialState, socketFd, clientDisplayName, maxResource, appName);
92 : }
93 0 : return false;
94 2 : }
95 :
96 3 : bool Controller::performPing(int serverId, int pingId)
97 : {
98 3 : std::unique_lock<std::mutex> lock{m_clientMutex};
99 3 : auto client = m_clients.find(serverId);
100 3 : if (client != m_clients.end())
101 : {
102 2 : return client->second->performPing(pingId);
103 : }
104 1 : return false;
105 3 : }
106 :
107 2 : bool Controller::setLogLevels(const service::LoggingLevels &logLevels) const
108 : {
109 2 : std::unique_lock<std::mutex> lock{m_clientMutex};
110 2 : return std::all_of(m_clients.begin(), m_clients.end(),
111 6 : [&](const auto &client) { return client.second->setLogLevels(logLevels); });
112 2 : }
113 : } // namespace rialto::servermanager::ipc
|