2 * Copyright © 2012-2014 Canonical Ltd.
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.
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.
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/>.
16 * Authored by: Alan Griffiths <alan@octopull.co.uk>
19 #ifndef ANBOX_NETWORK_CONNECTIONS_H_
20 #define ANBOX_NETWORK_CONNECTIONS_H_
28 template <class Connection>
32 ~Connections() { clear(); }
34 void add(std::shared_ptr<Connection> const& connection) {
35 std::unique_lock<std::mutex> lock(mutex);
36 connections.insert({connection->id(), connection});
40 std::unique_lock<std::mutex> lock(mutex);
41 connections.erase(id);
44 bool includes(int id) const {
45 std::unique_lock<std::mutex> lock(mutex);
46 return connections.find(id) != connections.end();
50 std::unique_lock<std::mutex> lock(mutex);
54 size_t size() { return connections.size(); }
56 std::shared_ptr<Connection> at(size_t n) { return connections.at(n); }
59 Connections(Connections const&) = delete;
60 Connections& operator=(Connections const&) = delete;
63 std::map<int, std::shared_ptr<Connection>> connections;
66 } // namespace network