/* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_NDEBUG 0 #define LOG_TAG "C2ComponentWrapper" #include #include #include #include #include #include namespace android { namespace { using namespace std::chrono_literals; c2_status_t WrapSimpleMethod( std::function op, const SimpleMethodState &state) { c2_status_t result = C2_OK; switch (state.getMode()) { case SimpleMethodState::EXECUTE: result = op(); break; case SimpleMethodState::NO_OP: break; case SimpleMethodState::HANG: while (true) { std::this_thread::sleep_for(1s); } break; } (void)state.overrideResult(&result); return result; } } // namespace C2ComponentWrapper::Injecter::Injecter(C2ComponentWrapper *thiz) : mThiz(thiz) {} SimpleMethodState::Injecter C2ComponentWrapper::Injecter::start() { return SimpleMethodState::Injecter(&mThiz->mStartState); } C2ComponentWrapper::Listener::Listener( const std::shared_ptr &listener) : mListener(listener) {} void C2ComponentWrapper::Listener::onWorkDone_nb(std::weak_ptr component, std::list> workItems) { mListener->onWorkDone_nb(component, std::move(workItems)); } void C2ComponentWrapper::Listener::onTripped_nb(std::weak_ptr component, std::vector> settingResult) { mListener->onTripped_nb(component,settingResult); } void C2ComponentWrapper::Listener::onError_nb( std::weak_ptr component, uint32_t errorCode) { mListener->onError_nb(component, errorCode); } C2ComponentWrapper::C2ComponentWrapper( const std::shared_ptr &comp) : mComp(comp) {} c2_status_t C2ComponentWrapper::setListener_vb( const std::shared_ptr &listener, c2_blocking_t mayBlock) { mListener = std::make_shared(listener); return mComp->setListener_vb(mListener, mayBlock); } c2_status_t C2ComponentWrapper::queue_nb(std::list>* const items) { return mComp->queue_nb(items); } c2_status_t C2ComponentWrapper::announce_nb(const std::vector &items) { return mComp->announce_nb(items); } c2_status_t C2ComponentWrapper::flush_sm( C2Component::flush_mode_t mode, std::list>* const flushedWork) { return mComp->flush_sm(mode, flushedWork); } c2_status_t C2ComponentWrapper::drain_nb(C2Component::drain_mode_t mode) { return mComp->drain_nb(mode); } c2_status_t C2ComponentWrapper::start() { return WrapSimpleMethod([this] { return mComp->start(); }, mStartState); } c2_status_t C2ComponentWrapper::stop() { return mComp->stop(); } c2_status_t C2ComponentWrapper::reset() { return mComp->reset(); } c2_status_t C2ComponentWrapper::release() { return mComp->release(); } std::shared_ptr C2ComponentWrapper::intf(){ return mComp->intf(); } C2ComponentWrapper::Injecter C2ComponentWrapper::inject() { return Injecter(this); } } // namespace android