summaryrefslogtreecommitdiff
path: root/src/launchpad-process-pool/config.hh
blob: 0daf5b224339cb046d0c32932e39fc223a70a5f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LAUNCHPAD_PROCESS_POOL_CONFIG_HH_
#define LAUNCHPAD_PROCESS_POOL_CONFIG_HH_

#include <vconf.h>

#include <string>

#include <ini_parser.hh>

namespace launchpad {

class Config {
 public:
  class MemoryStatus {
   public:
    explicit MemoryStatus(const IniParser& parser);

    const std::string& GetLowKey() const;
    const int GetLowValue() const;
    const std::string& GetNormalKey() const;
    const int GetNormalValue() const;

   private:
    std::string low_key_ = VCONFKEY_SYSMAN_LOW_MEMORY;
    int low_value_ = VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING;
    std::string normal_key_ = VCONFKEY_SYSMAN_LOW_MEMORY;
    int normal_value_ = VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL;
  };

  class MemoryMonitor {
   public:
    explicit MemoryMonitor(const IniParser& parser);

    const int GetThreshold() const;
    const int GetInterval() const;

   private:
    int threshold_ = 80;
    int interval_ = 5000;
  };

  class CPUChecker {
   public:
    explicit CPUChecker(const IniParser& parser);

    const int GetMaxCount() const;
    const bool IsEnabled() const;

   private:
    int max_count_ = 10;
    bool enable_ = false;
  };

  class Logger {
   public:
    explicit Logger(const IniParser& parser);

    const std::string& GetPath() const;
    const bool IsEnabled() const;

   private:
    std::string path_ = "/var/log/appfw";
    bool enable_ = true;
  };

  class ProcessPool {
   public:
    explicit ProcessPool(const IniParser& parser);

    const int GetNumberOfProcesses() const;
    const int GetNumberOfLoaderProcesses() const;

   private:
    int number_of_processes_ = 1;
    int number_of_loader_processes_ = 1;
  };

  class LaunchMode {
   public:
    enum class Mode : int {
      PreviousOperation = 0,
      DefaultOperation = 1,
      AlwaysLoader = 2,
      AlwaysLoaderWithoutCPUChecker = 3,
      AlwaysLoaderWithLowPriority = 4,
    };

    explicit LaunchMode(const IniParser& parser);

    const Mode GetMode() const;

   private:
    Mode mode_ = Mode::DefaultOperation;
  };

  Config(const Config&) = delete;
  Config& operator = (const Config&) = delete;
  Config(Config&&) = delete;
  Config& operator = (Config&&) = delete;

  static Config& GetInst();

  const MemoryStatus& GetMemoryStatus() const;
  const MemoryMonitor& GetMemoryMonitor() const;
  const CPUChecker& GetCPUChecker() const;
  const Logger& GetLogger() const;
  const ProcessPool& GetProcessPool() const;
  const LaunchMode& GetLaunchMode() const;

 private:
  Config();
  ~Config() = default;

 private:
  IniParser parser_;
  MemoryStatus memory_status_;
  MemoryMonitor memory_monitor_;
  CPUChecker cpu_checker_;
  Logger logger_;
  ProcessPool process_pool_;
  LaunchMode launch_mode_;
};

}  // namespace launchpad

#endif  // LAUNCHPAD_PROCESS_POOL_CONFIG_HH_