The code.ill.fr has been recreated and upgraded with the latest version this weekend, If you encounter any problem please inform the Helpdesk.

Commit d7af35f2 authored by legoc's avatar legoc
Browse files

(split) Simplified storage events into one single KeyEvent (server and APIs)

parent 5d7fa164
......@@ -22,10 +22,9 @@
#include "PublisherEvent.h"
#include "ResultEvent.h"
#include "StatusEvent.h"
#include "StoreKeyValueEvent.h"
#include "KeyEvent.h"
#include "impl/StreamSocketImpl.h"
#include "message/Message.h"
#include "RemoveKeyValueEvent.h"
using namespace std;
......@@ -111,7 +110,7 @@ std::unique_ptr<Event> EventStreamSocket::receive(bool blocking) {
return unique_ptr<Event>(new PortEvent(id, name, portName));
}
else if (response == message::Event::STOREKEYVALUE) {
else if (response == message::Event::KEYVALUE) {
message = m_impl->receive();
......@@ -119,27 +118,18 @@ std::unique_ptr<Event> EventStreamSocket::receive(bool blocking) {
json::Object event;
json::parse(event, message.get());
int id = event[message::StoreKeyValueEvent::ID].GetInt();
string name = event[message::StoreKeyValueEvent::NAME].GetString();
string key = event[message::StoreKeyValueEvent::KEY].GetString();
string value = event[message::StoreKeyValueEvent::VALUE].GetString();
int id = event[message::KeyEvent::ID].GetInt();
string name = event[message::KeyEvent::NAME].GetString();
long status = event[message::KeyEvent::STATUS].GetInt64();
string key = event[message::KeyEvent::KEY].GetString();
string value = event[message::KeyEvent::VALUE].GetString();
return unique_ptr<Event>(new StoreKeyValueEvent(id, name, key, value));
}
else if (response == message::Event::REMOVEKEYVALUE) {
message = m_impl->receive();
// Get the JSON event.
json::Object event;
json::parse(event, message.get());
int id = event[message::RemoveKeyValueEvent::ID].GetInt();
string name = event[message::RemoveKeyValueEvent::NAME].GetString();
string key = event[message::RemoveKeyValueEvent::KEY].GetString();
string value = event[message::RemoveKeyValueEvent::VALUE].GetString();
return unique_ptr<Event>(new RemoveKeyValueEvent(id, name, key, value));
if (status == message::STORE_KEY_VALUE) {
return unique_ptr<Event>(new KeyEvent(id, name, KeyEvent::Status::STORED, key, value));
}
else {
return unique_ptr<Event>(new KeyEvent(id, name, KeyEvent::Status::REMOVED, key, value));
}
}
else if (response == message::Event::CANCEL) {
......
......@@ -20,18 +20,28 @@
namespace cameo {
KeyEvent::KeyEvent(int id, const std::string& name, const std::string& key, const std::string& value) :
KeyEvent::KeyEvent(int id, const std::string& name, Status status, const std::string& key, const std::string& value) :
Event(id, name),
m_status(status),
m_key(key),
m_value(value) {
}
KeyEvent::KeyEvent(const KeyEvent& event) :
Event(event),
m_status(event.m_status),
m_key(event.m_key),
m_value(event.m_value) {
}
KeyEvent* KeyEvent::clone() {
return new KeyEvent(*this);
}
KeyEvent::Status KeyEvent::getStatus() const {
return m_status;
}
const std::string& KeyEvent::getKey() const {
return m_key;
}
......@@ -40,4 +50,14 @@ const std::string& KeyEvent::getValue() const {
return m_value;
}
std::ostream& operator<<(std::ostream& os, const KeyEvent& event) {
os << "name=" << event.m_name
<< "\nid=" << event.m_id
<< "\nstatus" << static_cast<int>(event.m_status)
<< "\nkey=" << event.m_key
<< "\nvalue=" << event.m_value;
return os;
}
}
......@@ -24,18 +24,28 @@ namespace cameo {
class KeyEvent : public Event {
friend std::ostream& operator<<(std::ostream&, const KeyEvent&);
public:
KeyEvent(int id, const std::string& name, const std::string& key, const std::string& value);
enum Status {STORED, REMOVED};
KeyEvent(int id, const std::string& name, Status status, const std::string& key, const std::string& value);
KeyEvent(const KeyEvent& event);
virtual KeyEvent* clone();
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;
};
std::ostream& operator<<(std::ostream&, const KeyEvent&);
}
#endif
/*
* 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 <iostream>
#include "RemoveKeyValueEvent.h"
namespace cameo {
RemoveKeyValueEvent::RemoveKeyValueEvent(int id, const std::string& name, const std::string& key, const std::string& value) :
KeyEvent(id, name, key, value) {
}
RemoveKeyValueEvent::RemoveKeyValueEvent(const RemoveKeyValueEvent& event) :
KeyEvent(event) {
}
RemoveKeyValueEvent* RemoveKeyValueEvent::clone() {
return new RemoveKeyValueEvent(*this);
}
std::ostream& operator<<(std::ostream& os, const cameo::RemoveKeyValueEvent& event) {
os << "name=" << event.m_name
<< "\nid=" << event.m_id
<< "\nkey=" << event.m_key
<< "\nvalue=" << event.m_value;
return os;
}
}
/*
* 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_REMOVEKEYVALUEEVENT_H_
#define CAMEO_REMOVEKEYVALUEEVENT_H_
#include <iostream>
#include "KeyEvent.h"
namespace cameo {
class RemoveKeyValueEvent : public KeyEvent {
friend std::ostream& operator<<(std::ostream&, const RemoveKeyValueEvent&);
public:
RemoveKeyValueEvent(int id, const std::string& name, const std::string& key, const std::string& value);
RemoveKeyValueEvent(const RemoveKeyValueEvent& event);
virtual RemoveKeyValueEvent* clone();
};
std::ostream& operator<<(std::ostream&, const RemoveKeyValueEvent&);
}
#endif
/*
* 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 "StoreKeyValueEvent.h"
#include <iostream>
namespace cameo {
StoreKeyValueEvent::StoreKeyValueEvent(int id, const std::string& name, const std::string& key, const std::string& value) :
KeyEvent(id, name, key, value) {
}
StoreKeyValueEvent::StoreKeyValueEvent(const StoreKeyValueEvent& event) :
KeyEvent(event) {
}
StoreKeyValueEvent* StoreKeyValueEvent::clone() {
return new StoreKeyValueEvent(*this);
}
std::ostream& operator<<(std::ostream& os, const cameo::StoreKeyValueEvent& event) {
os << "name=" << event.m_name
<< "\nid=" << event.m_id
<< "\nkey=" << event.m_key
<< "\nvalue=" << event.m_value;
return os;
}
}
/*
* 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_STOREKEYVALUEEVENT_H_
#define CAMEO_STOREKEYVALUEEVENT_H_
#include <iostream>
#include "KeyEvent.h"
namespace cameo {
class StoreKeyValueEvent : public KeyEvent {
friend std::ostream& operator<<(std::ostream&, const StoreKeyValueEvent&);
public:
StoreKeyValueEvent(int id, const std::string& name, const std::string& key, const std::string& value);
StoreKeyValueEvent(const StoreKeyValueEvent& event);
virtual StoreKeyValueEvent* clone();
};
std::ostream& operator<<(std::ostream&, const StoreKeyValueEvent&);
}
#endif
......@@ -69,8 +69,7 @@ namespace message {
constexpr const char* RESULT = "RESULT";
constexpr const char* PORT = "PORT";
constexpr const char* PUBLISHER = "PUBLISHER";
constexpr const char* STOREKEYVALUE = "STOREKEYVALUE";
constexpr const char* REMOVEKEYVALUE = "REMOVEKEYVALUE";
constexpr const char* KEYVALUE = "KEYVALUE";
}
namespace SyncStreamRequest {
......@@ -274,16 +273,10 @@ namespace message {
constexpr const char* KEY = "key"; // string
}
namespace StoreKeyValueEvent {
constexpr const char* ID = "id"; // int32
constexpr const char* NAME = "name"; // string
constexpr const char* KEY = "key"; // string
constexpr const char* VALUE = "value"; // string
}
namespace RemoveKeyValueEvent {
namespace KeyEvent {
constexpr const char* ID = "id"; // int32
constexpr const char* NAME = "name"; // string
constexpr const char* STATUS = "status"; // long STORE_KEY_VALUE or REMOVE_KEY
constexpr const char* KEY = "key"; // string
constexpr const char* VALUE = "value"; // string
}
......
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