2026-05-14 15:27:08 +05:30
|
|
|
#ifndef APPINFO_H
|
|
|
|
|
#define APPINFO_H
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <deque>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <syncstream>
|
2026-05-14 17:06:59 +05:30
|
|
|
#include <atomic>
|
2026-05-14 15:27:08 +05:30
|
|
|
|
|
|
|
|
class AppInfo
|
|
|
|
|
{
|
|
|
|
|
typedef std::unordered_map<std::string, std::string> string_map;
|
|
|
|
|
public:
|
|
|
|
|
enum class State {
|
|
|
|
|
initial,
|
|
|
|
|
running,
|
|
|
|
|
exited
|
|
|
|
|
};
|
|
|
|
|
enum class RunMode {
|
|
|
|
|
script,
|
|
|
|
|
daemon
|
|
|
|
|
};
|
|
|
|
|
struct AppData {
|
|
|
|
|
std::string program_name;
|
|
|
|
|
std::string module_name;
|
|
|
|
|
std::deque<std::string> args;
|
|
|
|
|
std::string working_dir;
|
|
|
|
|
string_map after;
|
2026-05-20 20:41:38 +05:30
|
|
|
string_map env;
|
2026-05-14 15:27:08 +05:30
|
|
|
std::string run_mode;
|
|
|
|
|
bool create_log = false;
|
|
|
|
|
void printInfo(std::ostream &out);
|
|
|
|
|
std::string getAfterString() const;
|
|
|
|
|
std::string getAfterKeys() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::string program_name;
|
|
|
|
|
std::string module_name;
|
|
|
|
|
std::deque<std::string> args;
|
|
|
|
|
std::string working_dir;
|
|
|
|
|
string_map after;
|
2026-05-20 20:41:38 +05:30
|
|
|
string_map env;
|
2026-05-14 15:27:08 +05:30
|
|
|
bool create_log = false;
|
|
|
|
|
std::unordered_map<std::shared_ptr<AppInfo>, State> parents;
|
2026-05-14 17:06:59 +05:30
|
|
|
std::atomic<State> state{State::initial};
|
2026-05-14 15:27:08 +05:30
|
|
|
RunMode mode = RunMode::script;
|
|
|
|
|
public:
|
|
|
|
|
void setProgramName(std::string name);
|
|
|
|
|
void setModuleName(std::string name);
|
|
|
|
|
void setArgs(std::deque<std::string> args);
|
|
|
|
|
void setWorkingDir(std::string working_dir);
|
|
|
|
|
void setAfter(string_map after);
|
2026-05-20 20:41:38 +05:30
|
|
|
void setEnv(string_map env);
|
2026-05-14 15:27:08 +05:30
|
|
|
void setCreateLog(bool create_log);
|
|
|
|
|
void setRunMode(std::string mode);
|
|
|
|
|
void setFinished();
|
|
|
|
|
void setRunning();
|
|
|
|
|
void insertParent(std::shared_ptr<AppInfo> parent, State state);
|
|
|
|
|
bool isParentDependencyCleared(std::osyncstream &out) const;
|
|
|
|
|
std::string getModuleName() const;
|
|
|
|
|
std::string getProgramName() const;
|
|
|
|
|
std::deque<std::string> getArgs() const;
|
|
|
|
|
std::string getWorkingDir() const;
|
2026-05-20 20:41:38 +05:30
|
|
|
string_map getEnv() const;
|
2026-05-14 15:27:08 +05:30
|
|
|
string_map getAfter() const;
|
|
|
|
|
std::string getAfterString() const;
|
|
|
|
|
std::string getAfterKeys() const;
|
|
|
|
|
RunMode getRunMode() const;
|
|
|
|
|
State getState() const;
|
|
|
|
|
std::unordered_map<std::shared_ptr<AppInfo>, State> getParents() const;
|
|
|
|
|
void copyFromData(AppInfo::AppData &other);
|
|
|
|
|
bool getCreateLog();
|
|
|
|
|
AppInfo();
|
|
|
|
|
~AppInfo();
|
|
|
|
|
AppInfo(const AppInfo &other) = delete;
|
|
|
|
|
AppInfo(const AppInfo &&other) = delete;
|
|
|
|
|
AppInfo &operator=(const AppInfo &other) = delete;
|
|
|
|
|
bool operator==(const AppInfo &other);
|
|
|
|
|
void printInfo(std::ostream& out);
|
|
|
|
|
private:
|
|
|
|
|
std::string runmodeToString() const;
|
|
|
|
|
std::string stateToString() const;
|
|
|
|
|
std::string stateToString(State s) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // APPINFO_H
|