Skip to content

Commit 2e2b637

Browse files
authored
Merge pull request #358 from ktf/pr358
Fix C-isms
2 parents 7909221 + 5bf7e4b commit 2e2b637

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

src/sendMetric.cxx

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,37 @@ void print_usage()
3030
printf("\nExample: o2-monitoring-send -u influxdb-stdout:// -m test.metric -i 12345\n");
3131
}
3232

33-
3433
int main(int argc, char** argv)
3534
{
3635

37-
bool verbose = 0; // if set, prints detailed messages
38-
36+
bool verbose = false; // if set, prints detailed messages
37+
3938
std::unique_ptr<Monitoring> monitoringCollector;
40-
char option;
39+
int option;
4140

42-
bool isOk = 1;
43-
const char *monitoringURI = nullptr;
44-
const char *monitoringValue = nullptr;
45-
const char *monitoringMetric = nullptr;
41+
bool isOk = true;
42+
const char* monitoringURI = nullptr;
43+
const char* monitoringValue = nullptr;
44+
const char* monitoringMetric = nullptr;
4645

4746
// read options
4847
while ((option = getopt(argc, argv, "hvu:i:m:")) != -1) {
4948
switch (option) {
50-
49+
5150
case 'u': {
5251
monitoringURI = optarg;
5352
} break;
54-
53+
5554
case 'i': {
5655
monitoringValue = optarg;
5756
} break;
58-
57+
5958
case 'm': {
6059
monitoringMetric = optarg;
6160
} break;
62-
61+
6362
case 'v': {
64-
verbose = 1;
63+
verbose = true;
6564
} break;
6665

6766
case 'h':
@@ -76,19 +75,19 @@ int main(int argc, char** argv)
7675

7776
if (monitoringURI == nullptr) {
7877
printf("Unspecified monitoring URI.\n");
79-
isOk = 0;
78+
isOk = false;
8079
}
8180

8281
if (monitoringMetric == nullptr) {
8382
printf("Unspecified monitoring metric.\n");
84-
isOk = 0;
83+
isOk = false;
8584
}
8685

8786
if (monitoringValue == nullptr) {
8887
printf("Unspecified monitoring value.\n");
89-
isOk = 0;
88+
isOk = false;
9089
}
91-
90+
9291
if (!isOk) {
9392
printf("Failed to send metric: bad parameters.\n\n\n");
9493
print_usage();
@@ -98,7 +97,7 @@ int main(int argc, char** argv)
9897
// conversions
9998
int monitoringValueI = atoi(monitoringValue);
10099

101-
// disable logs from monitoring lib
100+
// disable logs from monitoring lib
102101
setenv("O2_INFOLOGGER_MODE", "none", 1);
103102

104103
if (verbose) {
@@ -109,19 +108,17 @@ int main(int argc, char** argv)
109108
printf("\n");
110109
}
111110

112-
isOk = 0;
111+
isOk = false;
113112
try {
114113
monitoringCollector = MonitoringFactory::Get(monitoringURI);
115-
monitoringCollector->send({ monitoringValueI, monitoringMetric });
116-
isOk = 1;
117-
}
118-
catch (const std::exception &exc) {
114+
monitoringCollector->send({monitoringValueI, monitoringMetric});
115+
isOk = true;
116+
} catch (const std::exception& exc) {
119117
printf("Exception: %s\n", exc.what());
120-
}
121-
catch (...) {
118+
} catch (...) {
122119
printf("Undefined exception\n");
123120
}
124-
121+
125122
if (!isOk) {
126123
printf("Failed to send metric\n");
127124
return -1;
@@ -132,4 +129,3 @@ int main(int argc, char** argv)
132129
}
133130
return 0;
134131
}
135-

0 commit comments

Comments
 (0)