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 2024 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 : #ifndef FIREBOLT_RIALTO_CLIENT_CLIENT_LOG_CONTROL_H_
21 : #define FIREBOLT_RIALTO_CLIENT_CLIENT_LOG_CONTROL_H_
22 :
23 : #include <memory>
24 : #include <mutex>
25 : #include <string>
26 : #include <vector>
27 :
28 : #include "IClientLogControl.h"
29 : #include "RialtoLogging.h"
30 :
31 : namespace firebolt::rialto::client
32 : {
33 : /**
34 : * @brief IClientLogControl factory class definition.
35 : */
36 : class ClientLogControlFactory : public IClientLogControlFactory
37 : {
38 : public:
39 8 : ClientLogControlFactory() = default;
40 8 : ~ClientLogControlFactory() override = default;
41 :
42 : IClientLogControl &createClientLogControl() override;
43 :
44 : /**
45 : * @brief Create the (singleton) object.
46 : *
47 : * @retval the factory instance or null on error.
48 : */
49 : static std::shared_ptr<IClientLogControlFactory> createFactory();
50 : };
51 :
52 : /**
53 : * @brief The definition of the Control.
54 : */
55 : class ClientLogControl : public IClientLogControl
56 : {
57 : public:
58 : /**
59 : * @brief The constructor.
60 : */
61 : ClientLogControl();
62 :
63 : ClientLogControl(const ClientLogControl &) = delete;
64 : ClientLogControl &operator=(const ClientLogControl &) = delete;
65 :
66 : /**
67 : * @brief Virtual destructor.
68 : */
69 : ~ClientLogControl() override;
70 :
71 : bool registerLogHandler(const std::shared_ptr<IClientLogHandler> &handler, bool ignoreLogLevels) override;
72 :
73 : private:
74 : void forwardLog(RIALTO_COMPONENT component, RIALTO_DEBUG_LEVEL level, const char *file, int line,
75 : const char *function, const char *message, std::size_t messageLen);
76 : void cancelLogHandler();
77 :
78 : /**
79 : * @brief The registered log handler
80 : */
81 : std::shared_ptr<IClientLogHandler> m_logHandler;
82 : std::mutex m_logHandlerMutex;
83 : };
84 :
85 : }; // namespace firebolt::rialto::client
86 :
87 : #endif // FIREBOLT_RIALTO_CLIENT_CLIENT_LOG_CONTROL_H_
|