X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Frpc%2Fpending_call_cache.cpp;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Frpc%2Fpending_call_cache.cpp;h=15094f816b607018eaadd482294e2c333518e0e0;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git diff --git a/src/type3_AndroidCloud/anbox-master/src/anbox/rpc/pending_call_cache.cpp b/src/type3_AndroidCloud/anbox-master/src/anbox/rpc/pending_call_cache.cpp new file mode 100644 index 0000000..15094f8 --- /dev/null +++ b/src/type3_AndroidCloud/anbox-master/src/anbox/rpc/pending_call_cache.cpp @@ -0,0 +1,76 @@ +/* + * Copyright © 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser 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 warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Authored by: Alan Griffiths + */ + +#include "anbox/rpc/pending_call_cache.h" + +#include "anbox_rpc.pb.h" + +#ifdef USE_PROTOBUF_CALLBACK_HEADER +#include +#endif + +namespace anbox { +namespace rpc { +PendingCallCache::PendingCallCache() {} + +void PendingCallCache::save_completion_details( + anbox::protobuf::rpc::Invocation const& invocation, + google::protobuf::MessageLite* response, + google::protobuf::Closure* complete) { + std::unique_lock lock(mutex_); + pending_calls_[invocation.id()] = PendingCall(response, complete); +} + +void PendingCallCache::populate_message_for_result( + anbox::protobuf::rpc::Result& result, + std::function const& populator) { + std::unique_lock lock(mutex_); + populator(pending_calls_.at(result.id()).response); +} + +void PendingCallCache::complete_response(anbox::protobuf::rpc::Result& result) { + PendingCall completion; + + { + std::unique_lock lock(mutex_); + auto call = pending_calls_.find(result.id()); + if (call != pending_calls_.end()) { + completion = call->second; + pending_calls_.erase(call); + } + } + + if (completion.complete) completion.complete->Run(); +} + +void PendingCallCache::force_completion() { + std::unique_lock lock(mutex_); + for (auto& call : pending_calls_) { + auto& completion = call.second; + completion.complete->Run(); + } + + pending_calls_.erase(pending_calls_.begin(), pending_calls_.end()); +} + +bool PendingCallCache::empty() const { + std::unique_lock lock(mutex_); + return pending_calls_.empty(); +} +} // namespace rpc +} // namespace anbox