acd_main.cpp
2.86 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
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright 2002-2014 the original author or authors.
*
* 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
*
* CC/LICENSE
*
* 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.
*/
#include <iomanip>
#include "acd_tool.h"
void ShowVersion() {
cout << "Auto Call Distribution Server " << ACD_VERSION << endl;
}
void ShowHelp() {
ShowVersion();
cout << left << setw(20) << "--help, -h" << "Show this help page." << endl;
cout << left << setw(20) << "--version, -v" << "Show version." << endl;
cout << left << setw(20) << "--config, -c" << "Reload config file." << endl;
}
void ResetConfig() {
string password;
cout << "input password: ";
cin >> password;
acd::acdapiProxy proxy(bgcc::ServerInfo("127.0.0.1", (uint16_t)acd_tool::LocalPort()));
acd::AcdResultT ret = acd::AcdResultT::ArSuccess;
ret = proxy.ResetConfig(password);
if (proxy.get_errno() != 0) {
cout << "communication error, reset config fail!" << endl;
exit(0);
}
if (acd::AcdResultT::ArSuccess == ret) {
cout << "reset config success!" << endl;
} else if (acd::AcdResultT::ArPasswordError == ret) {
cout << "wrong password, reset config fail!" << endl;
} else {
cout << "error, reset config fail!" << endl;
}
}
#if WIN32
char getopt(int argc, char* argv[], const string& opt) {
if (2 != argc) {
return 0;
}
string optinput(argv[1]);
if (2 != optinput.size() || '-' != optinput[0]) {
return 0;
}
if (string::npos == opt.find(optinput[1])) {
return 0;
} else {
return optinput[1];
}
}
#else
struct option long_options[] = {
// name, has_arg, flag, val
{"config", 0, NULL, 'c'},
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'v'},
{NULL, 0, NULL, 0}
};
#endif
int main(int argc, char* argv[]) {
if (1 == argc) {
acd_tool::init();
acd_tool::un_init();
} else {
#if WIN32
char c = getopt(argc, argv, "hvc");
#else
char c = getopt_long(argc, argv, "hvc", long_options, NULL);
#endif
if (c == -1) {
return 0;
}
switch (c) {
case 'h':
ShowHelp();
break;
case 'v':
ShowVersion();
break;
case 'c':
ResetConfig();
break;
default:
ShowHelp();
break;
}
}
return 0;
}