Mir
event.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2017 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 2 or 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
17  */
18 
19 #ifndef MIR_CLIENT_EVENT_H_
20 #define MIR_CLIENT_EVENT_H_
21 
23 
24 #include <memory>
25 
26 namespace mir
27 {
28 namespace client
29 {
31 class Event
32 {
33 public:
34  Event() = default;
35  explicit Event(MirEvent const* event) : self{mir_event_ref(event), deleter}
36  {
37  }
38 
39  operator MirEvent const*() const { return self.get(); }
40 
41  void reset() { self.reset(); }
42 
43 private:
44  static void deleter(MirEvent const* event) { mir_event_unref(event); }
45  std::shared_ptr<MirEvent const> self;
46 };
47 
48 // Provide a deleted overload to avoid double release "accidents".
49 void mir_event_unref(Event const& event) = delete;
50 }
51 }
52 
53 #endif //MIR_CLIENT_EVENT_H_
54 
Definition: splash_session.h:24
Event(MirEvent const *event)
Definition: event.h:35
void mir_event_unref(Event const &event)=delete
void reset()
Definition: event.h:41
struct MirEvent MirEvent
Definition: event.h:84
MirEvent const * mir_event_ref(MirEvent const *event) __attribute__((warn_unused_result))
Reference this MirEvent and return a pointer to the newly referenced instance.
Handle class for MirEvent - provides automatic reference counting.
Definition: event.h:31

Copyright © 2012-2021 Canonical Ltd.
Generated on Wed Aug 11 12:02:04 UTC 2021
This documentation is licensed under the GPL version 2 or 3.