Repository navigation
Expand file tree
/
Copy pathConfig.h
More file actions
106 lines (86 loc) · 2.88 KB
/
Copy pathConfig.h
File metadata and controls
106 lines (86 loc) · 2.88 KB
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
/*
* @Author: Duanran 995122760@qq.com
* @Date: 2024-06-03 15:17:38
* @LastEditors: Duanran 995122760@qq.com
* @LastEditTime: 2024-07-09 14:41:34
* @FilePath: /VideoServer/src/base/Config.h
* @Description:
*
* Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
*/
#pragma once
#include <memory>
#include <string>
#include <mutex>
#include "base/Singleton.h"
#include "base/NoCopyable.h"
#include "json/json.h"
#include "base/Logger.h"
#include "base/FileMg.h"
#include <unordered_map>
namespace vdse
{
namespace base
{
using std::string;
struct LogInfo
{
RotateType rotate{kRotateNone};
std::string name;
std::string path;
LogLevel level;
};
using LogInfoPtr = std::shared_ptr<LogInfo>;
struct ServiceInfo
{
string addr;
uint16_t port;
string protocol;
string transport;
};
using ServiceInfoPtr = std::shared_ptr<ServiceInfo>;
class DomainInfo;
class AppInfo;
using DomainInfoPtr = std::shared_ptr<DomainInfo>;
using AppInfoPtr = std::shared_ptr<AppInfo>;
class Config
{
public:
Config() = default;
~Config() = default;
bool LoadConfig(const std::string &file);
LogInfoPtr& GetLogInfo();
const std::vector<ServiceInfoPtr> & GetServiceInfos();
const ServiceInfoPtr &GetServiceInfo(const string &protocol,const string &transport);
bool ParseServiceInfo(const Json::Value &serviceObj);
AppInfoPtr GetAppInfo(const string &domain,const string &app);
DomainInfoPtr GetDomainInfo(const string &domain);
private:
bool ParseLogInfo(const Json::Value &root);
bool ParseDirectory(const Json::Value &root);
bool ParseDomainPath(const string &path);
bool ParseDomainFile(const string &file);
LogInfoPtr log_info_;
std::string name_;
int32_t cpu_start_;
int32_t thread_nums_;
std::mutex lock_;
std::vector<ServiceInfoPtr> services_;
std::unordered_map<std::string,DomainInfoPtr> domaininfos_;
};
using ConfigPtr = std::shared_ptr<Config>;
class ConfigMg
{
public:
ConfigMg() = default;
~ConfigMg() = default;
bool LoadConfig(const std::string &file);
ConfigPtr GetConfig();
LogInfoPtr& GetLogInfo();
private:
std::mutex lock_;
ConfigPtr config_;
};
#define sConfigMg vdse::base::Singletion<vdse::base::ConfigMg>::Instance()
}
}