Commit 9b2bf21b authored by legoc's avatar legoc
Browse files

(split) Implemented waitFor() with KeyValue in Instance

parent d7af35f2
......@@ -35,6 +35,7 @@
#include "Services.h"
#include "TimeCondition.h"
#include "EventListener.h"
#include "KeyValue.h"
namespace cameo {
......@@ -210,6 +211,7 @@ public:
State waitFor(StateHandlerType handler = nullptr);
State waitFor(int states, StateHandlerType handler = nullptr);
State waitFor(const std::string& eventName);
State waitFor(KeyValue& keyValue);
void cancelWaitFor();
......@@ -254,7 +256,7 @@ private:
void setOutputStreamSocket(std::unique_ptr<OutputStreamSocket>& socket);
void setPastStates(State pastStates);
void setInitialState(State state);
State waitFor(int states, const std::string& eventName, StateHandlerType handler, bool blocking);
State waitFor(int states, const std::string& eventName, KeyValue& keyValue, StateHandlerType handler, bool blocking);
Server * m_server;
std::shared_ptr<OutputStreamSocket> m_outputStreamSocket;
......
/*
* Copyright 2015 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 CAMEO_KEYVALUE_H_
#define CAMEO_KEYVALUE_H_
#include <string>
namespace cameo {
class KeyValue {
public:
enum Status {UNDEFINED, STORED, REMOVED};
KeyValue(const std::string& key);
void setStatus(Status status);
void setValue(const std::string& value);
Status getStatus() const;
const std::string& getKey() const;
const std::string& getValue() const;
private:
Status m_status;
std::string m_key;
std::string m_value;
};
}
#endif
......@@ -42,6 +42,7 @@
#include "PublisherEvent.h"
#include "ResultEvent.h"
#include "PortEvent.h"
#include "KeyEvent.h"
#include "CancelEvent.h"
using namespace std;
......@@ -535,7 +536,7 @@ bool Instance::kill() {
return true;
}
State Instance::waitFor(int states, const std::string& eventName, StateHandlerType handler, bool blocking) {
State Instance::waitFor(int states, const std::string& eventName, KeyValue& keyValue, StateHandlerType handler, bool blocking) {
if (!exists()) {
// The application was not launched
......@@ -613,6 +614,19 @@ State Instance::waitFor(int states, const std::string& eventName, StateHandlerTy
break;
}
}
else if (KeyEvent * keyEvent = dynamic_cast<KeyEvent *>(event.get())) {
if (keyEvent->getKey() == keyValue.getKey()) {
// Set the status and value.
if (keyEvent->getStatus() == KeyEvent::Status::STORED) {
keyValue.setStatus(KeyValue::Status::STORED);
}
else {
keyValue.setStatus(KeyValue::Status::REMOVED);
}
keyValue.setValue(keyEvent->getValue());
break;
}
}
else if (CancelEvent * cancel = dynamic_cast<CancelEvent *>(event.get())) {
break;
}
......@@ -624,15 +638,22 @@ State Instance::waitFor(int states, const std::string& eventName, StateHandlerTy
}
State Instance::waitFor(int states, StateHandlerType handler) {
return waitFor(states, "", handler, true);
KeyValue keyValue("");
return waitFor(states, "", keyValue, handler, true);
}
State Instance::waitFor(StateHandlerType handler) {
return waitFor(0, "", handler, true);
KeyValue keyValue("");
return waitFor(0, "", keyValue, handler, true);
}
State Instance::waitFor(const std::string& eventName) {
return waitFor(0, eventName, nullptr, true);
KeyValue keyValue("");
return waitFor(0, eventName, keyValue, nullptr, true);
}
State Instance::waitFor(KeyValue& keyValue) {
return waitFor(0, "", keyValue, nullptr, true);
}
void Instance::cancelWaitFor() {
......@@ -646,8 +667,8 @@ State Instance::now() {
}
State Instance::getLastState() {
return waitFor(0, "", nullptr, false);
KeyValue keyValue("");
return waitFor(0, "", keyValue, nullptr, false);
}
State Instance::getActualState() const {
......
/*
* Copyright 2015 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 "KeyValue.h"
namespace cameo {
KeyValue::KeyValue(const std::string& key) :
m_status(Status::UNDEFINED),
m_key(key) {
}
void KeyValue::setStatus(Status status) {
m_status = status;
}
void KeyValue::setValue(const std::string& value) {
m_value = value;
}
KeyValue::Status KeyValue::getStatus() const {
return m_status;
}
const std::string& KeyValue::getKey() const {
return m_key;
}
const std::string& KeyValue::getValue() const {
return m_value;
}
}
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