Commit a248a46c authored by yannick legoc's avatar yannick legoc
Browse files

implemented enable/disable of dielectrics controllers

parent 21a47432
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
*/ */
#include "DielectricsRemoteMatlabReq.h" #include "DielectricsRemoteMatlabReq.h"
#include "Spectrums.h"
#include <InstrumentManager/InstrumentManager.h> #include <InstrumentManager/InstrumentManager.h>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <fstream> #include <fstream>
...@@ -93,27 +93,50 @@ RemoteMatlabReq::RemoteMatlabReq(const RemoteMatlabReq& controller) : ...@@ -93,27 +93,50 @@ RemoteMatlabReq::RemoteMatlabReq(const RemoteMatlabReq& controller) :
} }
RemoteMatlabReq::~RemoteMatlabReq() { RemoteMatlabReq::~RemoteMatlabReq() {
raz();
}
// Stop the subscriber void RemoteMatlabReq::postConfiguration() {
m_subscriber->cancel();
// The subscriber thread terminates if (m_server.get() == 0) {
m_subscriberThread->join(); // Create a new server if it is not already created.
if (serverEndpoint() == "") {
m_server.reset(new Server(application::This::getServer().getEndpoint()));
}
else {
m_server.reset(new Server(serverEndpoint()));
}
}
// Send a request to stop the remote application. // Do not initialise if the controller is disabled.
stopApplication(); if (isEnabled()) {
initialized = initApplication();
}
} }
void RemoteMatlabReq::postConfiguration() { void RemoteMatlabReq::setEnabled(bool all, bool postconf) {
ExperimentController::setEnabled(all);
// Enable the spectrums controller.
for (vector<Spectrums *>::const_iterator c = m_spectrumsControllers.begin(); c != m_spectrumsControllers.end(); ++c) {
(*c)->setEnabled(false, false);
}
}
void RemoteMatlabReq::setDisabled(bool all) {
if (serverEndpoint() == "") { raz();
m_server.reset(new Server(application::This::getServer().getEndpoint())); ExperimentController::setDisabled(all);
} else { // Disable the spectrums controller.
m_server.reset(new Server(serverEndpoint())); for (vector<Spectrums *>::const_iterator c = m_spectrumsControllers.begin(); c != m_spectrumsControllers.end(); ++c) {
(*c)->setDisabled(false);
} }
}
initialized = initApplication(); void RemoteMatlabReq::addSpectrumsController(Spectrums * controller) {
m_spectrumsControllers.push_back(controller);
} }
bool RemoteMatlabReq::initApplication() { bool RemoteMatlabReq::initApplication() {
...@@ -249,11 +272,21 @@ void RemoteMatlabReq::start() { ...@@ -249,11 +272,21 @@ void RemoteMatlabReq::start() {
void RemoteMatlabReq::raz() { void RemoteMatlabReq::raz() {
// First stop the application. // Reset if the controller was initialized.
stopApplication(); if (initialized()) {
// Stop the subscriber
m_subscriber->cancel();
// The subscriber thread terminates
m_subscriberThread->join();
// Restart the application. // First stop the application.
initialized = false; stopApplication();
// Restart the application.
initialized = false;
}
} }
void RemoteMatlabReq::test() { void RemoteMatlabReq::test() {
...@@ -276,6 +309,11 @@ void RemoteMatlabReq::stopApplication() { ...@@ -276,6 +309,11 @@ void RemoteMatlabReq::stopApplication() {
return; return;
} }
// Exit immediately if the server is not available.
if (!m_server->isAvailable(10000)) {
return;
}
// Serialize the request. // Serialize the request.
proto::RunSpectrumsRequest request; proto::RunSpectrumsRequest request;
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
namespace dielectrics { namespace dielectrics {
class Spectrums;
/*! /*!
* \brief Test command. * \brief Test command.
*/ */
...@@ -55,6 +57,11 @@ public: ...@@ -55,6 +57,11 @@ public:
virtual void postConfiguration(); virtual void postConfiguration();
virtual void setEnabled(bool all, bool postconf = true);
virtual void setDisabled(bool all = false);
void addSpectrumsController(Spectrums * controller);
virtual void start(); virtual void start();
virtual void raz(); virtual void raz();
virtual void test(); virtual void test();
...@@ -96,6 +103,8 @@ private: ...@@ -96,6 +103,8 @@ private:
static const std::string RESPONDER_NAME; static const std::string RESPONDER_NAME;
static const std::string PUBLISHER_NAME; static const std::string PUBLISHER_NAME;
std::vector<Spectrums *> m_spectrumsControllers;
std::auto_ptr<cameo::Server> m_server; std::auto_ptr<cameo::Server> m_server;
std::auto_ptr<cameo::application::Instance> m_matlabApplication; std::auto_ptr<cameo::application::Instance> m_matlabApplication;
std::auto_ptr<cameo::application::Requester> m_requester; std::auto_ptr<cameo::application::Requester> m_requester;
......
<module name="remotedielectrics"> <module name="remotedielectrics">
<controller class="dielectrics::RemoteMatlabReq"/> <controller class="dielectrics::RemoteMatlabReq"/>
<controller class="dielectrics::Spectrums"/>
<controller class="dielectrics::RunSpectrums"/> <controller class="dielectrics::RunSpectrums"/>
<controller class="dielectrics::RunSpectrumsTest"/> <controller class="dielectrics::RunSpectrumsTest"/>
<controller class="dielectrics::RunSpectrumsTime"/> <controller class="dielectrics::RunSpectrumsTime"/>
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
*/ */
#include "RunSpectrums.h" #include "RunSpectrums.h"
#include "controllers/common/family/Families.h"
namespace dielectrics { namespace dielectrics {
...@@ -28,9 +27,7 @@ using namespace cameo; ...@@ -28,9 +27,7 @@ using namespace cameo;
const std::string RunSpectrums::TYPE = "dielectrics_run_spectrums"; const std::string RunSpectrums::TYPE = "dielectrics_run_spectrums";
RunSpectrums::RunSpectrums(const std::string& name) : RunSpectrums::RunSpectrums(const std::string& name) :
ExperimentController(name), controller::Stoppable(this), controller::Raz(this) { Spectrums(name), controller::Stoppable(this), controller::Raz(this) {
setFamily(family::ACQUISITION);
fr.init(this, SAVE, "fr", "Freq"); fr.init(this, SAVE, "fr", "Freq");
frMin.init(this, SAVE | SPY, "frMin", "Freq Min"); frMin.init(this, SAVE | SPY, "frMin", "Freq Min");
...@@ -39,8 +36,6 @@ RunSpectrums::RunSpectrums(const std::string& name) : ...@@ -39,8 +36,6 @@ RunSpectrums::RunSpectrums(const std::string& name) :
time.init(this, SAVE, "actual_time", "wanted_time", "Time"); time.init(this, SAVE, "actual_time", "wanted_time", "Time");
comment.init(this, SAVE, "comment", "Comment"); comment.init(this, SAVE, "comment", "Comment");
actualRun.init(this, NOSAVE | SPY, "run", "Run"); actualRun.init(this, NOSAVE | SPY, "run", "Run");
matlabController.init(this, "matlab");
} }
RunSpectrums::~RunSpectrums() { RunSpectrums::~RunSpectrums() {
...@@ -48,6 +43,8 @@ RunSpectrums::~RunSpectrums() { ...@@ -48,6 +43,8 @@ RunSpectrums::~RunSpectrums() {
void RunSpectrums::postConfiguration() { void RunSpectrums::postConfiguration() {
Spectrums::postConfiguration();
registerUpdater(matlabController->applicationState, &RunSpectrums::updateApplicationState, this); registerUpdater(matlabController->applicationState, &RunSpectrums::updateApplicationState, this);
registerStatus(matlabController, &RunSpectrums::updateState, this); registerStatus(matlabController, &RunSpectrums::updateState, this);
......
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
#ifndef DIELECTRICS_RUNSPECTRUMS_H #ifndef DIELECTRICS_RUNSPECTRUMS_H
#define DIELECTRICS_RUNSPECTRUMS_H #define DIELECTRICS_RUNSPECTRUMS_H
#include "DielectricsRemoteMatlabReq.h" #include "Spectrums.h"
namespace dielectrics { namespace dielectrics {
class RunSpectrums : public ExperimentController, class RunSpectrums : public Spectrums,
public controller::Stoppable, public controller::Stoppable,
public controller::Raz { public controller::Raz {
...@@ -54,8 +54,6 @@ public: ...@@ -54,8 +54,6 @@ public:
Property<std::string> comment; Property<std::string> comment;
Property<int32> actualRun; Property<int32> actualRun;
ControllerPtr<RemoteMatlabReq> matlabController;
protected: protected:
void logRunNumbers(LogStream& logStream); void logRunNumbers(LogStream& logStream);
}; };
......
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "Spectrums.h"
#include "controllers/common/family/Families.h"
namespace dielectrics {
using namespace std;
using namespace common;
const std::string Spectrums::TYPE = "dielectrics_spectrums";
Spectrums::Spectrums(const std::string& name) :
ExperimentController(name) {
setFamily(family::ACQUISITION);
matlabController.init(this, "matlab");
}
Spectrums::~Spectrums() {
}
void Spectrums::postConfiguration() {
matlabController->addSpectrumsController(this);
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef DIELECTRICS_SPECTRUMS_H
#define DIELECTRICS_SPECTRUMS_H
#include "DielectricsRemoteMatlabReq.h"
namespace dielectrics {
class Spectrums : public ExperimentController {
public:
//! Type of controller
static const std::string TYPE;
Spectrums(const std::string& name);
virtual ~Spectrums();
virtual void postConfiguration();
ControllerPtr<RemoteMatlabReq> matlabController;
};
}
#endif
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
*/ */
#include "StopRunSpectrums.h" #include "StopRunSpectrums.h"
#include "controllers/common/family/Families.h"
namespace dielectrics { namespace dielectrics {
...@@ -27,11 +26,7 @@ using namespace common; ...@@ -27,11 +26,7 @@ using namespace common;
const std::string StopRunSpectrums::TYPE = "dielectrics_run_spectrums_stop"; const std::string StopRunSpectrums::TYPE = "dielectrics_run_spectrums_stop";
StopRunSpectrums::StopRunSpectrums(const std::string& name) : StopRunSpectrums::StopRunSpectrums(const std::string& name) :
ExperimentController(name), controller::Start(this) { Spectrums(name), controller::Start(this) {
setFamily(family::ACQUISITION);
matlabController.init(this, "matlab");
} }
StopRunSpectrums::~StopRunSpectrums() { StopRunSpectrums::~StopRunSpectrums() {
...@@ -39,6 +34,7 @@ StopRunSpectrums::~StopRunSpectrums() { ...@@ -39,6 +34,7 @@ StopRunSpectrums::~StopRunSpectrums() {
void StopRunSpectrums::postConfiguration() { void StopRunSpectrums::postConfiguration() {
Spectrums::postConfiguration();
} }
void StopRunSpectrums::start() { void StopRunSpectrums::start() {
......
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
#ifndef DIELECTRICS_STOPRUNSPECTRUMS_H #ifndef DIELECTRICS_STOPRUNSPECTRUMS_H
#define DIELECTRICS_STOPRUNSPECTRUMS_H #define DIELECTRICS_STOPRUNSPECTRUMS_H
#include "DielectricsRemoteMatlabReq.h" #include "Spectrums.h"
namespace dielectrics { namespace dielectrics {
class StopRunSpectrums : public ExperimentController, class StopRunSpectrums : public Spectrums,
public controller::Start { public controller::Start {
public: public:
...@@ -36,8 +36,6 @@ public: ...@@ -36,8 +36,6 @@ public:
virtual void postConfiguration(); virtual void postConfiguration();
virtual void start(); virtual void start();
ControllerPtr<RemoteMatlabReq> matlabController;
}; };
} }
......
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