-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
78 lines (67 loc) · 1.75 KB
/
main.cpp
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
#include "common.h"
#include "./lib/lightConf/ConfigFile.h"
#include "mmysql.h"
#include "worker.h"
static int GetProcessCount(const ConfData& conf)
{
int count = 0;
MYSQL* sqlIns = openMysql(conf.dbip.c_str(),conf.dbport,conf.dbuser.c_str(),conf.dbpwd.c_str(),conf.dbname.c_str());
if(sqlIns == NULL)
return -1;
char sql[SQLLEN] = {'\0'};
snprintf(sql,SQLLEN,"select count from info_status;");
doStatusSql(sqlIns,sql,count);
closeMysql(sqlIns);
return count;
}
static ConfData loadConf()
{
ConfData confData;
ConfigFile conf("./conf/dp.conf");
try
{
confData.dbip = (std::string) conf.Value("DB","ip");
confData.dbport = (int)conf.Value("DB","port");
confData.dbpwd = (std::string) conf.Value("DB","pwd");
confData.dbuser = (std::string) conf.Value("DB","user");
confData.dbname = (std::string) conf.Value("DB","db");
confData.mcip = (std::string) conf.Value("MC","ip");
confData.mcport = (int) conf.Value("MC","port");
confData.threadNum = (int) conf.Value("common","threadNum");
}
catch(char const* msg)
{
mylogD("load conf catch exception : %s",msg);
exit(0);
}
return confData;
}
int main()
{
ConfData conf = loadConf();
int count = GetProcessCount(conf);
if(count<=0)
return -1;
int eachRange = count/conf.threadNum;
uint32_t s = 1;
uint32_t e = 0;
Worker** worker = new Worker*[conf.threadNum];
for (int i = 0; i < conf.threadNum; ++i)
{
e = s + eachRange;
if(e>count)
e = count;
worker[i] = new Worker(conf,Prange(s,e));
mylogD("%d : %d - %d",i,s,e);
s = e+1;
worker[i]->start();
}
for (int i = 0; i < conf.threadNum; ++i)
{
worker[i]->join();
}
for (int i = 0; i < conf.threadNum; ++i)
delete worker[i];
delete worker;
return 0;
}