TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / rpc / message_processor.h
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
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, as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranties of
10  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11  * PURPOSE.  See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 #ifndef ANBOX_RPC_MESSAGE_PROCESSOR_H_
19 #define ANBOX_RPC_MESSAGE_PROCESSOR_H_
20
21 #include "anbox/network/message_processor.h"
22 #include "anbox/network/message_sender.h"
23 #include "anbox/rpc/pending_call_cache.h"
24
25 #include <memory>
26
27 #include <google/protobuf/message_lite.h>
28 #include <google/protobuf/stubs/common.h>
29
30 namespace anbox {
31 namespace protobuf {
32 namespace rpc {
33 class Invocation;
34 }  // namespace rpc
35 }  // namespace protobuf
36 namespace rpc {
37 class Invocation {
38  public:
39   Invocation(anbox::protobuf::rpc::Invocation const& invocation)
40       : invocation_(invocation) {}
41
42   const ::std::string& method_name() const;
43   const ::std::string& parameters() const;
44   google::protobuf::uint32 id() const;
45
46  private:
47   anbox::protobuf::rpc::Invocation const& invocation_;
48 };
49
50 class MessageProcessor : public network::MessageProcessor {
51  public:
52   MessageProcessor(const std::shared_ptr<network::MessageSender>& sender,
53                    const std::shared_ptr<PendingCallCache>& pending_calls);
54   ~MessageProcessor();
55
56   bool process_data(const std::vector<std::uint8_t>& data) override;
57
58   void send_response(::google::protobuf::uint32 id,
59                      google::protobuf::MessageLite* response);
60
61   virtual void dispatch(Invocation const&) {}
62   virtual void process_event_sequence(const std::string&) {}
63
64  private:
65   std::shared_ptr<network::MessageSender> sender_;
66   std::vector<std::uint8_t> buffer_;
67   std::shared_ptr<PendingCallCache> pending_calls_;
68 };
69 }  // namespace rpc
70 }  // namespace anbox
71
72 #endif