Commit 65d5beb5 authored by yannick legoc's avatar yannick legoc
Browse files

Improved Dielectrics controllers with logs, application restart

parent 50f23b3e
......@@ -24,7 +24,7 @@
#include <iostream>
#include <common/base/ServerProperties.h>
#include "controllers/common/family/Families.h"
#include "../remotedielectrics/FrequencyRequestMessages.pb.h"
#include "FrequencyRequestMessages.pb.h"
namespace dielectrics {
......@@ -46,8 +46,11 @@ const std::string RemoteMatlabReq::RUN_SINGLE_FREQUENCY = "Run Single Frequency"
RemoteMatlabReq::RemoteMatlabReq(const std::string& name) :
ExperimentController(name), controller::Start(this), controller::Raz(this) {
setFamily(family::ACQUISITION);
serverEndpoint.init(this, SAVE, "cameo_server");
initialized.init(this, NOSAVE, "initialized");
applicationState.init(this, NOSAVE, "matlab_state");
requestTypeValues.init(this, NOSAVE, "request_type_values");
......@@ -108,7 +111,6 @@ bool RemoteMatlabReq::initApplication() {
}
try {
// Start the Matlab server
if (!m_server->isAvailable(10000)) {
cout << "Matlab server is not available" << endl;
......@@ -118,6 +120,9 @@ bool RemoteMatlabReq::initApplication() {
cout << "Matlab server is connected to " << getName() << endl;
m_matlabApplication = m_server->connect(MATLAB_APPLICATION);
cout << "connected application" << endl;
if (m_matlabApplication->exists()) {
// The application exists from a previous server session
m_matlabApplication->stop();
......@@ -132,7 +137,12 @@ bool RemoteMatlabReq::initApplication() {
return false;
}
// Create the requester.
applicationState = m_matlabApplication->waitFor(application::STARTING);
// First delete the requester if it exists.
m_requester.reset(0);
// Create a new requester.
m_requester = application::Requester::create(*m_matlabApplication, RESPONDER_NAME);
if (m_requester.get() == 0) {
......@@ -143,6 +153,8 @@ bool RemoteMatlabReq::initApplication() {
// Application initialized.
initialized = true;
applicationState = m_matlabApplication->waitFor(application::RUNNING);
cout << "Matlab application initialized" << endl;
return true;
......@@ -157,7 +169,11 @@ bool RemoteMatlabReq::initApplication() {
void RemoteMatlabReq::start() {
initApplication();
if (!initApplication()) {
return;
}
commandStatus.setRunning();
// Serialize the request.
proto::RunSpectrumsRequest request;
......@@ -198,6 +214,8 @@ void RemoteMatlabReq::start() {
cout << "received response " << response.responseid() << endl;
sleep(1);
commandStatus.setIdle();
}
void RemoteMatlabReq::raz() {
......@@ -253,9 +271,9 @@ void RemoteMatlabReq::stopApplication() {
m_matlabApplication->stop();
// Wait for the termination
application::State state = m_matlabApplication->waitFor();
applicationState = m_matlabApplication->waitFor();
cout << "Matlab application terminated with state " << application::toString(state) << endl;
cout << "Matlab application terminated with state " << application::toString(applicationState()) << endl;
}
}
......@@ -58,6 +58,10 @@ public:
Property<double> time;
Property<std::string> comment;
Property<std::string> serverEndpoint;
Property<bool> initialized;
Property<int32> applicationState;
private:
bool initApplication();
void stopApplication();
......@@ -66,9 +70,6 @@ private:
static const std::string MATLAB_STOP_APPLICATION;
static const std::string RESPONDER_NAME;
Property<std::string> serverEndpoint;
Property<bool> initialized;
std::auto_ptr<cameo::Server> m_server;
std::auto_ptr<cameo::application::Instance> m_matlabApplication;
std::auto_ptr<cameo::application::Requester> m_requester;
......
......@@ -16,8 +16,7 @@
* limitations under the Licence.
*/
#include "../remotedielectrics/RunSingleFrequency.h"
#include "RunSingleFrequency.h"
#include "controllers/common/family/Families.h"
namespace dielectrics {
......@@ -42,6 +41,8 @@ void RunSingleFrequency::start() {
matlabController->comment = comment();
matlabController->startCommand();
log(Level::s_Info) << "Freq " << fr << " Time " << time << " Comment " << comment << endlog;
}
}
......@@ -19,9 +19,7 @@
#ifndef DIELECTRICS_RUNSINGLEFREQUENCY_H
#define DIELECTRICS_RUNSINGLEFREQUENCY_H
#include <Controller.h>
#include "../remotedielectrics/RunSpectrums.h"
#include "RunSpectrums.h"
namespace dielectrics {
......
......@@ -16,14 +16,14 @@
* limitations under the Licence.
*/
#include "../remotedielectrics/RunSpectrums.h"
#include "RunSpectrums.h"
#include "controllers/common/family/Families.h"
namespace dielectrics {
using namespace std;
using namespace common;
using namespace cameo;
const std::string RunSpectrums::TYPE = "dielectrics_run_spectrums";
......@@ -32,12 +32,12 @@ RunSpectrums::RunSpectrums(const std::string& name) :
setFamily(family::ACQUISITION);
fr.init(this, NOSAVE, "fr");
frMin.init(this, NOSAVE, "frMin");
frMax.init(this, NOSAVE, "frMax");
nMax.init(this, NOSAVE, "nMax");
time.init(this, NOSAVE, "time");
comment.init(this, NOSAVE, "comment");
fr.init(this, NOSAVE | SPY, "fr", "Freq");
frMin.init(this, NOSAVE, "frMin", "Freq Min");
frMax.init(this, NOSAVE, "frMax", "Freq Max");
nMax.init(this, NOSAVE, "nMax", "N Max");
time.init(this, NOSAVE, "time", "Time");
comment.init(this, NOSAVE, "comment", "Comment");
matlabController.init(this, "matlab");
}
......@@ -47,6 +47,35 @@ RunSpectrums::~RunSpectrums() {
void RunSpectrums::postConfiguration() {
registerUpdater(matlabController->applicationState, &RunSpectrums::updateApplicationState, this);
registerStatus(matlabController, &RunSpectrums::updateState, this);
updateApplicationState();
}
void RunSpectrums::updateApplicationState() {
int32 state = matlabController->applicationState();
if (state == application::STARTING) {
commandStatus.setWarning();
}
else if (state == application::RUNNING) {
commandStatus.setIdle();
}
else {
commandStatus.setError();
}
}
void RunSpectrums::updateState() {
if (matlabController->commandStatus.isRunning()) {
commandStatus.setRunning();
}
else {
commandStatus.setIdle();
}
}
void RunSpectrums::start() {
......@@ -58,6 +87,8 @@ void RunSpectrums::start() {
matlabController->comment = comment();
matlabController->startCommand();
log(Level::s_Info) << "Freq min " << frMin << " Freq Max " << frMax << " N Max " << nMax << " Comment " << comment << endlog;
}
void RunSpectrums::stop() {
......@@ -66,6 +97,8 @@ void RunSpectrums::stop() {
void RunSpectrums::raz() {
matlabController->razCommand();
log(Level::s_Info) << "Stopped remote application" << endlog;
}
}
......@@ -19,8 +19,6 @@
#ifndef DIELECTRICS_RUNSPECTRUMS_H
#define DIELECTRICS_RUNSPECTRUMS_H
#include <Controller.h>
#include "DielectricsRemoteMatlabReq.h"
namespace dielectrics {
......@@ -42,6 +40,9 @@ public:
virtual void stop();
virtual void raz();
void updateApplicationState();
void updateState();
Property<double> fr;
Property<double> frMin;
Property<double> frMax;
......
......@@ -16,8 +16,7 @@
* limitations under the Licence.
*/
#include "../remotedielectrics/RunSpectrumsTest.h"
#include "RunSpectrumsTest.h"
#include "controllers/common/family/Families.h"
namespace dielectrics {
......@@ -48,6 +47,8 @@ void RunSpectrumsTest::start() {
matlabController->comment = comment();
matlabController->startCommand();
log(Level::s_Info) << "Freq min " << frMin << " Freq Max " << frMax << " N Max " << nMax << " Comment " << comment << endlog;
}
}
......@@ -19,9 +19,7 @@
#ifndef DIELECTRICS_RUNSPECTRUMSTEST_H
#define DIELECTRICS_RUNSPECTRUMSTEST_H
#include "../remotedielectrics/RunSpectrums.h"
#include <Controller.h>
#include "RunSpectrums.h"
namespace dielectrics {
......
......@@ -16,8 +16,7 @@
* limitations under the Licence.
*/
#include "../remotedielectrics/RunSpectrumsTime.h"
#include "RunSpectrumsTime.h"
#include "controllers/common/family/Families.h"
namespace dielectrics {
......@@ -43,6 +42,8 @@ void RunSpectrumsTime::start() {
matlabController->comment = comment();
matlabController->startCommand();
log(Level::s_Info) << "Freq min " << frMin << " Freq Max " << frMax << " Time " << time << " Comment " << comment << endlog;
}
}
......@@ -19,9 +19,7 @@
#ifndef DIELECTRICS_RUNSPECTRUMSTIME_H
#define DIELECTRICS_RUNSPECTRUMSTIME_H
#include <Controller.h>
#include "../remotedielectrics/RunSpectrums.h"
#include "RunSpectrums.h"
namespace dielectrics {
......
......@@ -16,7 +16,7 @@
* limitations under the Licence.
*/
#include "../remotedielectrics/StopRunSpectrums.h"
#include "StopRunSpectrums.h"
#include "controllers/common/family/Families.h"
namespace dielectrics {
......@@ -44,6 +44,8 @@ void StopRunSpectrums::postConfiguration() {
void StopRunSpectrums::start() {
matlabController->stopRun();
log(Level::s_Info) << "Stopped run" << endlog;
}
}
......@@ -19,8 +19,6 @@
#ifndef DIELECTRICS_STOPRUNSPECTRUMS_H
#define DIELECTRICS_STOPRUNSPECTRUMS_H
#include <Controller.h>
#include "DielectricsRemoteMatlabReq.h"
namespace dielectrics {
......
dielectrics_remote_matlab.razPrefix=Stop application
dielectrics_remote_matlab.remote_application=Remote application
dielectrics_remote_matlab.serverPrefix=Server endpoint
\ No newline at end of file
<controller_plugin_config type="dielectrics_remote_matlab">
<image key="FREQGEN_CTRL"/>
<settings view="dielectrics_remote_matlabView.xml"/>
</controller_plugin_config>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<controller type="dielectrics_remote_matlab">
<property name="cameo_server" type="string" max_length="30">
</property>
</controller>
<plugin>
<controller type="dielectrics_remote_matlab" role="dielectrics_remote_matlab1"/>
<simple_label prefix="dielectrics_remote_matlab.serverPrefix" font_size="9" hAlignment="left"/>
<text role="dielectrics_remote_matlab1" property="cameo_server"/>
<button role="dielectrics_remote_matlab1" command="raz" prefix="dielectrics_remote_matlab.razPrefix"/>
</plugin>
dielectrics_run_single_frequency.parameters=Parameters
dielectrics_run_single_frequency.frPrefix=Freq.
dielectrics_run_single_frequency.timePrefix=Time
dielectrics_run_single_frequency.commentPrefix=Comment
dielectrics_run_single_frequency.razPrefix=Stop application
\ No newline at end of file
dielectrics_run_single_frequency.razPrefix=Stop application
dielectrics_run_single_frequency.remote_application=Remote application
dielectrics_run_single_frequency.serverPrefix=Server endpoint
\ No newline at end of file
......@@ -12,8 +12,4 @@
<simple_label prefix="dielectrics_run_single_frequency.commentPrefix" font_size="9" hAlignment="left"/>
<text role="dielectrics_run_single_frequency1" property="comment"/>
<newLine/>
<button role="dielectrics_run_single_frequency1" command="raz" prefix="dielectrics_run_single_frequency.razPrefix"/>
</plugin>
dielectrics_run_spectrums.parameters=Parameters
dielectrics_run_spectrums.frMinPrefix=Freq. Min
dielectrics_run_spectrums.frMaxPrefix=Freq. Max
dielectrics_run_spectrums.nMaxPrefix=N Max
dielectrics_run_spectrums.commentPrefix=Comment
dielectrics_run_spectrums.razPrefix=Stop application
\ No newline at end of file
dielectrics_run_spectrums.razPrefix=Stop application
dielectrics_run_spectrums.remote_application=Remote application
dielectrics_run_spectrums.serverPrefix=Server endpoint
\ No newline at end of file
......@@ -15,8 +15,4 @@
<simple_label prefix="dielectrics_run_spectrums.commentPrefix" font_size="9" hAlignment="left"/>
<text role="dielectrics_run_spectrums1" property="comment"/>
<newLine/>
<button role="dielectrics_run_spectrums1" command="raz" prefix="dielectrics_run_spectrums.razPrefix"/>
</plugin>
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