1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/PluginScript.h
12 #ifndef ZYPP_PLUGINSCRIPT_H
13 #define ZYPP_PLUGINSCRIPT_H
19 #include "zypp/base/PtrTypes.h"
20 #include "zypp/Pathname.h"
22 #include "zypp/PluginFrame.h"
23 #include "zypp/PluginScriptException.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 // CLASS NAME : PluginScript
34 * \brief Interface to pluigin scripts using a \c Stomp inspired communication protocol
36 * \note \ref PluginScript is copyable and assignable, but the connection is shared
37 * among multiple copies. It gets automatically closed if the last copy goes out of
41 * // Setup comnnection to plugin script
43 * PluginScript::Arguments args;
44 * args.push_back( "-v" );
45 * scr.open( "/soem/testplugin", args );
47 * // send frame to plugin
48 * PluginFrame f( "COMMAND" );
49 * f.setHeader( "key", "value" );
50 * f.setBody( "some\ndata" );
53 * // receive frame from plugin
54 * PluginFrame r( scr.receive() );
56 * // explicitly close or let PluginScript go out of scope
60 * \see http://stomp.codehaus.org/
64 friend std::ostream & operator<<( std::ostream & str, const PluginScript & obj );
67 /** Commandline arguments passed to a script on \ref open */
68 typedef std::vector<std::string> Arguments;
70 /** \c pid_t(-1) constant indicating no connection */
71 static const pid_t NotConnected = -1;
77 /** Ctor taking script path and no arguments */
78 PluginScript( const Pathname & script_r );
80 /** Ctor taking script path and script arguments */
81 PluginScript( const Pathname & script_r, const Arguments & args_r );
84 /** Return the script path if set */
85 const Pathname & script() const;
87 /** Return the script arguments if set */
88 const Arguments & args() const;
90 /** Whether we are connected to a script */
93 /** Return a connected scripts pid or \ref NotConnected */
97 /** Setup connection and execute script
98 * \throw PluginScriptException if already connected to a script
99 * \throw PluginScriptException if script does not exist or is not executable
100 * \throw PluginScriptException on error
104 /** \overload taking script path and no arguments */
105 void open( const Pathname & script_r );
107 /** \overload taking script path and script arguments */
108 void open( const Pathname & script_r, const Arguments & args_r );
110 /** Close any open connection. */
114 /** Send a \ref PluginFrame
115 * \throw PluginScriptException on error
117 void send( const PluginFrame & frame_r ) const;
119 /** Receive a \ref PluginFrame
120 * \throw PluginScriptException on error
122 PluginFrame receive() const;
125 /** Implementation */
128 /** Pointer to implementation */
129 RW_pointer<Impl> _pimpl;
131 ///////////////////////////////////////////////////////////////////
133 /** \relates PluginScript Stream output */
134 std::ostream & operator<<( std::ostream & str, const PluginScript & obj );
136 /////////////////////////////////////////////////////////////////
138 ///////////////////////////////////////////////////////////////////
139 #endif // ZYPP_PLUGINSCRIPT_H