OutputStreamSocket.h 1.48 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_OUTPUTSTREAMSOCKET_H_
#define CAMEO_OUTPUTSTREAMSOCKET_H_

#include "Event.h"
21
22
#include <memory>
#include <optional>
legoc's avatar
legoc committed
23
24
25

namespace cameo {

26
class StreamSocketImpl;
legoc's avatar
legoc committed
27
28
29
30
31
32
33
34
35
36
class WaitingImpl;

namespace application {

class Instance;

}

class Output {

37
38
	friend class OutputStreamSocket;

legoc's avatar
legoc committed
39
public:
40
	Output();
legoc's avatar
legoc committed
41
42
43

	int getId() const;
	const std::string& getMessage() const;
44
	bool isEndOfLine() const;
legoc's avatar
legoc committed
45
46
47
48

private:
	int m_id;
	std::string m_message;
49
	bool m_endOfLine;
legoc's avatar
legoc committed
50
51
52
53
54
55
56
57
};


class OutputStreamSocket {

	friend class Services;
	friend class application::Instance;

58
59
	void setApplicationId(int id);

legoc's avatar
legoc committed
60
61
62
public:
	~OutputStreamSocket();

63
	std::optional<Output> receive();
legoc's avatar
legoc committed
64
	void cancel();
65
66
	bool isEnded() const;
	bool isCanceled() const;
legoc's avatar
legoc committed
67
68

private:
69
	OutputStreamSocket(StreamSocketImpl * impl);
legoc's avatar
legoc committed
70
71
72

	WaitingImpl * waiting();

legoc's avatar
legoc committed
73
	int m_applicationId;
74
75
	bool m_ended;
	bool m_canceled;
legoc's avatar
legoc committed
76

77
	std::unique_ptr<StreamSocketImpl> m_impl;
legoc's avatar
legoc committed
78
79
80
81
82
};

}

#endif