Commit d48d9064 authored by Locatelli's avatar Locatelli
Browse files

Use cameo publisher for setting plot window on front

Remove usr1_signal
parent ad085027
......@@ -126,6 +126,16 @@ int main(int32 argc, char* argv[]) {
}
}
std::shared_ptr<cameo::application::Publisher> frontpublisher;
// Create the publisher.
frontpublisher = application::Publisher::create("front_publisher");
DBGMSG("Created frontpublisher " << *frontpublisher);
if (frontpublisher.get() == 0) {
// TODO Error
cout << "spypublisher error" << endl;
return EXIT_FAILURE;
}
// Manage application signal
// signal(SIGABRT, crash_handler);
signal(SIGHUP, crash_handler);
......@@ -143,7 +153,7 @@ int main(int32 argc, char* argv[]) {
thread serverLogSubscriberThread(bind(&OffScreenPlotManager::loop, OffScreenPlotManager::getInstance(), logsubscriber));
// Start thread waiting and managing nomad gui request
thread plotRequestThread(bind(&manager::RequestDealerManager::loop, manager::RequestDealerManager::getInstance(), requesterplot));
thread plotRequestThread(bind(&manager::RequestDealerManager::loop, manager::RequestDealerManager::getInstance(), requesterplot, frontpublisher));
// Set cameo application running
application::This::setRunning();
......@@ -158,7 +168,7 @@ int main(int32 argc, char* argv[]) {
else {
// Start thread waiting and managing nomad gui request
thread plotRequestThread(bind(&manager::RequestDealerManager::loop, manager::RequestDealerManager::getInstance(), requesterplot));
thread plotRequestThread(bind(&manager::RequestDealerManager::loop, manager::RequestDealerManager::getInstance(), requesterplot, frontpublisher));
// Set cameo application running
application::This::setRunning();
......
......@@ -50,7 +50,8 @@ using namespace std;
using namespace cameo;
using namespace plot;
shared_ptr<application::Subscriber> datachangesubscriber; //! Subcriber on data change publisher of the server
shared_ptr<application::Subscriber> datachangesubscriber; //! Subscriber on data change publisher of the server
shared_ptr<application::Subscriber> frontsubscriber; //! Subscriber on front publisher of the ploty2 from nomadgui
shared_ptr<QApplication> app;
unique_ptr<window::PropertyPlotWindow> plotwindow;
......@@ -59,24 +60,40 @@ unique_ptr<window::PropertyPlotWindow> plotwindow;
* \param[in] sig the signal number which calling this method
*/
void crash_handler(int32 sig) {
// Cancel waiting message on data change subscriber connected to nomad server
// Cancel waiting message on data change subscriber connected to nomad server et ploty2
datachangesubscriber->cancel();
frontsubscriber->cancel();
app->closeAllWindows();
}
/*!
* \brief window in front
* \param[in] sig the signal number which calling this method
*/
void us1_signal(int32 sig) {
DBGMSG("receive us1_signal : " << sig);
if (plotwindow.get() != nullptr) {
plotwindow->activateWindow();
///*!
// * \brief window in front
// * \param[in] sig the signal number which calling this method
// */
//void us1_signal(int32 sig) {
// DBGMSG("receive us1_signal : " << sig);
// if (plotwindow.get() != nullptr) {
// plotwindow->activateWindow();
// }
//}
void frontThread(std::shared_ptr<cameo::application::Subscriber> responder, string key) {
string data;
while (true) {
// Wait for a new request.
responder->receive(data);
if (responder->isCanceled() == false) {
if (plotwindow.get() != nullptr) {
plotwindow->activateWindow();
}
}
else {
break;
}
}
}
/*!
* \brief main program function
* \return error code
......@@ -114,6 +131,15 @@ int32 main(int32 argc, char* argv[]) {
}
DBGMSG("Connected to " << *nomadserver);
// Get nomad server instance
unique_ptr<application::Instance> ploty2 = getPloty2Instance(server);
if (ploty2.get() == 0) {
Error("mainplot", "No ploty2 instance");
err = EXIT_FAILURE;
goto exit;
}
DBGMSG("Connected to " << *ploty2);
// create a subscriber connected on data change nomad server data_change_publisher
datachangesubscriber = application::Subscriber::create(*nomadserver, "data_change_publisher");
if (datachangesubscriber.get() == 0) {
......@@ -123,6 +149,15 @@ int32 main(int32 argc, char* argv[]) {
}
DBGMSG("Created requester " << *datachangesubscriber);
// create a subscriber connected on data change nomad server data_change_publisher
frontsubscriber = application::Subscriber::create(*ploty2, "front_publisher");
if (frontsubscriber.get() == 0) {
Error("mainplot", "Connection problem on front_publisher");
err = EXIT_FAILURE;
goto exit;
}
DBGMSG("Created requester " << *frontsubscriber);
// create a requester on the nomad server database
shared_ptr<application::Requester> requesterdb = application::Requester::create(*nomadserver, "database");
if (requesterdb.get() == 0) {
......@@ -147,7 +182,7 @@ int32 main(int32 argc, char* argv[]) {
// signal(SIGSEGV, crash_handler);
signal(SIGPIPE, crash_handler);
signal(SIGINT, crash_handler);
signal(SIGUSR1, us1_signal);
// signal(SIGUSR1, us1_signal);
// Init the nomad server requester manager
manager::ServerRequesterManager::getInstance()->init(requesterdb);
......@@ -193,6 +228,9 @@ int32 main(int32 argc, char* argv[]) {
DBGMSG("plotMessage.datay_ids_size() = " << plotMessage.datay_ids_size());
DBGMSG("plotMessage.dataz_ids_size() = " << plotMessage.dataz_ids_size());
// Start thread waiting and managing nomad gui request
thread frontRequestThread(frontThread, frontsubscriber, plotMessage.plotkey());
plotwindow = make_unique<window::PropertyPlotWindow>(PlotId::id++, mpl, plotMessage);
try {
plotwindow->create(*app, datachangesubscriber);
......@@ -216,8 +254,9 @@ int32 main(int32 argc, char* argv[]) {
err = EXIT_FAILURE;
}
// Cancel subscriber
// Cancel subscribers
datachangesubscriber->cancel();
frontsubscriber->cancel();
// Clean manager
manager::ServerRequesterManager::resetInstance();
......@@ -237,6 +276,7 @@ exit:
app->quit();
app.reset();
datachangesubscriber.reset();
frontsubscriber.reset();
mpl.reset();
// Terminate cameo application
......
......@@ -97,7 +97,7 @@ void PlotManager::reset() {
/*
* reset
*/
void PlotManager::restore() {
void PlotManager::restore(std::shared_ptr<cameo::application::Publisher> frontpublisher) {
ostringstream filename;
filename << getenv("HOME") << CONFIG_PATH << CONFIG_NAME;
ifstream file(filename.str().c_str());
......@@ -132,7 +132,7 @@ void PlotManager::restore() {
plotMessage.ParseFromString(part2.str());
// Display plot
displayPropertyPlot(message, plotMessage);
displayPropertyPlot(message, plotMessage, frontpublisher);
}
}
}
......@@ -152,7 +152,7 @@ PlotManager * PlotManager::getInstance() {
/*
* displayPlot
*/
void PlotManager::displayPropertyPlot(const ploty::Message& message, const ploty::PlotPropertyDataMessage& plotMessage) {
void PlotManager::displayPropertyPlot(const ploty::Message& message, const ploty::PlotPropertyDataMessage& plotMessage, std::shared_ptr<cameo::application::Publisher> frontpublisher) {
unique_lock<recursive_mutex> lock(m_PlotsMutex);
///////////////////////////////////////////////////////////////////////////////////////
//// Check if this plot key is already open or was closed
......@@ -238,13 +238,14 @@ void PlotManager::displayPropertyPlot(const ploty::Message& message, const ploty
///////////////////////////////////////////////////////////////////////////////////////
//// bring to front the plot
////
//TODO show in front
// Send signal USR1 to process pid , waiting for the new version of cameo cpp api
for(auto info : application::This::getServer().getApplicationInfos()) {
if (info.getId() == m_PlotsProcesses[plotMessage.plotkey()]->getId()) {
kill(info.getPid(), SIGUSR1);
}
}
string data = plotMessage.plotkey();
frontpublisher->sendBinary(data);
// // Send signal USR1 to process pid , waiting for the new version of cameo cpp api
// for(auto info : application::This::getServer().getApplicationInfos()) {
// if (info.getId() == m_PlotsProcesses[plotMessage.plotkey()]->getId()) {
// kill(info.getPid(), SIGUSR1);
// }
// }
}
}
......
......@@ -51,7 +51,7 @@ public:
* \brief display a plot
* \param[in] plotRequest plot info
*/
void displayPropertyPlot(const ploty::Message& message, const ploty::PlotPropertyDataMessage& plotMessage);
void displayPropertyPlot(const ploty::Message& message, const ploty::PlotPropertyDataMessage& plotMessage, std::shared_ptr<cameo::application::Publisher> frontpublisher);
/*!
* \brief reset instance
......@@ -61,7 +61,7 @@ public:
/*!
* \brief restore plot as the previous instance
*/
void restore();
void restore(std::shared_ptr<cameo::application::Publisher> frontpublisher);
private:
......
......@@ -66,7 +66,7 @@ RequestDealerManager* RequestDealerManager::getInstance() {
/*
* loop
*/
void RequestDealerManager::loop(std::shared_ptr<cameo::application::Responder> responder) {
void RequestDealerManager::loop(std::shared_ptr<cameo::application::Responder> responder, std::shared_ptr<cameo::application::Publisher> frontpublisher) {
string data;
// Loop until cancel is done.
while (true) {
......@@ -83,7 +83,7 @@ void RequestDealerManager::loop(std::shared_ptr<cameo::application::Responder> r
string secondPart = request->getSecondBinaryPart();
ploty::PlotPropertyDataMessage dataMessage;
dataMessage.ParseFromString(secondPart);
PlotManager::getInstance()->displayPropertyPlot(message, dataMessage);
PlotManager::getInstance()->displayPropertyPlot(message, dataMessage, frontpublisher);
}
// Close plots message
else if (message.type() == ploty::Message::ClosePlots) {
......@@ -91,7 +91,7 @@ void RequestDealerManager::loop(std::shared_ptr<cameo::application::Responder> r
}
// Restore plots message
else if (message.type() == ploty::Message::RestorePlots) {
PlotManager::getInstance()->restore();
PlotManager::getInstance()->restore(frontpublisher);
}
else {
Error("RequestDealerManager", "loop", "Receive bad plot type request");
......
......@@ -50,7 +50,7 @@ public:
* \brief responder loop for nomad gui plot_requester
* \param[in] responder instance of the cameo responder
*/
void loop(std::shared_ptr<cameo::application::Responder> responder);
void loop(std::shared_ptr<cameo::application::Responder> responder, std::shared_ptr<cameo::application::Publisher> frontpublisher);
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment