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 
8 #pragma once
9 
10 #include <atomic>
11 
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,
29  UserMessage = 1000,
30  };
31 
32  Message(Type type);
33  virtual ~Message();
34 
35  Type type() const { return type_; }
36  Object *receiver() const { return receiver_; }
37 
38  static Type registerMessageType();
39 
40 private:
41  friend class Thread;
42 
43  Type type_;
44  Object *receiver_;
45 
46  static std::atomic_uint nextUserType_;
47 };
48 
49 class InvokeMessage : public Message
50 {
51 public:
52  InvokeMessage(BoundMethodBase *method,
53  std::shared_ptr<BoundMethodPackBase> pack,
54  Semaphore *semaphore = nullptr,
55  bool deleteMethod = false);
56  ~InvokeMessage();
57 
58  Semaphore *semaphore() const { return semaphore_; }
59 
60  void invoke();
61 
62 private:
63  BoundMethodBase *method_;
64  std::shared_ptr<BoundMethodPackBase> pack_;
65  Semaphore *semaphore_;
66  bool deleteMethod_;
67 };
68 
69 } /* namespace libcamera */
Method bind and invocation.
A message carrying a method invocation across threads.
Definition: message.h:50
Semaphore * semaphore() const
Retrieve the message semaphore passed to the constructor.
Definition: message.h:58
void invoke()
Invoke the method bound to InvokeMessage::method_ with arguments InvokeMessage::pack_.
Definition: message.cpp:151
A message that can be posted to a Thread.
Definition: message.h:22
Object * receiver() const
Retrieve the message receiver.
Definition: message.h:36
Type type() const
Retrieve the message type.
Definition: message.h:35
Type
The message type.
Definition: message.h:24
@ DeferredDelete
Object is scheduled for deletion.
Definition: message.h:28
@ 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:29
Message(Type type)
Construct a message object of type type.
Definition: message.cpp:61
static Type registerMessageType()
Reserve and register a custom user-defined message type.
Definition: message.cpp:109
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:29
Top-level libcamera namespace.
Definition: backtrace.h:17