ServicesImpl.h 3.38 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

namespace cameo {

class ServicesImpl {

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

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

	bool isAvailable(const std::string& strRequestType, const std::string& strRequestData, const std::string& endpoint, int timeout);
	void waitForSubscriber(zmq::socket_t * subscriber, const std::string& strRequestType, const std::string& strRequestData, const std::string& endpoint);
	void subscribeToPublisher(const std::string& endpoint);

	std::string createRequest(ProtoType type) const;
	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
64
65
66

	zmq::socket_t * createEventSubscriber(const std::string& endpoint, const std::string& cancelEndpoint);
	zmq::socket_t * createCancelPublisher(const std::string& endpoint);

67
	std::auto_ptr<zmq::message_t> tryRequestWithOnePartReply(const std::string& strRequestType, const std::string& strRequestData, const std::string& endpoint, int overrideTimeout = -1);
legoc's avatar
legoc committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
	std::string createShowStreamRequest(int id) const;

	proto::MessageType_Type convertToProtoType(ProtoType type) const;

	int m_timeout;
	zmq::context_t m_context;

	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;
};

}

#endif