1/* sane - Scanner Access Now Easy. 2 3 Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt> 4 5 This file is part of the SANE package. 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the 10 License, or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <https://www.gnu.org/licenses/>. 19*/ 20 21#define DEBUG_DECLARE_ONLY 22 23#include "static_init.h" 24#include <vector> 25 26namespace genesys { 27 28static std::unique_ptr<std::vector<std::function<void()>>> s_functions_run_at_backend_exit; 29 30void add_function_to_run_at_backend_exit(const std::function<void()>& function) 31{ 32 if (!s_functions_run_at_backend_exit) 33 s_functions_run_at_backend_exit.reset(new std::vector<std::function<void()>>()); 34 s_functions_run_at_backend_exit->push_back(std::move(function)); 35} 36 37void run_functions_at_backend_exit() 38{ 39 if (s_functions_run_at_backend_exit) 40 { 41 for (auto it = s_functions_run_at_backend_exit->rbegin(); 42 it != s_functions_run_at_backend_exit->rend(); ++it) 43 { 44 (*it)(); 45 } 46 s_functions_run_at_backend_exit.reset(); 47 } 48} 49 50} // namespace genesys 51