libcamera  v0.0.0
Supporting cameras in Linux since 2019
message.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2019, Google Inc.
4  *
5  * message.h - Message queue support
6  */
7 #ifndef __LIBCAMERA_INTERNAL_MESSAGE_H__
8 #define __LIBCAMERA_INTERNAL_MESSAGE_H__
9 
10 #include <atomic>
11 
12 #include <libcamera/bound_method.h>
13 
14 namespace libcamera {
15 
16 class BoundMethodBase;
17 class Object;
18 class Semaphore;
19 class Thread;
20 
21 class Message
22 {
23 public:
24  enum Type {
25  None = 0,
28  UserMessage = 1000,
29  };
30 
31  Message(Type type);
32  virtual ~Message();
33 
34  Type type() const { return type_; }
35  Object *receiver() const { return receiver_; }
36 
37  static Type registerMessageType();
38 
39 private:
40  friend class Thread;
41 
42  Type type_;
43  Object *receiver_;
44 
45  static std::atomic_uint nextUserType_;
46 };
47 
48 class InvokeMessage : public Message
49 {
50 public:
51  InvokeMessage(BoundMethodBase *method,
52  std::shared_ptr<BoundMethodPackBase> pack,
53  Semaphore *semaphore = nullptr,
54  bool deleteMethod = false);
55  ~InvokeMessage();
56 
57  Semaphore *semaphore() const { return semaphore_; }
58 
59  void invoke();
60 
61 private:
62  BoundMethodBase *method_;
63  std::shared_ptr<BoundMethodPackBase> pack_;
64  Semaphore *semaphore_;
65  bool deleteMethod_;
66 };
67 
68 } /* namespace libcamera */
69 
70 #endif /* __LIBCAMERA_INTERNAL_MESSAGE_H__ */
Method bind and invocation.
A message carrying a method invocation across threads.
Definition: message.h:49
Semaphore * semaphore() const
Retrieve the message semaphore passed to the constructor.
Definition: message.h:57
void invoke()
Invoke the method bound to InvokeMessage::method_ with arguments InvokeMessage::pack_.
Definition: message.cpp:150
A message that can be posted to a Thread.
Definition: message.h:22
Object * receiver() const
Retrieve the message receiver.
Definition: message.h:35
Type type() const
Retrieve the message type.
Definition: message.h:34
Type
The message type.
Definition: message.h:24
@ None
Invalid message type.
Definition: message.h:25
@ InvokeMessage
Asynchronous method invocation across threads.
Definition: message.h:26
@ ThreadMoveMessage
Object is being moved to a different thread.
Definition: message.h:27
@ UserMessage
First value available for user-defined messages.
Definition: message.h:28
Message(Type type)
Construct a message object of type type.
Definition: message.cpp:60
static Type registerMessageType()
Reserve and register a custom user-defined message type.
Definition: message.cpp:108
Base object to support automatic signal disconnection.
Definition: object.h:25
General-purpose counting semaphore.
Definition: semaphore.h:17
A thread of execution.
Definition: thread.h:31