libcamera  v0.2.0+133-f1522e94
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 queue support
6  */
7 
8 #pragma once
9 
10 #include <atomic>
11 
12 #include <libcamera/base/private.h>
13 
15 
16 namespace libcamera {
17 
18 class BoundMethodBase;
19 class Object;
20 class Semaphore;
21 class Thread;
22 
23 class Message
24 {
25 public:
26  enum Type {
27  None = 0,
31  UserMessage = 1000,
32  };
33 
34  Message(Type type);
35  virtual ~Message();
36 
37  Type type() const { return type_; }
38  Object *receiver() const { return receiver_; }
39 
40  static Type registerMessageType();
41 
42 private:
43  friend class Thread;
44 
45  Type type_;
46  Object *receiver_;
47 
48  static std::atomic_uint nextUserType_;
49 };
50 
51 class InvokeMessage : public Message
52 {
53 public:
54  InvokeMessage(BoundMethodBase *method,
55  std::shared_ptr<BoundMethodPackBase> pack,
56  Semaphore *semaphore = nullptr,
57  bool deleteMethod = false);
58  ~InvokeMessage();
59 
60  Semaphore *semaphore() const { return semaphore_; }
61 
62  void invoke();
63 
64 private:
65  BoundMethodBase *method_;
66  std::shared_ptr<BoundMethodPackBase> pack_;
67  Semaphore *semaphore_;
68  bool deleteMethod_;
69 };
70 
71 } /* namespace libcamera */
static Type registerMessageType()
Reserve and register a custom user-defined message type.
Definition: message.cpp:109
First value available for user-defined messages.
Definition: message.h:31
Semaphore * semaphore() const
Retrieve the message semaphore passed to the constructor.
Definition: message.h:60
General-purpose counting semaphore.
Definition: semaphore.h:16
Asynchronous method invocation across threads.
Definition: message.h:28
Top-level libcamera namespace.
Definition: backtrace.h:17
Type type() const
Retrieve the message type.
Definition: message.h:37
Object is being moved to a different thread.
Definition: message.h:29
Object is scheduled for deletion.
Definition: message.h:30
A thread of execution.
Definition: thread.h:28
A message carrying a method invocation across threads.
Definition: message.h:51
Object * receiver() const
Retrieve the message receiver.
Definition: message.h:38
A message that can be posted to a Thread.
Definition: message.h:23
Message(Type type)
Construct a message object of type type.
Definition: message.cpp:61
Type
The message type.
Definition: message.h:26
Base object to support automatic signal disconnection.
Definition: object.h:24
Method bind and invocation.
Invalid message type.
Definition: message.h:27