0daf5b224339cb046d0c32932e39fc223a70a5f9
[platform/core/appfw/launchpad.git] / src / launchpad-process-pool / config.hh
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef LAUNCHPAD_PROCESS_POOL_CONFIG_HH_
18 #define LAUNCHPAD_PROCESS_POOL_CONFIG_HH_
19
20 #include <vconf.h>
21
22 #include <string>
23
24 #include <ini_parser.hh>
25
26 namespace launchpad {
27
28 class Config {
29  public:
30   class MemoryStatus {
31    public:
32     explicit MemoryStatus(const IniParser& parser);
33
34     const std::string& GetLowKey() const;
35     const int GetLowValue() const;
36     const std::string& GetNormalKey() const;
37     const int GetNormalValue() const;
38
39    private:
40     std::string low_key_ = VCONFKEY_SYSMAN_LOW_MEMORY;
41     int low_value_ = VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING;
42     std::string normal_key_ = VCONFKEY_SYSMAN_LOW_MEMORY;
43     int normal_value_ = VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL;
44   };
45
46   class MemoryMonitor {
47    public:
48     explicit MemoryMonitor(const IniParser& parser);
49
50     const int GetThreshold() const;
51     const int GetInterval() const;
52
53    private:
54     int threshold_ = 80;
55     int interval_ = 5000;
56   };
57
58   class CPUChecker {
59    public:
60     explicit CPUChecker(const IniParser& parser);
61
62     const int GetMaxCount() const;
63     const bool IsEnabled() const;
64
65    private:
66     int max_count_ = 10;
67     bool enable_ = false;
68   };
69
70   class Logger {
71    public:
72     explicit Logger(const IniParser& parser);
73
74     const std::string& GetPath() const;
75     const bool IsEnabled() const;
76
77    private:
78     std::string path_ = "/var/log/appfw";
79     bool enable_ = true;
80   };
81
82   class ProcessPool {
83    public:
84     explicit ProcessPool(const IniParser& parser);
85
86     const int GetNumberOfProcesses() const;
87     const int GetNumberOfLoaderProcesses() const;
88
89    private:
90     int number_of_processes_ = 1;
91     int number_of_loader_processes_ = 1;
92   };
93
94   class LaunchMode {
95    public:
96     enum class Mode : int {
97       PreviousOperation = 0,
98       DefaultOperation = 1,
99       AlwaysLoader = 2,
100       AlwaysLoaderWithoutCPUChecker = 3,
101       AlwaysLoaderWithLowPriority = 4,
102     };
103
104     explicit LaunchMode(const IniParser& parser);
105
106     const Mode GetMode() const;
107
108    private:
109     Mode mode_ = Mode::DefaultOperation;
110   };
111
112   Config(const Config&) = delete;
113   Config& operator = (const Config&) = delete;
114   Config(Config&&) = delete;
115   Config& operator = (Config&&) = delete;
116
117   static Config& GetInst();
118
119   const MemoryStatus& GetMemoryStatus() const;
120   const MemoryMonitor& GetMemoryMonitor() const;
121   const CPUChecker& GetCPUChecker() const;
122   const Logger& GetLogger() const;
123   const ProcessPool& GetProcessPool() const;
124   const LaunchMode& GetLaunchMode() const;
125
126  private:
127   Config();
128   ~Config() = default;
129
130  private:
131   IniParser parser_;
132   MemoryStatus memory_status_;
133   MemoryMonitor memory_monitor_;
134   CPUChecker cpu_checker_;
135   Logger logger_;
136   ProcessPool process_pool_;
137   LaunchMode launch_mode_;
138 };
139
140 }  // namespace launchpad
141
142 #endif  // LAUNCHPAD_PROCESS_POOL_CONFIG_HH_