Commit 1911562a authored by legoc's avatar legoc
Browse files

Renamed WaitingImpl into Waiting

parent c0c2281c
......@@ -47,10 +47,10 @@ const int OUTPUTSTREAM = 1;
class Server;
class EventStreamSocket;
class OutputStreamSocket;
class WaitingImpl;
class Waiting;
class SocketWaitingImpl;
class GenericWaitingImpl;
class WaitingImplSet;
class Waiting;
class WaitingSet;
class HandlerImpl;
class RequestSocket;
......@@ -83,7 +83,7 @@ const State KILLED = 256;
class This : private EventListener {
friend class cameo::SocketWaitingImpl;
friend class cameo::GenericWaitingImpl;
friend class cameo::Waiting;
friend class cameo::Server;
friend std::ostream& operator<<(std::ostream&, const cameo::application::This&);
......@@ -203,7 +203,7 @@ private:
std::unique_ptr<Server> m_starterServer;
std::unique_ptr<Com> m_com;
std::unique_ptr<WaitingImplSet> m_waitingSet;
std::unique_ptr<WaitingSet> m_waitingSet;
std::unique_ptr<HandlerImpl> m_stopHandler;
bool m_inited;
......@@ -313,7 +313,7 @@ private:
bool m_hasResult;
std::string m_resultData;
int m_exitCode;
std::unique_ptr<WaitingImpl> m_waiting;
std::unique_ptr<Waiting> m_waiting;
};
///////////////////////////////////////////////////////////////////////////
......
......@@ -70,7 +70,7 @@ private:
static std::string createCreatePublisherRequest(int id, const std::string &name, int numberOfSubscribers);
std::unique_ptr<PublisherImpl> m_impl;
std::unique_ptr<WaitingImpl> m_waiting;
std::unique_ptr<Waiting> m_waiting;
};
///////////////////////////////////////////////////////////////////////////
......@@ -125,7 +125,7 @@ private:
static std::string createConnectPublisherRequest(int id, const std::string& publisherName);
std::unique_ptr<SubscriberImpl> m_impl;
std::unique_ptr<WaitingImpl> m_waiting;
std::unique_ptr<Waiting> m_waiting;
};
std::ostream& operator<<(std::ostream&, const cameo::coms::Publisher&);
......
......@@ -95,7 +95,7 @@ private:
Responder(int responderPort, const std::string &name);
std::unique_ptr<ResponderImpl> m_impl;
std::unique_ptr<WaitingImpl> m_waiting;
std::unique_ptr<Waiting> m_waiting;
};
///////////////////////////////////////////////////////////////////////////
......@@ -138,7 +138,7 @@ private:
Requester(const Endpoint &endpoint, int requesterPort, int responderPort, const std::string &name, int responderId, int requesterId);
std::unique_ptr<RequesterImpl> m_impl;
std::unique_ptr<WaitingImpl> m_waiting;
std::unique_ptr<Waiting> m_waiting;
};
std::ostream& operator<<(std::ostream&, const cameo::coms::Request&);
......
......@@ -24,16 +24,15 @@
#include "StarterServerException.h"
#include "StatusEvent.h"
#include "EventStreamSocket.h"
#include "impl/GenericWaitingImpl.h"
#include "impl/HandlerImpl.h"
#include "impl/StreamSocketImpl.h"
#include "impl/WaitingImpl.h"
#include "impl/WaitingImplSet.h"
#include "impl/zmq/ContextZmq.h"
#include "Strings.h"
#include "Server.h"
#include "Messages.h"
#include "RequestSocket.h"
#include "Waiting.h"
#include "WaitingSet.h"
#include <sstream>
#include <iostream>
#include <stdexcept>
......@@ -243,7 +242,7 @@ void This::initApplication() {
m_starterServer = std::make_unique<Server>(m_starterEndpoint);
}
m_waitingSet = std::make_unique<WaitingImplSet>();
m_waitingSet = std::make_unique<WaitingSet>();
// Init listener.
setName(m_name);
......@@ -455,7 +454,7 @@ Instance::Instance(Server * server) :
m_hasResult(false),
m_exitCode(-1) {
m_waiting.reset(new GenericWaitingImpl(std::bind(&Instance::cancelWaitFor, this)));
m_waiting.reset(new Waiting(std::bind(&Instance::cancelWaitFor, this)));
}
Instance::~Instance() {
......
......@@ -14,9 +14,8 @@
* limitations under the Licence.
*/
#include "GenericWaitingImpl.h"
#include "WaitingImplSet.h"
#include "Waiting.h"
#include "WaitingSet.h"
#include "Application.h"
#include <iostream>
......@@ -25,7 +24,7 @@ using namespace std;
namespace cameo {
GenericWaitingImpl::GenericWaitingImpl(GenericWaitingImpl::Function function)
Waiting::Waiting(Waiting::Function function)
: m_function(function) {
// Add the object in the waiting set if This exists.
......@@ -34,7 +33,7 @@ GenericWaitingImpl::GenericWaitingImpl(GenericWaitingImpl::Function function)
}
}
GenericWaitingImpl::~GenericWaitingImpl() {
Waiting::~Waiting() {
// Remove the object in the waiting set if This exists.
if (application::This::m_instance.m_inited) {
......@@ -42,7 +41,7 @@ GenericWaitingImpl::~GenericWaitingImpl() {
}
}
void GenericWaitingImpl::cancel() {
void Waiting::cancel() {
m_function();
}
......
......@@ -17,21 +17,19 @@
#ifndef CAMEO_GENERICWAITINGIMPL_H_
#define CAMEO_GENERICWAITINGIMPL_H_
#include "WaitingImpl.h"
#include <functional>
namespace cameo {
class GenericWaitingImpl : public WaitingImpl {
class Waiting {
public:
typedef std::function<void ()> Function;
GenericWaitingImpl(Function function);
virtual ~GenericWaitingImpl();
Waiting(Function function);
~Waiting();
virtual void cancel();
void cancel();
private:
Function m_function;
......
......@@ -14,41 +14,41 @@
* limitations under the Licence.
*/
#include "WaitingImplSet.h"
#include "WaitingSet.h"
#include "WaitingImpl.h"
#include "Waiting.h"
using namespace std;
namespace cameo {
WaitingImplSet::WaitingImplSet() {
WaitingSet::WaitingSet() {
}
void WaitingImplSet::add(WaitingImpl * waiting) {
void WaitingSet::add(Waiting * waiting) {
lock_guard<mutex> lock(m_mutex);
m_set.insert(waiting);
}
void WaitingImplSet::remove(WaitingImpl * waiting) {
void WaitingSet::remove(Waiting * waiting) {
lock_guard<mutex> lock(m_mutex);
set<WaitingImpl *>::iterator it = m_set.find(waiting);
set<Waiting *>::iterator it = m_set.find(waiting);
if (it != m_set.end()) {
m_set.erase(it);
}
}
void WaitingImplSet::cancelAll() {
void WaitingSet::cancelAll() {
lock_guard<mutex> lock(m_mutex);
for (set<WaitingImpl *>::iterator it = m_set.begin(); it != m_set.end(); ++it) {
for (set<Waiting *>::iterator it = m_set.begin(); it != m_set.end(); ++it) {
(*it)->cancel();
}
......
......@@ -14,8 +14,8 @@
* limitations under the Licence.
*/
#ifndef CAMEO_WAITINGIMPLSET_H_
#define CAMEO_WAITINGIMPLSET_H_
#ifndef CAMEO_WAITINGSET_H_
#define CAMEO_WAITINGSET_H_
#include <set>
#include <thread>
......@@ -23,25 +23,25 @@
namespace cameo {
class WaitingImpl;
class Waiting;
/**
* Class containing a set of WaitingImpl objects.
* Class containing a set of Waiting objects.
* It is protected with a mutex because the class must be thread-safe.
*/
class WaitingImplSet {
class WaitingSet {
public:
WaitingImplSet();
WaitingSet();
void add(WaitingImpl * waiting);
void remove(WaitingImpl * waiting);
void add(Waiting * waiting);
void remove(Waiting * waiting);
void cancelAll();
private:
std::mutex m_mutex;
std::set<WaitingImpl *> m_set;
std::set<Waiting *> m_set;
};
}
......
/*
* 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_WAITINGIMPL_H_
#define CAMEO_WAITINGIMPL_H_
namespace cameo {
class WaitingImpl {
public:
virtual ~WaitingImpl() {}
virtual void cancel() = 0;
};
}
#endif
\ No newline at end of file
......@@ -132,9 +132,9 @@ void PublisherImpl::cancelWaitForSubscribers() {
requestSocket->requestJSON(request.toString());
}
WaitingImpl * PublisherImpl::waiting() {
Waiting * PublisherImpl::waiting() {
return new GenericWaitingImpl(std::bind(&PublisherImpl::cancelWaitForSubscribers, this));
return new Waiting(std::bind(&PublisherImpl::cancelWaitForSubscribers, this));
}
void PublisherImpl::sendBinary(const std::string& data) {
......
......@@ -17,8 +17,7 @@
#ifndef CAMEO_PUBLISHERIMPL_H_
#define CAMEO_PUBLISHERIMPL_H_
#include "../../base/impl/GenericWaitingImpl.h"
#include "../../base/Waiting.h"
#include "zmq.hpp"
#include <memory>
#include <string>
......@@ -44,7 +43,7 @@ public:
bool waitForSubscribers();
void cancelWaitForSubscribers();
WaitingImpl * waiting();
Waiting * waiting();
void sendBinary(const std::string& data);
void send(const std::string& data);
......
......@@ -71,8 +71,8 @@ std::string RequesterImpl::getRequesterPortName(const std::string& name, int res
return requesterPortName.str();
}
WaitingImpl * RequesterImpl::waiting() {
return new GenericWaitingImpl(std::bind(&RequesterImpl::cancel, this));
Waiting * RequesterImpl::waiting() {
return new Waiting(std::bind(&RequesterImpl::cancel, this));
}
void RequesterImpl::sendBinary(const std::string& requestData) {
......
......@@ -17,7 +17,7 @@
#ifndef CAMEO_REQUESTERIMPL_H_
#define CAMEO_REQUESTERIMPL_H_
#include "../../base/impl/GenericWaitingImpl.h"
#include "../../base/Waiting.h"
#include "Strings.h"
#include "zmq.hpp"
#include <string>
......@@ -41,7 +41,7 @@ public:
static int newRequesterId();
static std::string getRequesterPortName(const std::string& name, int responderId, int requesterId);
WaitingImpl * waiting();
Waiting * waiting();
void sendBinary(const std::string& requestData);
void send(const std::string& requestData);
......
......@@ -59,8 +59,8 @@ void ResponderImpl::cancel() {
requestSocket->requestJSON(request.toString());
}
WaitingImpl * ResponderImpl::waiting() {
return new GenericWaitingImpl(std::bind(&ResponderImpl::cancel, this));
Waiting * ResponderImpl::waiting() {
return new Waiting(std::bind(&ResponderImpl::cancel, this));
}
std::unique_ptr<RequestImpl> ResponderImpl::receive() {
......
......@@ -17,8 +17,7 @@
#ifndef CAMEO_RESPONDERIMPL_H_
#define CAMEO_RESPONDERIMPL_H_
#include "../../base/impl/GenericWaitingImpl.h"
#include "../../base/Waiting.h"
#include "zmq.hpp"
#include <string>
#include <vector>
......@@ -36,7 +35,7 @@ public:
~ResponderImpl();
void cancel();
WaitingImpl * waiting();
Waiting * waiting();
std::unique_ptr<RequestImpl> receive();
......
......@@ -23,7 +23,7 @@
#include "../../base/Messages.h"
#include "../../base/RequestSocket.h"
#include "../../base/impl/zmq/ContextZmq.h"
#include "../../base/impl/GenericWaitingImpl.h"
#include "../../base/Waiting.h"
#include <sstream>
namespace cameo {
......@@ -229,10 +229,10 @@ void SubscriberImpl::cancel() {
m_cancelPublisher->send(requestData);
}
WaitingImpl * SubscriberImpl::waiting() {
Waiting * SubscriberImpl::waiting() {
// Waiting gets the cancel publisher.
return new GenericWaitingImpl(std::bind(&SubscriberImpl::cancel, this));
return new Waiting(std::bind(&SubscriberImpl::cancel, this));
}
std::string SubscriberImpl::createSubscribePublisherRequest() const {
......
......@@ -27,7 +27,7 @@
namespace cameo {
class Server;
class WaitingImpl;
class Waiting;
namespace coms {
......@@ -47,7 +47,7 @@ public:
std::optional<std::tuple<std::string, std::string>> receiveTwoBinaryParts();
void cancel();
WaitingImpl * waiting();
Waiting * waiting();
std::string createSubscribePublisherRequest() const;
......
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