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
26namespace mir
27{
28namespace client
29{
31class Event
32{
33public:
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
43private:
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".
49void mir_event_unref(Event const& event) = delete;
50}
51}
52
53#endif //MIR_CLIENT_EVENT_H_
54
Handle class for MirEvent - provides automatic reference counting.
Definition: event.h:32
void reset()
Definition: event.h:41
Event(MirEvent const *event)
Definition: event.h:35
MirEvent const * mir_event_ref(MirEvent const *event) __attribute__((warn_unused_result))
Reference this MirEvent and return a pointer to the newly referenced instance.
struct MirEvent MirEvent
Definition: event.h:84
void mir_event_unref(Event const &event)=delete
Definition: splash_session.h:24

Copyright © 2012-2022 Canonical Ltd.
Generated on Sun Oct 9 06:13:38 UTC 2022
This documentation is licensed under the GPL version 2 or 3.