Mir
connections.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012-2014 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 MIR_FRONTEND_CONNECTIONS_H_
20 #define MIR_FRONTEND_CONNECTIONS_H_
21 
22 #include <memory>
23 #include <mutex>
24 #include <map>
25 
26 namespace mir
27 {
28 namespace frontend
29 {
30 namespace detail
31 {
32 template<class Connection>
34 {
35 public:
38 
39  void add(std::shared_ptr<Connection> const& connection)
40  {
41  std::unique_lock<std::mutex> lock(mutex);
42  connections[connection->id()] = connection;
43  }
44 
45  void remove(int id)
46  {
47  std::unique_lock<std::mutex> lock(mutex);
48  connections.erase(id);
49  }
50 
51  bool includes(int id) const
52  {
53  std::unique_lock<std::mutex> lock(mutex);
54  return connections.find(id) != connections.end();
55  }
56 
57  void clear()
58  {
59  std::unique_lock<std::mutex> lock(mutex);
60  connections.clear();
61  }
62 
63 
64 private:
65  Connections(Connections const&) = delete;
66  Connections& operator =(Connections const&) = delete;
67 
68  std::mutex mutex;
69  std::map<int, std::shared_ptr<Connection>> connections;
70 };
71 }
72 }
73 }
74 
75 #endif // MIR_FRONTEND_CONNECTIONS_H_
All things Mir.
Definition: atomic_callback.h:25
void add(std::shared_ptr< Connection > const &connection)
Definition: connections.h:39
Connections()
Definition: connections.h:36
void clear()
Definition: connections.h:57
Definition: connections.h:33
bool includes(int id) const
Definition: connections.h:51
~Connections()
Definition: connections.h:37

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015