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_protobuf.pb.h"
23 #include "mir/fd.h"
24 
25 #include <map>
26 #include <memory>
27 #include <mutex>
28 
29 namespace mir
30 {
31 namespace frontend
32 {
33 
35 {
36 public:
37  virtual void save_resource(google::protobuf::Message* key, std::shared_ptr<void> const& value) = 0;
38  virtual void free_resource(google::protobuf::Message* key) = 0;
39  virtual void save_fd(google::protobuf::Message* key, Fd const& fd) = 0;
40 
41  virtual ~MessageResourceCache() = default;
42  MessageResourceCache() = default;
45 };
46 
47 // Used to save resources that must be retained until a call completes.
49 {
50 public:
51  void save_resource(google::protobuf::Message* key, std::shared_ptr<void> const& value);
52  void save_fd(google::protobuf::Message* key, Fd const& fd);
53  void free_resource(google::protobuf::Message* key);
54 
55 private:
56  typedef std::map<google::protobuf::Message*, std::shared_ptr<void>> Resources;
57  typedef std::multimap<google::protobuf::Message*, mir::Fd> FdResources;
58 
59  std::mutex guard;
60  Resources resources;
61  FdResources fd_resources;
62 };
63 
64 }
65 }
66 
67 #endif /* MIR_FRONTEND_RESOURCE_CACHE_H_ */
All things Mir.
Definition: buffer_stream.h:37
void free_resource(google::protobuf::Message *key)
Definition: resource_cache.cpp:37
virtual void save_resource(google::protobuf::Message *key, std::shared_ptr< void > const &value)=0
Definition: fd.h:33
Definition: resource_cache.h:34
virtual void save_fd(google::protobuf::Message *key, Fd const &fd)=0
MessageResourceCache & operator=(MessageResourceCache const &)=delete
Definition: resource_cache.h:48
virtual void free_resource(google::protobuf::Message *key)=0
void save_resource(google::protobuf::Message *key, std::shared_ptr< void > const &value)
Definition: resource_cache.cpp:21
void save_fd(google::protobuf::Message *key, Fd const &fd)
Definition: resource_cache.cpp:29
virtual ~MessageResourceCache()=default

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015