~alan-griffiths/miral/fix-1602331

« back to all changes in this revision

Viewing changes to include/miral/toolkit/connection.h

  • Committer: Alan Griffiths
  • Date: 2016-06-26 21:23:31 UTC
  • mfrom: (215.1.2 miral0)
  • Revision ID: alan@octopull.co.uk-20160626212331-evfjjolxzi7xf7ng
Fixes and enhancements to libmiral identified when trying to rewrite titlebar code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2016 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3,
 
6
 * as 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: Alan Griffiths <alan@octopull.co.uk>
 
17
 */
 
18
 
 
19
#ifndef MIRAL_TOOLKIT_CONNECTION_H
 
20
#define MIRAL_TOOLKIT_CONNECTION_H
 
21
 
 
22
#include <mir_toolkit/mir_connection.h>
 
23
 
 
24
#include <memory>
 
25
 
 
26
namespace miral
 
27
{
 
28
namespace toolkit
 
29
{
 
30
class Connection
 
31
{
 
32
public:
 
33
    Connection() = default;
 
34
    explicit Connection(MirConnection* connection) : self{connection, deleter} {}
 
35
 
 
36
    operator MirConnection*() const { return self.get(); }
 
37
 
 
38
    void reset() { self.reset(); }
 
39
 
 
40
private:
 
41
    static void deleter(MirConnection* connection) { mir_connection_release(connection); }
 
42
    std::shared_ptr<MirConnection> self;
 
43
};
 
44
}
 
45
}
 
46
 
 
47
#endif //MIRAL_TOOLKIT_CONNECTION_H