TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / bridge / platform_message_processor.cpp
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 #include "anbox/bridge/platform_message_processor.h"
19 #include "anbox/bridge/platform_api_skeleton.h"
20 #include "anbox/logger.h"
21 #include "anbox/rpc/template_message_processor.h"
22
23 #include "anbox_bridge.pb.h"
24
25 namespace anbox {
26 namespace bridge {
27 PlatformMessageProcessor::PlatformMessageProcessor(
28     const std::shared_ptr<network::MessageSender> &sender,
29     const std::shared_ptr<PlatformApiSkeleton> &server,
30     const std::shared_ptr<rpc::PendingCallCache> &pending_calls)
31     : rpc::MessageProcessor(sender, pending_calls), server_(server) {}
32
33 PlatformMessageProcessor::~PlatformMessageProcessor() {}
34
35 void PlatformMessageProcessor::dispatch(rpc::Invocation const &invocation) {
36   if (invocation.method_name() == "set_clipboard_data")
37     invoke(this, server_.get(), &PlatformApiSkeleton::set_clipboard_data, invocation);
38   else if (invocation.method_name() == "get_clipboard_data")
39     invoke(this, server_.get(), &PlatformApiSkeleton::get_clipboard_data, invocation);
40 }
41
42 void PlatformMessageProcessor::process_event_sequence(
43     const std::string &raw_events) {
44   anbox::protobuf::bridge::EventSequence seq;
45   if (!seq.ParseFromString(raw_events)) {
46     WARNING("Failed to parse events from raw string");
47     return;
48   }
49
50   if (seq.has_boot_finished())
51     server_->handle_boot_finished_event(seq.boot_finished());
52
53   if (seq.has_window_state_update())
54     server_->handle_window_state_update_event(seq.window_state_update());
55
56   if (seq.has_application_list_update())
57     server_->handle_application_list_update_event(
58         seq.application_list_update());
59 }
60 }  // namespace anbox
61 }  // namespace network