2 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
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.
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.
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/>.
18 #include "anbox/qemu/camera_message_processor.h"
19 #include "anbox/logger.h"
23 CameraMessageProcessor::CameraMessageProcessor(
24 const std::shared_ptr<network::SocketMessenger> &messenger)
25 : messenger_(messenger) {}
27 CameraMessageProcessor::~CameraMessageProcessor() {}
29 bool CameraMessageProcessor::process_data(
30 const std::vector<std::uint8_t> &data) {
31 for (const auto &byte : data) buffer_.push_back(byte);
38 void CameraMessageProcessor::process_commands() {
39 while (buffer_.size() > 0) {
41 while (size < buffer_.size()) {
42 if (buffer_.at(size) == 0x0) break;
47 command.insert(0, reinterpret_cast<const char *>(buffer_.data()), size);
48 buffer_.erase(buffer_.begin(), buffer_.begin() + size + 1);
50 handle_command(command);
54 void CameraMessageProcessor::handle_command(const std::string &command) {
55 if (command == "list") list();
58 void CameraMessageProcessor::list() {
60 snprintf(buf, 5, "\n");
61 messenger_->send(buf, strlen(buf));