Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
protobuf_message_processor.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 
20 #ifndef MIR_FRONTEND_PROTOBUF_MESSAGE_PROCESSOR_H_
21 #define MIR_FRONTEND_PROTOBUF_MESSAGE_PROCESSOR_H_
22 
23 #include "fd_sets.h"
24 
25 #include "message_processor.h"
26 #include "message_sender.h"
27 
28 #include "mir_protobuf.pb.h"
29 #include "mir_protobuf_wire.pb.h"
31 
32 #include <vector>
33 #include <memory>
34 #include <iosfwd>
35 #include <cstdint>
36 
37 namespace mir
38 {
39 namespace protobuf { class DisplayServer; }
40 
41 namespace frontend
42 {
43 class ResourceCache;
44 class MessageProcessorReport;
45 
46 namespace detail
47 {
48 
50 {
51 public:
53  std::shared_ptr<MessageSender> const& sender,
54  std::shared_ptr<protobuf::DisplayServer> const& display_server,
55  std::shared_ptr<ResourceCache> const& resource_cache,
56  std::shared_ptr<MessageProcessorReport> const& report);
57 
59 
60 private:
61  void send_response(::google::protobuf::uint32 id, google::protobuf::Message* response);
62  void send_response(::google::protobuf::uint32 id, google::protobuf::Message* response,
63  FdSets const& fd_sets);
64 
65  template<class ResultMessage>
66  void send_response(::google::protobuf::uint32 id, ResultMessage* response);
67 
68  // TODO detecting the message type to see if we send FDs seems a bit of a frig.
69  // OTOH until we have a real requirement it is hard to see how best to generalise.
70  void send_response(::google::protobuf::uint32 id, mir::protobuf::Buffer* response);
71 
72  // TODO detecting the message type to see if we send FDs seems a bit of a frig.
73  // OTOH until we have a real requirement it is hard to see how best to generalise.
74  void send_response(::google::protobuf::uint32 id, mir::protobuf::Connection* response);
75 
76  // TODO detecting the message type to see if we send FDs seems a bit of a frig.
77  // OTOH until we have a real requirement it is hard to see how best to generalise.
78  void send_response(::google::protobuf::uint32 id, mir::protobuf::Surface* response);
79 
80  template<class Response>
81  std::vector<int32_t> extract_fds_from(Response* response);
82 
83  bool process_message(std::istream& msg);
84 
85  bool dispatch(mir::protobuf::wire::Invocation const& invocation);
86 
87  template<class ParameterMessage, class ResultMessage>
88  void invoke(
89  void (protobuf::DisplayServer::*function)(
90  ::google::protobuf::RpcController* controller,
91  const ParameterMessage* request,
92  ResultMessage* response,
93  ::google::protobuf::Closure* done),
94  mir::protobuf::wire::Invocation const& invocation);
95 
96  std::shared_ptr<MessageSender> const sender;
97  std::shared_ptr<protobuf::DisplayServer> const display_server;
98  std::shared_ptr<ResourceCache> const resource_cache;
99  std::shared_ptr<MessageProcessorReport> const report;
100 
101  std::string send_response_buffer;
102  mir::protobuf::wire::Result send_response_result;
103 };
104 }
105 }
106 }
107 
108 #endif /* PROTOBUF_MESSAGE_PROCESSOR_H_ */

Copyright © 2012,2013 Canonical Ltd.
Generated on Wed Oct 30 18:52:19 UTC 2013