-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathASDP_Storage_Module.cpp
More file actions
99 lines (89 loc) · 3.54 KB
/
Copy pathASDP_Storage_Module.cpp
File metadata and controls
99 lines (89 loc) · 3.54 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
/*
* Copyright (C) 2024: Arizona Board of Regents on Behalf of the University of Arizona
*/
// This is a storage module that (optionally) listens for commands from a client and
// (optionally) acts as a Core_Module to other clients.
#include <cstdlib>
#include <iostream>
#include <chrono>
#include <string>
#include <vector>
#include <ASDP_Core_API.h>
#include <Storage_Module.h>
using namespace asdp;
static std::string VERSION = "3.12.0";
void Usage(const char* programName, int code)
{
std::cerr << "Usage: " << programName << " [--version] [--verbosity V]"
<< " NICNameIn NICNameOut StorageRoot [StorageRoot+]" << std::endl;
std::cerr << " --version: Print out the version number and exit" << std::endl;
std::cerr << " --verbosity V: Set the verbosity level to V (default 0)" << std::endl;
std::cerr << " NICNameIn: The IP address or DNS name of the NIC to listen on" << std::endl;
std::cerr << " NICNameOut: The IP address or DNS name of the NIC to broadcast on" << std::endl;
std::cerr << " StorageRoot: Root directory of the storage, which has a directory for each serial number" << std::endl;
std::cerr << " StorageRoot+: Additional storage root directories (optional), camera streams written round-robin" << std::endl;
std::exit(code);
}
int main(int argc, char** argv)
{
std::string NICNameIn, NICNameOut;
std::vector<std::string> StorageRoots;
size_t realParams = 0;
int verbosity = 0;
// Parse the command line arguments, with the first non-flag argument being the
// name of the IP address to broadcast on. There is a --serial flag to specify
// the serial number of the server, which defaults to 1.
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]) == "--version") {
std::cout << "Storage Module version: " << VERSION + "-" + BUILD_TYPE << " using Core API "
<< asdp::Core::GetVersion() << std::endl;
return 0;
} else if (std::string(argv[i]) == "--verbosity") {
if (i + 1 < argc) {
verbosity = std::stoi(argv[i + 1]);
++i;
} else {
std::cerr << "--verbosity flag requires an argument" << std::endl;
return 1;
}
} else if (argv[i][0] == '-' ) {
std::cerr << "Unknown flag: " << argv[i] << std::endl;
return 1;
} else switch (realParams++) {
case 0:
NICNameIn = argv[i];
break;
case 1:
NICNameOut = argv[i];
break;
case 2:
default:
StorageRoots.push_back(argv[i]);
break;
}
}
if (realParams< 3) {
Usage(argv[0], 2);
}
if (NICNameIn == NICNameOut) {
std::cerr << "NICNameIn and NICNameOut must be different" << std::endl;
return 2;
}
// Open a Storage Module, specifying the NIC to listen and broadcast on.
{
if (verbosity > 0) {
std::cout << "Opening storage module version " << VERSION << " listening on " << NICNameIn << " and broadcasting on " << NICNameOut << std::endl;
}
Storage_Module sModule(NICNameIn, NICNameOut, StorageRoots, verbosity);
if (sModule.GetConstructorStatus() != OKAY) {
std::cerr << "Failed to open module: " << ErrorMessage(sModule.GetConstructorStatus()) << std::endl;
return 3;
}
// Watch the module. Print an error message if it fails.
do {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
} while (sModule.GetCurrentStatus() == OKAY);
std::cerr << "Module failed: " << ErrorMessage(sModule.GetCurrentStatus()) << std::endl;
}
return 4;
}