#include #include #include #include #include #include #include #include #include #include "RTService.pb.h" #include "../include/RTSMonitoringTask.h" using namespace boost::interprocess; using namespace proto_messages; class RTServiceImpl : public RTService { private: /* data */ RTSMonitoringTask rtsMonTask; const std::string RTSCOMMANDQUEUE = "RTSSERVICECOMMANDQUEUE"; const int MAXMSGSIZE = 250; const int MAXMSGCOUNT = 25; // message_queue shared_ptr rtsMQ; private: public: virtual void createMonitoring(::google::protobuf::RpcController* /* controller_ */, const SCreateIn* request_, ::SResult* response_, ::google::protobuf::Closure* /* done_ */) { // print request and std::cout << "Received request RTService / CreateMonitoring : " << request_->id() << " and " << request_->name() << std::endl << std::endl; bool res = rtsMonTask.CreateMonitoring(request_->id(), request_->samplerate(), request_->sampleperiod(), request_->downtime(), request_->status()); // create response response_->set_result(res); } // we need all parameters like id, samplerate, sampletime, downtime, later: HW-channels with the configurations bool createMonitoring(std::string id, int samplerate, int sampleperiod, int downtime, std::string status) { //TODO ML: add this to the M4Core if (rtsMonTask.Init()) { return rtsMonTask.CreateMonitoring(id, samplerate, sampleperiod, downtime, status); } return false; } bool deleteMonitoring(std::string id) { //TODO ML: add this to the M4Core return true; } std::string getMonitoringState(std::string id) { //TODO ask the M4Core for the Monitpring Status return "Start"; } std::list getMonitoringStates() { //TODO ask the M4Core for the Monitpring Status std::list list; return list; } bool setMonitoringStatus(std::string id, std::string status) { //set the Status return true; } void Run() { BOOST_TRY{ //Erase previous message queue message_queue::remove(RTSCOMMANDQUEUE.c_str()); //Create a message_queue. message_queue rtsMQ (create_only //only create ,RTSCOMMANDQUEUE.c_str() //name ,MAXMSGCOUNT //max message number ,MAXMSGSIZE //max message size ); bool bCmdQueueRun = true; unsigned int priority; message_queue::size_type recvd_size; boost::property_tree::ptree pt; while (bCmdQueueRun) { char rtsCmdbuffer [MAXMSGSIZE]; //mq.receive(buffer, sizeof(buffer), recvd_size, pri); rtsMQ.receive(rtsCmdbuffer, sizeof(rtsCmdbuffer), recvd_size, priority); //read json and go to cmd execution boost::property_tree::read_json(rtsCmdbuffer,pt); } // //Send 100 numbers // for(int i = 0; i < 100; ++i){ // mq.send(&i, sizeof(i), 0); // } } BOOST_CATCH(interprocess_exception &ex){ std::cout << ex.what() << std::endl; message_queue::remove(RTSCOMMANDQUEUE.c_str()); } BOOST_CATCH_END } }; int main(int argc, char **argv) { // initialize eCAL API eCAL::Initialize(argc, argv, "RTService"); // create minimal service server eCAL::CServiceServer rtService("RTSMonService"); // create Math service server std::shared_ptr rt_service = std::make_shared(); eCAL::protobuf::CServiceServer math_server(rt_service); // idle while(eCAL::Ok()) { // sleep 100 ms std::this_thread::sleep_for(std::chrono::milliseconds(100)); } // finalize eCAL API eCAL::Finalize(); return 0; }