1*edb230c4SIgor Ostapenko // Copyright 2024 The Kyua Authors. 2*edb230c4SIgor Ostapenko // All rights reserved. 3*edb230c4SIgor Ostapenko // 4*edb230c4SIgor Ostapenko // Redistribution and use in source and binary forms, with or without 5*edb230c4SIgor Ostapenko // modification, are permitted provided that the following conditions are 6*edb230c4SIgor Ostapenko // met: 7*edb230c4SIgor Ostapenko // 8*edb230c4SIgor Ostapenko // * Redistributions of source code must retain the above copyright 9*edb230c4SIgor Ostapenko // notice, this list of conditions and the following disclaimer. 10*edb230c4SIgor Ostapenko // * Redistributions in binary form must reproduce the above copyright 11*edb230c4SIgor Ostapenko // notice, this list of conditions and the following disclaimer in the 12*edb230c4SIgor Ostapenko // documentation and/or other materials provided with the distribution. 13*edb230c4SIgor Ostapenko // * Neither the name of Google Inc. nor the names of its contributors 14*edb230c4SIgor Ostapenko // may be used to endorse or promote products derived from this software 15*edb230c4SIgor Ostapenko // without specific prior written permission. 16*edb230c4SIgor Ostapenko // 17*edb230c4SIgor Ostapenko // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18*edb230c4SIgor Ostapenko // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19*edb230c4SIgor Ostapenko // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20*edb230c4SIgor Ostapenko // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21*edb230c4SIgor Ostapenko // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22*edb230c4SIgor Ostapenko // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23*edb230c4SIgor Ostapenko // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24*edb230c4SIgor Ostapenko // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25*edb230c4SIgor Ostapenko // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26*edb230c4SIgor Ostapenko // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27*edb230c4SIgor Ostapenko // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*edb230c4SIgor Ostapenko 29*edb230c4SIgor Ostapenko /// \file engine/prepare/prepare.hpp 30*edb230c4SIgor Ostapenko /// Requirement preparation subsystem interface. 31*edb230c4SIgor Ostapenko 32*edb230c4SIgor Ostapenko #if !defined(ENGINE_PREPARE_HPP) 33*edb230c4SIgor Ostapenko #define ENGINE_PREPARE_HPP 34*edb230c4SIgor Ostapenko 35*edb230c4SIgor Ostapenko #include <string> 36*edb230c4SIgor Ostapenko #include <vector> 37*edb230c4SIgor Ostapenko 38*edb230c4SIgor Ostapenko #include "utils/cmdline/parser.ipp" 39*edb230c4SIgor Ostapenko #include "utils/cmdline/ui.hpp" 40*edb230c4SIgor Ostapenko #include "utils/config/tree.ipp" 41*edb230c4SIgor Ostapenko 42*edb230c4SIgor Ostapenko namespace cmdline = utils::cmdline; 43*edb230c4SIgor Ostapenko namespace config = utils::config; 44*edb230c4SIgor Ostapenko 45*edb230c4SIgor Ostapenko 46*edb230c4SIgor Ostapenko namespace engine { 47*edb230c4SIgor Ostapenko namespace prepare { 48*edb230c4SIgor Ostapenko 49*edb230c4SIgor Ostapenko 50*edb230c4SIgor Ostapenko /// Abstract interface of a requirement preparation handler. 51*edb230c4SIgor Ostapenko class handler { 52*edb230c4SIgor Ostapenko public: 53*edb230c4SIgor Ostapenko /// Constructor. handler()54*edb230c4SIgor Ostapenko handler() {} 55*edb230c4SIgor Ostapenko 56*edb230c4SIgor Ostapenko /// Destructor. ~handler()57*edb230c4SIgor Ostapenko virtual ~handler() {} 58*edb230c4SIgor Ostapenko 59*edb230c4SIgor Ostapenko /// Returns name of the handler. 60*edb230c4SIgor Ostapenko virtual const std::string& name() const = 0; 61*edb230c4SIgor Ostapenko 62*edb230c4SIgor Ostapenko /// Returns short description of the handler. 63*edb230c4SIgor Ostapenko virtual const std::string& description() const = 0; 64*edb230c4SIgor Ostapenko 65*edb230c4SIgor Ostapenko /// Runs the requirement preparation handler. 66*edb230c4SIgor Ostapenko /// 67*edb230c4SIgor Ostapenko /// \param ui Object to interact with the I/O of the program. 68*edb230c4SIgor Ostapenko /// \param cmdline Representation of the command line to the subcommand. 69*edb230c4SIgor Ostapenko /// \param user_config The runtime configuration of the program. 70*edb230c4SIgor Ostapenko /// 71*edb230c4SIgor Ostapenko /// \return 0 to indicate success. 72*edb230c4SIgor Ostapenko virtual int exec(cmdline::ui* ui, 73*edb230c4SIgor Ostapenko const cmdline::parsed_cmdline& cmdline, 74*edb230c4SIgor Ostapenko const config::tree& user_config) const = 0; 75*edb230c4SIgor Ostapenko }; 76*edb230c4SIgor Ostapenko 77*edb230c4SIgor Ostapenko 78*edb230c4SIgor Ostapenko /// Registers a requirement preparation handler. 79*edb230c4SIgor Ostapenko /// 80*edb230c4SIgor Ostapenko /// \param handler A requirement preparation handler. 81*edb230c4SIgor Ostapenko void register_handler(const std::shared_ptr< handler > handler); 82*edb230c4SIgor Ostapenko 83*edb230c4SIgor Ostapenko 84*edb230c4SIgor Ostapenko /// Returns the list of registered requirement preparation handlers. 85*edb230c4SIgor Ostapenko /// 86*edb230c4SIgor Ostapenko /// \return A vector of pointers to requirement preparation handlers. 87*edb230c4SIgor Ostapenko const std::vector< std::shared_ptr< handler > > handlers(); 88*edb230c4SIgor Ostapenko 89*edb230c4SIgor Ostapenko 90*edb230c4SIgor Ostapenko /// Run named handlers. 91*edb230c4SIgor Ostapenko /// 92*edb230c4SIgor Ostapenko /// \param handler_names Names of the handlers to run. 93*edb230c4SIgor Ostapenko /// \param ui Object to interact with the I/O of the program. 94*edb230c4SIgor Ostapenko /// \param cmdline Representation of the command line to the subcommand. 95*edb230c4SIgor Ostapenko /// \param user_config The runtime configuration of the program. 96*edb230c4SIgor Ostapenko /// 97*edb230c4SIgor Ostapenko /// \return 0 to indicate success. 98*edb230c4SIgor Ostapenko int run(const std::vector< std::string >& handler_names, 99*edb230c4SIgor Ostapenko cmdline::ui* ui, 100*edb230c4SIgor Ostapenko const cmdline::parsed_cmdline& cmdline, 101*edb230c4SIgor Ostapenko const config::tree& user_config); 102*edb230c4SIgor Ostapenko 103*edb230c4SIgor Ostapenko 104*edb230c4SIgor Ostapenko } // namespace prepare 105*edb230c4SIgor Ostapenko } // namespace engine 106*edb230c4SIgor Ostapenko 107*edb230c4SIgor Ostapenko #endif // !defined(ENGINE_PREPARE_HPP) 108