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 bb2f5af5 authored by legoc's avatar legoc
Browse files

(split) The cameo server sends the key value events and they are dispatched in the APIs

parent 2cc56d70
......@@ -30,6 +30,10 @@ public:
EventListener();
virtual ~EventListener();
/**
* Sets the name of the listener i.e. the application name.
* It is used to filter the messages in the event thread because when the listener is registered, the application id is not known.
*/
void setName(const std::string& name);
const std::string& getName() const;
......
......@@ -22,6 +22,8 @@
#include "PublisherEvent.h"
#include "ResultEvent.h"
#include "StatusEvent.h"
#include "StoreKeyValueEvent.h"
#include "RemoveKeyEvent.h"
#include "impl/StreamSocketImpl.h"
#include "message/Message.h"
......@@ -109,6 +111,35 @@ std::unique_ptr<Event> EventStreamSocket::receive(bool blocking) {
return unique_ptr<Event>(new PortEvent(id, name, portName));
}
else if (response == message::Event::STOREKEYVALUE) {
message = m_impl->receive();
// Get the JSON event.
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();
return unique_ptr<Event>(new StoreKeyValueEvent(id, name, key, value));
}
else if (response == message::Event::REMOVEKEY) {
message = m_impl->receive();
// Get the JSON event.
json::Object event;
json::parse(event, message.get());
int id = event[message::RemoveKeyEvent::ID].GetInt();
string name = event[message::RemoveKeyEvent::NAME].GetString();
string key = event[message::RemoveKeyEvent::KEY].GetString();
return unique_ptr<Event>(new RemoveKeyEvent(id, name, key));
}
else if (response == message::Event::CANCEL) {
message = m_impl->receive();
......
......@@ -52,6 +52,7 @@ void EventThread::start() {
for (EventListener * listener : eventListeners) {
// If the application name is null, all the status are pushed, otherwise, filter on the name.
// We filter on the name because the id is not known at the registration.
if (listener->getName() == ""
|| listener->getName() == event->getName()) {
......
/*
* 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 "KeyEvent.h"
#include <iostream>
namespace cameo {
KeyEvent::KeyEvent(int id, const std::string& name, const std::string& key) :
Event(id, name),
m_key(key) {
}
KeyEvent::KeyEvent(const KeyEvent& event) :
Event(event), m_key(event.m_key) {
}
const std::string& KeyEvent::getKey() const {
return m_key;
}
}
/*
* 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_KEYEVENT_H_
#define CAMEO_KEYEVENT_H_
#include <iostream>
#include "Event.h"
namespace cameo {
class KeyEvent : public Event {
public:
KeyEvent(int id, const std::string& name, const std::string& key);
KeyEvent(const KeyEvent& event);
const std::string& getKey() const;
private:
std::string m_key;
};
}
#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 "RemoveKeyEvent.h"
#include <iostream>
namespace cameo {
RemoveKeyEvent::RemoveKeyEvent(int id, const std::string& name, const std::string& key) :
KeyEvent(id, name, key) {
}
RemoveKeyEvent::RemoveKeyEvent(const RemoveKeyEvent& event) :
KeyEvent(event) {
}
RemoveKeyEvent* RemoveKeyEvent::clone() {
return new RemoveKeyEvent(*this);
}
std::ostream& operator<<(std::ostream& os, const cameo::RemoveKeyEvent& event) {
os << "name=" << event.m_name
<< "\nid=" << event.m_id
<< "\nkey=" << event.m_key;
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_REMOVEKEYEVENT_H_
#define CAMEO_REMOVEKEYEVENT_H_
#include <iostream>
#include "KeyEvent.h"
namespace cameo {
class RemoveKeyEvent : public KeyEvent {
friend std::ostream& operator<<(std::ostream&, const RemoveKeyEvent&);
public:
RemoveKeyEvent(int id, const std::string& name, const std::string& key);
RemoveKeyEvent(const RemoveKeyEvent& event);
virtual RemoveKeyEvent* clone();
};
std::ostream& operator<<(std::ostream&, const RemoveKeyEvent&);
}
#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),
m_value(value) {
}
StoreKeyValueEvent::StoreKeyValueEvent(const StoreKeyValueEvent& event) :
KeyEvent(event), m_value(event.m_value) {
}
StoreKeyValueEvent* StoreKeyValueEvent::clone() {
return new StoreKeyValueEvent(*this);
}
const std::string& StoreKeyValueEvent::getValue() const {
return m_value;
}
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();
const std::string& getValue() const;
private:
std::string m_value;
};
std::ostream& operator<<(std::ostream&, const StoreKeyValueEvent&);
}
#endif
......@@ -69,6 +69,8 @@ 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* REMOVEKEY = "REMOVEKEY";
}
namespace SyncStreamRequest {
......@@ -272,6 +274,18 @@ 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 RemoveKeyEvent {
constexpr const char* ID = "id"; // int32
constexpr const char* NAME = "name"; // string
constexpr const char* KEY = "key"; // 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