X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Frpc%2Fconnection_creator.cpp;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Frpc%2Fconnection_creator.cpp;h=2f3f864949e1ef1ec2f304245d7ab7256928d318;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git diff --git a/src/type3_AndroidCloud/anbox-master/src/anbox/rpc/connection_creator.cpp b/src/type3_AndroidCloud/anbox-master/src/anbox/rpc/connection_creator.cpp new file mode 100644 index 0000000..2f3f864 --- /dev/null +++ b/src/type3_AndroidCloud/anbox-master/src/anbox/rpc/connection_creator.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#include "anbox/rpc/connection_creator.h" +#include "anbox/logger.h" +#include "anbox/network/local_socket_messenger.h" +#include "anbox/rpc/message_processor.h" + +#include + +namespace ba = boost::asio; + +namespace anbox { +namespace rpc { +ConnectionCreator::ConnectionCreator(const std::shared_ptr& rt, + const MessageProcessorFactory& factory) + : runtime_(rt), + next_connection_id_(0), + connections_( + std::make_shared>()), + message_processor_factory_(factory) {} + +ConnectionCreator::~ConnectionCreator() noexcept {} + +void ConnectionCreator::create_connection_for( + std::shared_ptr const& + socket) { + if (connections_->size() >= 1) { + socket->close(); + WARNING( + "A second client tried to connect. Denied request as we already have " + "one and only allow a single client"); + return; + } + + auto const messenger = + std::make_shared(socket); + auto const processor = message_processor_factory_(messenger); + + auto const& connection = std::make_shared( + messenger, messenger, next_id(), connections_, processor); + connection->set_name("rpc"); + connections_->add(connection); + connection->read_next_message(); +} + +int ConnectionCreator::next_id() { return next_connection_id_.fetch_add(1); } + +} // namespace rpc +} // namespace anbox