00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */ 00002 00003 /* 00004 * Copyright (c) 2005, 2006, 2007, 2008 Ciaran McCreesh 00005 * Copyright (c) 2007 Piotr JaroszyĆski 00006 * 00007 * This file is part of the Paludis package manager. Paludis is free software; 00008 * you can redistribute it and/or modify it under the terms of the GNU General 00009 * Public License version 2, as published by the Free Software Foundation. 00010 * 00011 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY 00012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00014 * details. 00015 * 00016 * You should have received a copy of the GNU General Public License along with 00017 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00018 * Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 00021 #ifndef PALUDIS_GUARD_PALUDIS_HOOK_HH 00022 #define PALUDIS_GUARD_PALUDIS_HOOK_HH 1 00023 00024 #include <paludis/hook-fwd.hh> 00025 #include <paludis/environment-fwd.hh> 00026 #include <paludis/util/attributes.hh> 00027 #include <paludis/util/graph-fwd.hh> 00028 #include <paludis/util/private_implementation_pattern.hh> 00029 #include <paludis/util/wrapped_forward_iterator-fwd.hh> 00030 #include <paludis/util/sequence-fwd.hh> 00031 #include <paludis/util/named_value.hh> 00032 #include <tr1/memory> 00033 #include <string> 00034 00035 /** \file 00036 * Declarations for the Hook classes. 00037 * 00038 * \ingroup g_hooks 00039 * 00040 * \section Examples 00041 * 00042 * - None at this time. 00043 */ 00044 00045 namespace paludis 00046 { 00047 namespace n 00048 { 00049 struct max_exit_status; 00050 struct output; 00051 } 00052 00053 /** 00054 * Result of a Hook. 00055 * 00056 * \see Hook 00057 * \ingroup g_hooks 00058 * \nosubgrouping 00059 */ 00060 struct HookResult 00061 { 00062 NamedValue<n::max_exit_status, int> max_exit_status; 00063 NamedValue<n::output, std::string> output; 00064 }; 00065 00066 /** 00067 * Represents the data for a hook call. 00068 * 00069 * \see Environment::perform_hook 00070 * \ingroup g_hooks 00071 * \nosubgrouping 00072 */ 00073 class PALUDIS_VISIBLE Hook : 00074 private PrivateImplementationPattern<Hook> 00075 { 00076 public: 00077 ///\name Basic operations 00078 ///\{ 00079 00080 class AllowedOutputValues; 00081 00082 HookOutputDestination output_dest; 00083 00084 Hook(const std::string & name); 00085 00086 Hook(const Hook &); 00087 00088 ~Hook(); 00089 00090 ///\} 00091 00092 /// Add data to the hook. 00093 Hook operator() (const std::string & key, const std::string & value) const 00094 PALUDIS_ATTRIBUTE((warn_unused_result)); 00095 00096 /// Get data from the hook. 00097 std::string get(const std::string & key) const 00098 PALUDIS_ATTRIBUTE((warn_unused_result)); 00099 00100 Hook grab_output(const AllowedOutputValues & av); 00101 00102 bool validate_value(const std::string & value) const; 00103 00104 ///\name Iterate over environment data 00105 ///\{ 00106 00107 struct ConstIteratorTag; 00108 typedef WrappedForwardIterator<ConstIteratorTag, const std::pair<const std::string, std::string> > ConstIterator; 00109 00110 ConstIterator begin() const 00111 PALUDIS_ATTRIBUTE((warn_unused_result)); 00112 00113 ConstIterator end() const 00114 PALUDIS_ATTRIBUTE((warn_unused_result)); 00115 00116 ///\} 00117 00118 /// Our name. 00119 std::string name() const 00120 PALUDIS_ATTRIBUTE((warn_unused_result)); 00121 }; 00122 00123 /** 00124 * Hooks with grabbed output can specify that only certain output values are 00125 * allowed. 00126 * 00127 * \ingroup g_hooks 00128 * \since 0.26 00129 * \nosubgrouping 00130 */ 00131 class PALUDIS_VISIBLE Hook::AllowedOutputValues : 00132 private PrivateImplementationPattern<Hook::AllowedOutputValues> 00133 { 00134 friend class Hook; 00135 00136 public: 00137 ///\name Basic operations 00138 ///\{ 00139 00140 AllowedOutputValues(); 00141 00142 AllowedOutputValues(const AllowedOutputValues & other); 00143 00144 ~AllowedOutputValues(); 00145 00146 ///\} 00147 00148 /// Add a new allowed value. 00149 AllowedOutputValues operator() (const std::string & v) const 00150 PALUDIS_ATTRIBUTE((warn_unused_result)); 00151 }; 00152 } 00153 00154 extern "C" paludis::HookResult PALUDIS_VISIBLE paludis_hook_run( 00155 const paludis::Environment *, const paludis::Hook &); 00156 00157 extern "C" void PALUDIS_VISIBLE paludis_hook_add_dependencies( 00158 const paludis::Environment *, const paludis::Hook &, paludis::DirectedGraph<std::string, int> &); 00159 00160 extern "C" const std::tr1::shared_ptr<const paludis::Sequence<std::string> > PALUDIS_VISIBLE paludis_hook_auto_phases( 00161 const paludis::Environment *); 00162 00163 #endif