Mir
resource_cache.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012 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_RESOURCE_CACHE_H_
20 #define MIR_FRONTEND_RESOURCE_CACHE_H_
21 
22 #include "mir/fd.h"
23 
24 #include <map>
25 #include <memory>
26 #include <mutex>
27 
28 namespace google {
29 namespace protobuf
30 {
31 class MessageLite;
32 }
33 }
34 
35 namespace mir
36 {
37 namespace frontend
38 {
39 
41 {
42 public:
43  virtual void save_resource(google::protobuf::MessageLite* key, std::shared_ptr<void> const& value) = 0;
44  virtual void free_resource(google::protobuf::MessageLite* key) = 0;
45  virtual void save_fd(google::protobuf::MessageLite* key, Fd const& fd) = 0;
46 
47  virtual ~MessageResourceCache() = default;
48  MessageResourceCache() = default;
50  MessageResourceCache& operator=(MessageResourceCache const&) = delete;
51 };
52 
53 // Used to save resources that must be retained until a call completes.
55 {
56 public:
57  void save_resource(google::protobuf::MessageLite* key, std::shared_ptr<void> const& value);
58  void save_fd(google::protobuf::MessageLite* key, Fd const& fd);
59  void free_resource(google::protobuf::MessageLite* key);
60 
61 private:
62  typedef std::map<google::protobuf::MessageLite*, std::shared_ptr<void>> Resources;
63  typedef std::multimap<google::protobuf::MessageLite*, mir::Fd> FdResources;
64 
65  std::mutex guard;
66  Resources resources;
67  FdResources fd_resources;
68 };
69 
70 }
71 }
72 
73 #endif /* MIR_FRONTEND_RESOURCE_CACHE_H_ */
All things Mir.
Definition: atomic_callback.h:25
Definition: fd.h:33
Definition: resource_cache.h:40
Definition: resource_cache.h:54
Definition: buffer_stream.h:37

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016