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

Implemented new features: spy, rsync

parent 5de2e283
......@@ -37,6 +37,7 @@ const std::string RemoteMatlabReq::TYPE = "dielectrics_remote_matlab";
const std::string RemoteMatlabReq::MATLAB_APPLICATION = "dielectrics-matlab";
const std::string RemoteMatlabReq::MATLAB_STOP_APPLICATION = "dielectrics-matlab-stop";
const std::string RemoteMatlabReq::RESPONDER_NAME = "dielectrics_controller";
const std::string RemoteMatlabReq::PUBLISHER_NAME = "dielectrics_pub";
const std::string RemoteMatlabReq::RUN_SPECTRUMS_TEST = "Run Spectrums Test";
const std::string RemoteMatlabReq::RUN_SPECTRUMS = "Run Spectrums";
......@@ -75,6 +76,10 @@ RemoteMatlabReq::RemoteMatlabReq(const std::string& name) :
time.init(this, NOSAVE, "time");
comment.init(this, NOSAVE, "comment");
actualN.init(this, NOSAVE, "N");
actualTime.init(this, NOSAVE, "actual_time");
actualRun.init(this, NOSAVE, "actual_run");
fr = 0;
frMin = 1E1;
frMax = 1E6;
......@@ -89,6 +94,12 @@ RemoteMatlabReq::RemoteMatlabReq(const RemoteMatlabReq& controller) :
RemoteMatlabReq::~RemoteMatlabReq() {
// Stop the subscriber
m_subscriber->cancel();
// The subscriber thread terminates
m_subscriberThread->join();
// Send a request to stop the remote application.
stopApplication();
}
......@@ -152,6 +163,12 @@ bool RemoteMatlabReq::initApplication() {
return false;
}
// Create a new subscriber.
m_subscriber = application::Subscriber::create(*m_matlabApplication, PUBLISHER_NAME);
// Start the subscriber loop
m_subscriberThread.reset(new thread(bind(&RemoteMatlabReq::subscriberLoop, this)));
// Application initialized.
initialized = true;
......@@ -213,7 +230,7 @@ void RemoteMatlabReq::start() {
proto::FrequencyResponse response;
response.ParseFromString(data);
cout << "received response " << response.responseid() << " values " << response.values_size() << endl;
cout << "received response " << response.responseid() << endl;
delete [] values.get();
int32* newArray = new int32[response.values_size()];
......@@ -243,7 +260,6 @@ void RemoteMatlabReq::stopRun() {
auto_ptr<cameo::application::Instance> matlabStopApplication = m_server->start(MATLAB_STOP_APPLICATION);
application::State state = matlabStopApplication->waitFor();
cout << "Matlab stop application terminated with state " << state << endl;
}
void RemoteMatlabReq::stopApplication() {
......@@ -288,4 +304,21 @@ void RemoteMatlabReq::stopApplication() {
cout << "Matlab application terminated with state " << application::toString(applicationState()) << endl;
}
void RemoteMatlabReq::subscriberLoop() {
// Loop on events
string data;
while (m_subscriber->receiveBinary(data)) {
// Parse the status.
proto::RunSpectrumsStatus status;
status.ParseFromString(data);
// No need to read the type.
actualN = status.n();
actualTime = status.time();
actualRun = status.run();
}
}
}
......@@ -64,17 +64,25 @@ public:
ArrayProperty<int32> values;
Property<int32> actualN;
Property<double> actualTime;
Property<int32> actualRun;
private:
bool initApplication();
void stopApplication();
void subscriberLoop();
static const std::string MATLAB_APPLICATION;
static const std::string MATLAB_STOP_APPLICATION;
static const std::string RESPONDER_NAME;
static const std::string PUBLISHER_NAME;
std::auto_ptr<cameo::Server> m_server;
std::auto_ptr<cameo::application::Instance> m_matlabApplication;
std::auto_ptr<cameo::application::Requester> m_requester;
std::auto_ptr<cameo::application::Subscriber> m_subscriber;
std::auto_ptr<boost::thread> m_subscriberThread;
};
}
......
......@@ -18,6 +18,7 @@ namespace proto {
void protobuf_ShutdownFile_FrequencyRequestMessages_2eproto() {
delete RunSpectrumsRequest::default_instance_;
delete FrequencyResponse::default_instance_;
delete RunSpectrumsStatus::default_instance_;
}
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
......@@ -34,8 +35,10 @@ void protobuf_AddDesc_FrequencyRequestMessages_2eproto() {
#endif
RunSpectrumsRequest::default_instance_ = new RunSpectrumsRequest();
FrequencyResponse::default_instance_ = new FrequencyResponse();
RunSpectrumsStatus::default_instance_ = new RunSpectrumsStatus();
RunSpectrumsRequest::default_instance_->InitAsDefaultInstance();
FrequencyResponse::default_instance_->InitAsDefaultInstance();
RunSpectrumsStatus::default_instance_->InitAsDefaultInstance();
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_FrequencyRequestMessages_2eproto);
}
......@@ -734,6 +737,402 @@ void FrequencyResponse::Swap(FrequencyResponse* other) {
}
// ===================================================================
bool RunSpectrumsStatus_Type_IsValid(int value) {
switch(value) {
case 1:
case 2:
case 3:
case 4:
return true;
default:
return false;
}
}
#ifndef _MSC_VER
const RunSpectrumsStatus_Type RunSpectrumsStatus::RUN;
const RunSpectrumsStatus_Type RunSpectrumsStatus::RUN_TIME;
const RunSpectrumsStatus_Type RunSpectrumsStatus::RUN_SINGLE;
const RunSpectrumsStatus_Type RunSpectrumsStatus::TEST;
const RunSpectrumsStatus_Type RunSpectrumsStatus::Type_MIN;
const RunSpectrumsStatus_Type RunSpectrumsStatus::Type_MAX;
const int RunSpectrumsStatus::Type_ARRAYSIZE;
#endif // _MSC_VER
#ifndef _MSC_VER
const int RunSpectrumsStatus::kTypeFieldNumber;
const int RunSpectrumsStatus::kFrMinFieldNumber;
const int RunSpectrumsStatus::kFrMaxFieldNumber;
const int RunSpectrumsStatus::kNFieldNumber;
const int RunSpectrumsStatus::kTimeFieldNumber;
const int RunSpectrumsStatus::kRunFieldNumber;
#endif // !_MSC_VER
RunSpectrumsStatus::RunSpectrumsStatus()
: ::google::protobuf::MessageLite() {
SharedCtor();
// @@protoc_insertion_point(constructor:proto.RunSpectrumsStatus)
}
void RunSpectrumsStatus::InitAsDefaultInstance() {
}
RunSpectrumsStatus::RunSpectrumsStatus(const RunSpectrumsStatus& from)
: ::google::protobuf::MessageLite() {
SharedCtor();
MergeFrom(from);
// @@protoc_insertion_point(copy_constructor:proto.RunSpectrumsStatus)
}
void RunSpectrumsStatus::SharedCtor() {
_cached_size_ = 0;
type_ = 1;
frmin_ = 0;
frmax_ = 0;
n_ = 0;
time_ = 0;
run_ = 0;
::memset(_has_bits_, 0, sizeof(_has_bits_));
}
RunSpectrumsStatus::~RunSpectrumsStatus() {
// @@protoc_insertion_point(destructor:proto.RunSpectrumsStatus)
SharedDtor();
}
void RunSpectrumsStatus::SharedDtor() {
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
if (this != &default_instance()) {
#else
if (this != default_instance_) {
#endif
}
}
void RunSpectrumsStatus::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const RunSpectrumsStatus& RunSpectrumsStatus::default_instance() {
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
protobuf_AddDesc_FrequencyRequestMessages_2eproto();
#else
if (default_instance_ == NULL) protobuf_AddDesc_FrequencyRequestMessages_2eproto();
#endif
return *default_instance_;
}
RunSpectrumsStatus* RunSpectrumsStatus::default_instance_ = NULL;
RunSpectrumsStatus* RunSpectrumsStatus::New() const {
return new RunSpectrumsStatus;
}
void RunSpectrumsStatus::Clear() {
#define OFFSET_OF_FIELD_(f) (reinterpret_cast<char*>( \
&reinterpret_cast<RunSpectrumsStatus*>(16)->f) - \
reinterpret_cast<char*>(16))
#define ZR_(first, last) do { \
size_t f = OFFSET_OF_FIELD_(first); \
size_t n = OFFSET_OF_FIELD_(last) - f + sizeof(last); \
::memset(&first, 0, n); \
} while (0)
if (_has_bits_[0 / 32] & 63) {
ZR_(n_, run_);
type_ = 1;
frmin_ = 0;
}
#undef OFFSET_OF_FIELD_
#undef ZR_
::memset(_has_bits_, 0, sizeof(_has_bits_));
mutable_unknown_fields()->clear();
}
bool RunSpectrumsStatus::MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input) {
#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure
::google::protobuf::uint32 tag;
::google::protobuf::io::StringOutputStream unknown_fields_string(
mutable_unknown_fields());
::google::protobuf::io::CodedOutputStream unknown_fields_stream(
&unknown_fields_string);
// @@protoc_insertion_point(parse_start:proto.RunSpectrumsStatus)
for (;;) {
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// required .proto.RunSpectrumsStatus.Type type = 1;
case 1: {
if (tag == 8) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
input, &value)));
if (::proto::RunSpectrumsStatus_Type_IsValid(value)) {
set_type(static_cast< ::proto::RunSpectrumsStatus_Type >(value));
} else {
unknown_fields_stream.WriteVarint32(tag);
unknown_fields_stream.WriteVarint32(value);
}
} else {
goto handle_unusual;
}
if (input->ExpectTag(17)) goto parse_frMin;
break;
}
// required double frMin = 2;
case 2: {
if (tag == 17) {
parse_frMin:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
double, ::google::protobuf::internal::WireFormatLite::TYPE_DOUBLE>(
input, &frmin_)));
set_has_frmin();
} else {
goto handle_unusual;
}
if (input->ExpectTag(25)) goto parse_frMax;
break;
}
// required double frMax = 3;
case 3: {
if (tag == 25) {
parse_frMax:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
double, ::google::protobuf::internal::WireFormatLite::TYPE_DOUBLE>(
input, &frmax_)));
set_has_frmax();
} else {
goto handle_unusual;
}
if (input->ExpectTag(32)) goto parse_n;
break;
}
// required int32 n = 4;
case 4: {
if (tag == 32) {
parse_n:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &n_)));
set_has_n();
} else {
goto handle_unusual;
}
if (input->ExpectTag(41)) goto parse_time;
break;
}
// required double time = 5;
case 5: {
if (tag == 41) {
parse_time:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
double, ::google::protobuf::internal::WireFormatLite::TYPE_DOUBLE>(
input, &time_)));
set_has_time();
} else {
goto handle_unusual;
}
if (input->ExpectTag(48)) goto parse_run;
break;
}
// required int32 run = 6;
case 6: {
if (tag == 48) {
parse_run:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &run_)));
set_has_run();
} else {
goto handle_unusual;
}
if (input->ExpectAtEnd()) goto success;
break;
}
default: {
handle_unusual:
if (tag == 0 ||
::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
goto success;
}
DO_(::google::protobuf::internal::WireFormatLite::SkipField(
input, tag, &unknown_fields_stream));
break;
}
}
}
success:
// @@protoc_insertion_point(parse_success:proto.RunSpectrumsStatus)
return true;
failure:
// @@protoc_insertion_point(parse_failure:proto.RunSpectrumsStatus)
return false;
#undef DO_
}
void RunSpectrumsStatus::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:proto.RunSpectrumsStatus)
// required .proto.RunSpectrumsStatus.Type type = 1;
if (has_type()) {
::google::protobuf::internal::WireFormatLite::WriteEnum(
1, this->type(), output);
}
// required double frMin = 2;
if (has_frmin()) {
::google::protobuf::internal::WireFormatLite::WriteDouble(2, this->frmin(), output);
}
// required double frMax = 3;
if (has_frmax()) {
::google::protobuf::internal::WireFormatLite::WriteDouble(3, this->frmax(), output);
}
// required int32 n = 4;
if (has_n()) {
::google::protobuf::internal::WireFormatLite::WriteInt32(4, this->n(), output);
}
// required double time = 5;
if (has_time()) {
::google::protobuf::internal::WireFormatLite::WriteDouble(5, this->time(), output);
}
// required int32 run = 6;
if (has_run()) {
::google::protobuf::internal::WireFormatLite::WriteInt32(6, this->run(), output);
}
output->WriteRaw(unknown_fields().data(),
unknown_fields().size());
// @@protoc_insertion_point(serialize_end:proto.RunSpectrumsStatus)
}
int RunSpectrumsStatus::ByteSize() const {
int total_size = 0;
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
// required .proto.RunSpectrumsStatus.Type type = 1;
if (has_type()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::EnumSize(this->type());
}
// required double frMin = 2;
if (has_frmin()) {
total_size += 1 + 8;
}
// required double frMax = 3;
if (has_frmax()) {
total_size += 1 + 8;
}
// required int32 n = 4;
if (has_n()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
this->n());
}
// required double time = 5;
if (has_time()) {
total_size += 1 + 8;
}
// required int32 run = 6;
if (has_run()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
this->run());
}
}
total_size += unknown_fields().size();
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = total_size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
return total_size;
}
void RunSpectrumsStatus::CheckTypeAndMergeFrom(
const ::google::protobuf::MessageLite& from) {
MergeFrom(*::google::protobuf::down_cast<const RunSpectrumsStatus*>(&from));
}
void RunSpectrumsStatus::MergeFrom(const RunSpectrumsStatus& from) {
GOOGLE_CHECK_NE(&from, this);
if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (from.has_type()) {
set_type(from.type());
}
if (from.has_frmin()) {
set_frmin(from.frmin());
}
if (from.has_frmax()) {
set_frmax(from.frmax());
}
if (from.has_n()) {
set_n(from.n());
}
if (from.has_time()) {
set_time(from.time());
}
if (from.has_run()) {
set_run(from.run());
}
}
mutable_unknown_fields()->append(from.unknown_fields());
}
void RunSpectrumsStatus::CopyFrom(const RunSpectrumsStatus& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool RunSpectrumsStatus::IsInitialized() const {
if ((_has_bits_[0] & 0x0000003f) != 0x0000003f) return false;
return true;
}
void RunSpectrumsStatus::Swap(RunSpectrumsStatus* other) {
if (other != this) {
std::swap(type_, other->type_);
std::swap(frmin_, other->frmin_);
std::swap(frmax_, other->frmax_);
std::swap(n_, other->n_);
std::swap(time_, other->time_);
std::swap(run_, other->run_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_unknown_fields_.swap(other->_unknown_fields_);
std::swap(_cached_size_, other->_cached_size_);
}
}
::std::string RunSpectrumsStatus::GetTypeName() const {
return "proto.RunSpectrumsStatus";
}
// @@protoc_insertion_point(namespace_scope)
} // namespace proto
......
......@@ -34,6 +34,7 @@ void protobuf_ShutdownFile_FrequencyRequestMessages_2eproto();
class RunSpectrumsRequest;
class FrequencyResponse;
class RunSpectrumsStatus;
enum RunSpectrumsRequest_Type {
RunSpectrumsRequest_Type_START = 1,
......@@ -48,6 +49,17 @@ const RunSpectrumsRequest_Type RunSpectrumsRequest_Type_Type_MIN = RunSpectrumsR
const RunSpectrumsRequest_Type RunSpectrumsRequest_Type_Type_MAX = RunSpectrumsRequest_Type_TEST;
const int RunSpectrumsRequest_Type_Type_ARRAYSIZE = RunSpectrumsRequest_Type_Type_MAX + 1;
enum RunSpectrumsStatus_Type {
RunSpectrumsStatus_Type_RUN = 1,
RunSpectrumsStatus_Type_RUN_TIME = 2,
RunSpectrumsStatus_Type_RUN_SINGLE = 3,
RunSpectrumsStatus_Type_TEST = 4
};
bool RunSpectrumsStatus_Type_IsValid(int value);
const RunSpectrumsStatus_Type RunSpectrumsStatus_Type_Type_MIN = RunSpectrumsStatus_Type_RUN;
const RunSpectrumsStatus_Type RunSpectrumsStatus_Type_Type_MAX = RunSpectrumsStatus_Type_TEST;
const int RunSpectrumsStatus_Type_Type_ARRAYSIZE = RunSpectrumsStatus_Type_Type_MAX + 1;
// ===================================================================
class RunSpectrumsRequest : public ::google::protobuf::MessageLite {
......@@ -326,6 +338,162 @@ class FrequencyResponse : public ::google::protobuf::MessageLite {
void InitAsDefaultInstance();
static FrequencyResponse* default_instance_;
};
// -------------------------------------------------------------------
class RunSpectrumsStatus : public ::google::protobuf::MessageLite {
public:
RunSpectrumsStatus();
virtual ~RunSpectrumsStatus();
RunSpectrumsStatus(const RunSpectrumsStatus& from);
inline RunSpectrumsStatus& operator=(const RunSpectrumsStatus& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const RunSpectrumsStatus& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.