eis/eqpalg/utility/proxy_py.cc

65 lines
2.2 KiB
C++
Raw Normal View History

#include <eqpalg/utility/proxy_py.h>
ProxPy::ProxPy() {
prox_py_ptrs_["glitch"] = ProxyMag::GetAppICEPrx("baosight/glitch");
logger_ = std::make_unique<LOG>("ProxyPy");
if (ruleid_CMemMap_ == nullptr) {
ruleid_CMemMap_ = std::make_unique<CMemMap<std::string, GlithData>>(
table_name, CMemMapMaxSize);
}
}
ProxPy::~ProxPy() {}
bool ProxPy::insert(std::string ruleid, std::array<double, 2000> datax,
int dataSize) {
try {
auto res = ruleid_CMemMap_->operator[](ruleid);
if (res == nullptr) {
logger_->Error() << "ruleid:" << ruleid
<< ",ruleid_CMemMap_->operator[](ruleid) return false!"
<< std::endl;
}
// else {
// logger_->Info() << "data size:" << (*res).data_szie << std::endl;
// }
GlithData now_data;
now_data.update(datax, dataSize);
// logger_->Debug() << "GlithData,size of:" << sizeof(GlithData)
// << ",data size:" << now_data.data_szie << std::endl;
// ruleid_CMemMap_->clear();
ruleid_CMemMap_->insert(ruleid, &now_data);
} catch (const std::exception &e) {
logger_->Error() << e.what() << std::endl;
return false;
}
return true;
}
bool ProxPy::send2py(std::string module_name, string content) {
try {
std::vector<unsigned char> seq((unsigned char *)content.c_str(),
(unsigned char *)content.c_str() +
content.length());
this->add_module(module_name);
prox_py_ptrs_[module_name]->SendDataShort(0, seq, content.length());
} catch (const std::exception &e) {
logger_->Error() << e.what() << std::endl;
return false;
}
return true;
}
void ProxPy::add_module(std::string module_name) {
try {
if (prox_py_ptrs_.find(module_name) != prox_py_ptrs_.end()) {
// logger_->Debug() << module_name << " 已存在" << std::endl;
return;
}
string pre_name = "baosight/";
prox_py_ptrs_[module_name] =
ProxyMag::GetAppICEPrx((pre_name + module_name).c_str());
logger_->Debug() << "新增module" << module_name << ""
<< pre_name + module_name << std::endl;
} catch (const std::exception &e) {
logger_->Error() << e.what() << std::endl;
}
}