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 "ServerManagerService.h"
21 : #include "ISessionServerAppManager.h"
22 : #include "RialtoServerManagerLogging.h"
23 : #include "Utils.h"
24 :
25 : namespace
26 : {
27 1 : rialto::servermanager::service::ILogHandler::Level convertLevel(const RIALTO_DEBUG_LEVEL &level)
28 : {
29 1 : switch (level)
30 : {
31 0 : case RIALTO_DEBUG_LEVEL_FATAL:
32 0 : return rialto::servermanager::service::ILogHandler::Level::Fatal;
33 0 : case RIALTO_DEBUG_LEVEL_ERROR:
34 0 : return rialto::servermanager::service::ILogHandler::Level::Error;
35 0 : case RIALTO_DEBUG_LEVEL_WARNING:
36 0 : return rialto::servermanager::service::ILogHandler::Level::Warning;
37 0 : case RIALTO_DEBUG_LEVEL_MILESTONE:
38 0 : return rialto::servermanager::service::ILogHandler::Level::Milestone;
39 1 : case RIALTO_DEBUG_LEVEL_INFO:
40 1 : return rialto::servermanager::service::ILogHandler::Level::Info;
41 0 : case RIALTO_DEBUG_LEVEL_DEBUG:
42 0 : return rialto::servermanager::service::ILogHandler::Level::Debug;
43 0 : case RIALTO_DEBUG_LEVEL_EXTERNAL:
44 0 : return rialto::servermanager::service::ILogHandler::Level::External;
45 0 : case RIALTO_DEBUG_LEVEL_DEFAULT:
46 0 : return rialto::servermanager::service::ILogHandler::Level::Milestone;
47 : }
48 0 : return rialto::servermanager::service::ILogHandler::Level::Debug;
49 : }
50 : } // namespace
51 :
52 : namespace rialto::servermanager::service
53 : {
54 9 : ServerManagerService::ServerManagerService(std::unique_ptr<IServiceContext> &&context, unsigned numOfPreloadedServers)
55 9 : : m_kContext{std::move(context)}
56 : {
57 9 : RIALTO_SERVER_MANAGER_LOG_MIL("RialtoServerManager is starting...");
58 9 : m_kContext->getSessionServerAppManager().preloadSessionServers(numOfPreloadedServers);
59 : }
60 :
61 27 : ServerManagerService::~ServerManagerService()
62 : {
63 9 : RIALTO_SERVER_MANAGER_LOG_MIL("RialtoServerManager is closing...");
64 9 : if (m_logHandler)
65 : {
66 1 : firebolt::rialto::logging::setLogHandler(RIALTO_COMPONENT_SERVER_MANAGER, 0, false);
67 : }
68 18 : }
69 :
70 2 : bool ServerManagerService::initiateApplication(const std::string &appId,
71 : const firebolt::rialto::common::SessionServerState &state,
72 : const firebolt::rialto::common::AppConfig &appConfig)
73 : {
74 2 : return m_kContext->getSessionServerAppManager().initiateApplication(appId, state, appConfig);
75 : }
76 :
77 2 : bool ServerManagerService::changeSessionServerState(const std::string &appId,
78 : const firebolt::rialto::common::SessionServerState &state)
79 : {
80 2 : return m_kContext->getSessionServerAppManager().setSessionServerState(appId, state);
81 : }
82 :
83 1 : std::string ServerManagerService::getAppConnectionInfo(const std::string &appId) const
84 : {
85 1 : return m_kContext->getSessionServerAppManager().getAppConnectionInfo(appId);
86 : }
87 :
88 2 : bool ServerManagerService::setLogLevels(const LoggingLevels &logLevels) const
89 : {
90 2 : return m_kContext->getSessionServerAppManager().setLogLevels(logLevels);
91 : }
92 :
93 2 : bool ServerManagerService::registerLogHandler(const std::shared_ptr<ILogHandler> &handler)
94 : {
95 2 : if (!handler)
96 : {
97 1 : RIALTO_SERVER_MANAGER_LOG_ERROR("Cannot set custom log handler - ptr is null!");
98 1 : return false;
99 : }
100 1 : m_logHandler = handler;
101 : return firebolt::rialto::logging::RIALTO_LOGGING_STATUS_OK ==
102 1 : firebolt::rialto::logging::setLogHandler(RIALTO_COMPONENT_SERVER_MANAGER,
103 2 : std::bind(&ServerManagerService::forwardLog, this,
104 : std::placeholders::_1, std::placeholders::_2,
105 : std::placeholders::_3, std::placeholders::_4,
106 : std::placeholders::_5, std::placeholders::_6),
107 1 : false);
108 : }
109 :
110 1 : void ServerManagerService::forwardLog(RIALTO_DEBUG_LEVEL level, const char *file, int line, const char *function,
111 : const char *message, std::size_t messageLen) const
112 : {
113 1 : if (!m_logHandler)
114 : {
115 0 : return;
116 : }
117 7 : m_logHandler->log(convertLevel(level), std::string(file), line, std::string(function), std::string(message));
118 : }
119 : } // namespace rialto::servermanager::service
|