99 lines
3.5 KiB
C++
99 lines
3.5 KiB
C++
//
|
|
// Created by xtkuang on 2025/5/6.
|
|
//
|
|
|
|
#include <unistd.h>
|
|
#include <limits.h>
|
|
#include <libgen.h>
|
|
#include <iostream>
|
|
#include <glog/logging.h>
|
|
#include "device_manager/include/device_manager.h"
|
|
#include "monitor_manager/include/monitor_manager.h"
|
|
#include "service/grpc/include/grpc_camera_service.h"
|
|
#include "service/grpc/include/grpc_system_service.h"
|
|
#include "service/grpc/include/grpc_speaker_service.h"
|
|
#include "service/grpc/include/grpc_microphone_service.h"
|
|
#include "service/grpc/include/grpc_dexhand_service.h"
|
|
#include "utils/base/include/logger.h"
|
|
#include "service/grpc/include/grpc_head_service.h"
|
|
#include "service/grpc/include/grpc_humanoid_robot_service.h"
|
|
#include "service/grpc/include/grpc_hlc_service.h"
|
|
#include "json/json.h"
|
|
#include <grpcpp/ext/proto_server_reflection_plugin.h>
|
|
void runServer(const XmlNode &cfg){
|
|
using namespace cmvr::device;
|
|
using namespace cmvr::service;
|
|
using namespace cmvr::monitor;
|
|
|
|
if (!cfg.hasChild("DeviceManager")){
|
|
LOG(ERROR) << "Device Manager node not found";
|
|
return;
|
|
}
|
|
try {
|
|
// 🔥 关键!启用反射
|
|
grpc::reflection::InitProtoReflectionServerBuilderPlugin();
|
|
auto dmgr_cfg = cfg.getChild("DeviceManager");
|
|
DeviceManager::getInstance(dmgr_cfg);
|
|
|
|
auto mmgr_cfg = cfg.getChild("MonitorManager");
|
|
MonitorManager::getInstance(mmgr_cfg);
|
|
|
|
auto grpc_cfg = cfg.getChild("gRPCServer");
|
|
string port = grpc_cfg.getAttrDefault("port", "50051");
|
|
|
|
std::string address("0.0.0.0:" + port);
|
|
auto camera_service = gRPCCameraServiceImpl();
|
|
auto system_service = gRPCSystemServiceImpl();
|
|
auto speaker_service = gRPCSpeakerServiceImpl();
|
|
auto microphone_service = gRPCMicroPhoneServiceImpl();
|
|
auto dexhand_service = gRPCDexHandServiceImpl();
|
|
auto biohand_service = gRPCMBioHeadServiceImpl();
|
|
auto humanoid_robot_service = gRPCHumanoidRobotServiceImpl();
|
|
auto hlc_service = gRPCHlcServiceImpl();
|
|
|
|
grpc::ServerBuilder builder;
|
|
builder.AddListeningPort(address, grpc::InsecureServerCredentials());
|
|
builder.RegisterService(&camera_service);
|
|
builder.RegisterService(&system_service);
|
|
builder.RegisterService(&speaker_service);
|
|
builder.RegisterService(µphone_service);
|
|
builder.RegisterService(&dexhand_service);
|
|
builder.RegisterService(&biohand_service);
|
|
builder.RegisterService(&humanoid_robot_service);
|
|
builder.RegisterService(&hlc_service);
|
|
|
|
// 🔥 关键!启用反射
|
|
//grpc::reflection::InitProtoReflectionServerBuilderPlugin();
|
|
const std::unique_ptr server(builder.BuildAndStart());
|
|
std::cout << "Server listening on " << address << std::endl;
|
|
server->Wait();
|
|
}
|
|
catch (std:: exception &e) {
|
|
LOG(FATAL) << e.what();
|
|
}
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
std::string config_path;
|
|
if(argc == 1) {
|
|
char exe_path[PATH_MAX] = {0};
|
|
ssize_t count = readlink("/proc/self/exe", exe_path, PATH_MAX);
|
|
if (count == -1) {
|
|
std::cerr << "Failed to read /proc/self/exe" << std::endl;
|
|
return 1;
|
|
}
|
|
std::string exe_dir = dirname(exe_path);
|
|
config_path = exe_dir + "/config/cabin_robot.xml";
|
|
std::cout << "Using default config path: " << config_path << std::endl;
|
|
}
|
|
else if (argc == 2){
|
|
config_path = argv[1];
|
|
}
|
|
|
|
const XmlNode config(config_path);
|
|
initLogger(config.getChild("Logger"));
|
|
runServer(config);
|
|
google::ShutdownGoogleLogging();
|
|
return 0;
|
|
}
|