ServicesImpl.h 3.34 KB
Newer Older
legoc's avatar
legoc committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * 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_SERVICESIMPL_H_
#define CAMEO_SERVICESIMPL_H_

#include "../../proto/Messages.pb.h"
21
#include "../ProtoType.h"
legoc's avatar
legoc committed
22
#include <vector>
23
#include <memory>
24
#include "zmq.hpp"
legoc's avatar
legoc committed
25
26
27

namespace cameo {

28
29
class RequestSocketImpl;

legoc's avatar
legoc committed
30
31
32
33
34
35
36
37
38
class ServicesImpl {

public:
	ServicesImpl();
	virtual ~ServicesImpl();

	void setTimeout(int timeout);
	int getTimeout() const;

39
	proto::MessageType_Type convertToProtoType(ProtoType type) const;
legoc's avatar
legoc committed
40

41
	std::string createRequestType(ProtoType type) const;
legoc's avatar
legoc committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	std::string createInitRequest() const;
	std::string createStartRequest(const std::string& name, const std::vector<std::string> & args, const std::string& instanceReference) const;
	std::string createStopRequest(int id) const;
	std::string createKillRequest(int id) const;
	std::string createConnectRequest(const std::string& name) const;
	std::string createIsAliveRequest(int id) const;
	std::string createAllAvailableRequest() const;
	std::string createShowAllRequest() const;
	std::string createShowStatusRequest() const;
	std::string createSetStatusRequest(int id, int32_t state) const;
	std::string createGetStatusRequest(int id) const;
	std::string createSetResultRequest(int id, const std::string& data) const;
	std::string createSubscribePublisherRequest() const;
	std::string createCreatePublisherRequest(int id, const std::string& name, int numberOfSubscribers) const;
	std::string createConnectPublisherRequest(int id, const std::string& publisherName) const;
	std::string createTerminatePublisherRequest(int id, const std::string& name) const;
	std::string createRequestPortRequest(int id, const std::string& name) const;
	std::string createConnectPortRequest(int id, const std::string& name) const;
	std::string createRemovePortRequest(int id, const std::string& name) const;
legoc's avatar
legoc committed
61
62
	std::string createStartedUnmanagedRequest(const std::string& name) const;
	std::string createTerminatedUnmanagedRequest(int id) const;
legoc's avatar
legoc committed
63
	std::string createOutputRequest(const std::string& name) const;
legoc's avatar
legoc committed
64
65

	zmq::socket_t * createEventSubscriber(const std::string& endpoint, const std::string& cancelEndpoint);
66
	zmq::socket_t * createOutputStreamSubscriber(const std::string& endpoint, const std::string& cancelEndpoint);
legoc's avatar
legoc committed
67
	zmq::socket_t * createCancelPublisher(const std::string& endpoint);
68
	zmq::socket_t * createRequestSocket(const std::string& endpoint);
legoc's avatar
legoc committed
69
70
71

	std::string createShowStreamRequest(int id) const;

72
	bool isAvailable(RequestSocketImpl * socket, int timeout);
legoc's avatar
legoc committed
73
	void waitForSubscriber(zmq::socket_t * subscriber, RequestSocketImpl * socket);
74

legoc's avatar
legoc committed
75
	zmq::context_t m_context;
76
	int m_timeout;
legoc's avatar
legoc committed
77
78
79
80
81
82

	static const std::string STATUS;
	static const std::string RESULT;
	static const std::string PUBLISHER;
	static const std::string PORT;
	static const std::string CANCEL;
legoc's avatar
legoc committed
83
84
	static const std::string STREAM;
	static const std::string ENDSTREAM;
legoc's avatar
legoc committed
85
86
87
88
89
};

}

#endif