49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
// Copyright (2019-2023) Paul Scherrer Institute
|
|
|
|
#include <fstream>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include "../common/Logger.h"
|
|
#include "../common/NetworkAddressConvert.h"
|
|
|
|
#include "JFJochBroker.h"
|
|
#include "../grpc/gRPCServer_Template.h"
|
|
|
|
#include "JFJochBrokerParser.h"
|
|
|
|
int main (int argc, char **argv) {
|
|
if (argc > 3) {
|
|
std::cout << "Usage ./jfjoch_broker {<JSON config> {<TCP gRPC port>}}" << std::endl;
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
uint16_t grpc_port = 5232;
|
|
if (argc >= 3) grpc_port = atoi(argv[2]);
|
|
|
|
Logger logger("jfjoch_broker");
|
|
|
|
nlohmann::json input;
|
|
if (argc > 1) {
|
|
std::ifstream file(argv[1]);
|
|
try {
|
|
input = nlohmann::json::parse(file);
|
|
} catch (const nlohmann::json::exception &e) {
|
|
logger.Error("JSON Parsing exception: " + std::string(e.what()));
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
DiffractionExperiment experiment;
|
|
experiment.MaskChipEdges(true).MaskModuleEdges(true);
|
|
ParseFacilityConfiguration(input, "cfg", experiment);
|
|
|
|
JFJochBroker broker(experiment);
|
|
ParseBrokerConfiguration(input, "services", broker);
|
|
ParseDetectorSetup(input, "detectors", broker);
|
|
|
|
std::string grpc_addr = "0.0.0.0:" + std::to_string(grpc_port);
|
|
|
|
auto server = gRPCServer(grpc_addr, broker);
|
|
logger.Info("gRPC configuration listening on address " + grpc_addr);
|
|
server->Wait();
|
|
} |