eis/TestProject/CronTab/CronTab_icei.cc

110 lines
4.2 KiB
C++
Raw Normal View History

#include <TestProject/CronTab/CronTab_icei.h>
#include <TestProject/CronTab/cron_timer.h>
#include <common/L2Event.h>
#include <dao/DbStandardDBAX.h>
#include <mix_cc/utility/read_config.h>
#include <string>
#include <thread>
std::atomic_bool _shutDown;
CronTabICEI::CronTabICEI() {
this->logger_ = std::make_unique<LOG>("CronTab_icei");
// auto cronTab_config_maybe = mix_cc::read_config_maybe("utility", "CronTab");
// if (cronTab_config_maybe.is_nothing()) {
// logger_->Error() << "配置读取失败" << endl;
// _shutDown = true;
// }
// auto cronTab_config = cronTab_config_maybe.unsafe_get_just();
// vector<std::string> proxy_vec =
// cronTab_config.at("proxy").get<vector<std::string>>();
// vector<std::string> exp_vec =
// cronTab_config.at("exp").get<vector<std::string>>();
// vector<int> eventno_vec = cronTab_config.at("eventno").get<vector<int>>();
// int p_size = proxy_vec.size();
// int e_size = exp_vec.size();
// int ev_size = eventno_vec.size();
// if (p_size != e_size || p_size == 0 || ev_size == 0 || ev_size != p_size) {
// logger_->Error() << "配置为空 或配置不匹配,proxy size:" << p_size
// << ",exp size:" << e_size << endl;
// _shutDown = true;
// }
// for (int i = 0; i < p_size; i++) {
// logger_->Debug() << "proxy:" << proxy_vec[i];
// vec_prox_.push_back(ProxyMag::GetAppICEPrx(proxy_vec[i]));
// }
// ::Ice::ByteSeq seq;
// cron_timer::TimerMgr mgr;
// for (int i = 0; i < p_size; i++) {
// // mgr.AddTimer(exp_vec[i], [&,i](void) {
// // this->logger_->Debug() << "Test--1--" << i << endl;
// // });
// mgr.AddTimer(exp_vec[i], [&, i, &seq, &proxy_vec, &exp_vec](void) {
// // every second
// // this->logger_->Debug() << "1 second cron timer hit--1" << endl;
// try {
// vec_prox_[i]->TimeNotify(eventno_vec[i], seq);
// this->logger_->Info() << "proxy:" << proxy_vec[i]
// << ",exp:" << exp_vec[i] << ",is OK!" << endl;
// } catch (const std::exception& e) {
// this->logger_->Error()
// << "proxy:" << proxy_vec[i] << ",exp:" << exp_vec[i]
// << ",ERROR:" << e.what() << endl;
// }
// // vec_prox_[0]->SendDataShort(1, seq, seq.size());
// // this->logger_->Debug() << "1 second cron timer hit--2" << endl;
// });
// }
// while (!_shutDown) {
// auto nearest_timer = (std::min)(
// std::chrono::system_clock::now() + std::chrono::milliseconds(500),
// mgr.GetNearestTime());
// std::this_thread::sleep_until(nearest_timer);
// mgr.Update();
// }
}
CronTabICEI::~CronTabICEI() {
_shutDown = true;
logger_->Debug() << "CronTabICEI::~CronTabICEI()" << endl;
}
void baosight::CronTabICEI::SendDataShort(::Ice::Int eventNo,
const ::Ice::ByteSeq& seq,
::Ice::Int length,
const Ice::Current& current) {
// string data(seq.begin(), seq.end());
logger_->Info() << "CronTabICEI::SendDataShort:" << endl;
// if (eventNo == 12) {
// logger_->Debug() << "Test:" << eventNo << ",size:" << seq.size() << endl;
// }
// send2pyml_->SendDataShort(eventNo, seq, length);
// logger_->Info() << "CronTabICEI::SendDataShort 结束!" << endl;
}
void baosight::CronTabICEI::SendDataLong(
::Ice::Int eventNo, const ::Ice::ByteSeq& seq, ::Ice::Int length,
const ::std::string& sender, const ::std::string& receiver,
const ::std::string& additional, const Ice::Current& current) {}
void baosight::CronTabICEI::TimeNotify(::Ice::Int eventNo,
const ::Ice::ByteSeq& seq,
const Ice::Current& current) {
// logger_->Debug() << "CronTab" << endl;
// string proxyName = "baosight/ptest1";
// string keyValue = "CronTab 2 baosight/ptest1!";
// int length = keyValue.size();
// ::Ice::ByteSeq sendData((unsigned char*)keyValue.c_str(),
// (unsigned char*)keyValue.c_str() + length);
// ProxyMag::GetAppICEPrx(proxyName)->SendDataShort(eventNo, sendData,
// sendData.size());
logger_->Debug() << "Test!" << eventNo << endl;
}