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