summaryrefslogtreecommitdiff
path: root/src/libcamera/include/message.h
blob: 92717e316cc355085540c2e8ec74c9276d7abec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
61
62
63
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * message.h - Message queue support
 */
#ifndef __LIBCAMERA_MESSAGE_H__
#define __LIBCAMERA_MESSAGE_H__

#include <atomic>

#include <libcamera/bound_method.h>

namespace libcamera {

class BoundMethodBase;
class Object;
class Thread;

class Message
{
public:
	enum Type {
		None = 0,
		InvokeMessage = 1,
		UserMessage = 1000,
	};

	Message(Type type);
	virtual ~Message();

	Type type() const { return type_; }
	Object *receiver() const { return receiver_; }

	static Type registerMessageType();

private:
	friend class Thread;

	Type type_;
	Object *receiver_;

	static std::atomic_uint nextUserType_;
};

class InvokeMessage : public Message
{
public:
	InvokeMessage(BoundMethodBase *method, void *pack,
		      bool deleteMethod = false);
	~InvokeMessage();

	void invoke();

private:
	BoundMethodBase *method_;
	void *pack_;
	bool deleteMethod_;
};

} /* namespace libcamera */

#endif /* __LIBCAMERA_MESSAGE_H__ */