fixup Fix to build with libxml 2.12.x (fixes #505)
[platform/upstream/libzypp.git] / zypp / PluginExecutor.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/PluginExecutor.h
10  */
11 #ifndef ZYPP_PLUGINEXECUTOR_H
12 #define ZYPP_PLUGINEXECUTOR_H
13
14 #include <iosfwd>
15
16 #include "zypp/base/PtrTypes.h"
17 #include "zypp/PluginScript.h"
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 {
22   ///////////////////////////////////////////////////////////////////
23   /// \class PluginExecutor
24   /// \brief Parallel execution of stateful PluginScripts
25   ///
26   /// Sent PluginFrames are distributed to all open PluginScripts and
27   /// need to be receipted by sending back either \c ACK or \c _ENOMETHOD
28   /// command.
29   ///
30   /// All PluginScripts receive an initial \c PLUGINBEGIN frame, containing
31   /// a \c userdata header if \ref ZConfig::userData are defined.
32   /// \see also zypper '--userdata' option
33   ///
34   /// A final \c PLUGINEND frame is sent and open scripts are closed, when the
35   /// executors last reference goes out of scope. Failing PluginScripts are
36   /// closed immediately.
37   ///
38   /// \see PluginScript
39   /// \ingroup g_RAII
40   ///////////////////////////////////////////////////////////////////
41   class PluginExecutor
42   {
43     friend std::ostream & operator<<( std::ostream & str, const PluginExecutor & obj );
44     friend bool operator==( const PluginExecutor & lhs, const PluginExecutor & rhs );
45
46     public:
47       /** Default ctor: Empty plugin list */
48       PluginExecutor();
49
50       /** Dtor: Send \c PLUGINEND and close all plugins */
51       ~PluginExecutor();
52
53     public:
54       /**  Validate object in a boolean context: There are plugins waiting for input */
55       explicit operator bool() const
56       { return !empty(); }
57
58       /** Whether no plugins are waiting */
59       bool empty() const;
60
61       /** Number of open plugins */
62       size_t size() const;
63
64     public:
65       /** Find and launch plugins sending \c PLUGINBEGIN.
66        *
67        * If \a path_r is a directory all executable files within are
68        * expected to be plugins. Otherwise \a path_r must point to an
69        * executable plugin.
70        */
71       void load( const Pathname & path_r );
72
73       /** Send \ref PluginFrame to all open plugins.
74        * Failed plugins are removed from the execution list.
75        */
76       void send( const PluginFrame & frame_r );
77
78     public:
79       class Impl;               ///< Implementation class.
80     private:
81       RW_pointer<Impl> _pimpl;  ///< Pointer to implementation.
82   };
83
84   /** \relates PluginExecutor Stream output */
85   std::ostream & operator<<( std::ostream & str, const PluginExecutor & obj );
86
87   /** \relates PluginExecutor Comparison based on reference. */
88   inline bool operator==( const PluginExecutor & lhs, const PluginExecutor & rhs )
89   { return ( lhs._pimpl == rhs._pimpl ); }
90
91   /** \relates PluginExecutor Comparison based on reference. */
92   inline bool operator!=( const PluginExecutor & lhs, const PluginExecutor & rhs )
93   { return( ! operator==( lhs, rhs ) ); }
94
95 } // namespace zypp
96 ///////////////////////////////////////////////////////////////////
97 #endif // ZYPP_PLUGINEXECUTOR_H