libzypp: zypp::PluginScript Class Reference

libzypp 17.38.7

zypp::PluginScript Class Reference

Interface to plugin scripts using a `Stomp` inspired communication protocol. More...

`#include <zypp/PluginScript.h>`

## Classes
struct | Impl
| PluginScript implementation. More...

## Public Types
using | Arguments = std::vector<std::string>
| Commandline arguments passed to a script on open.

## Static Public Attributes
static const pid_t | NotConnected
| `pid_t`(-1) constant indicating no connection.

## Friends
std::ostream & | operator<< (std::ostream &str, const PluginScript &obj)
| relates: PluginScript Stream output

## Get/set local timeout settings.
RW_pointer< Impl > | _pimpl
| Pointer to implementation.
long | sendTimeout () const
| Local default timeout (sec.) when sending data.
long | receiveTimeout () const
| Local default timeout (sec.) when receiving data.
void | sendTimeout (long newval_r)
| Set local default timeout (sec.) when sending data.
void | receiveTimeout (long newval_r)
| Set local default timeout (sec.) when receiving data.
void | timeout (long newval_r)
| Set local default timeout (sec.) (both: send and receive).
void | open ()
| Setup connection and execute script.
void | open (const Pathname &script_r)
void | open (const Pathname &script_r, const Arguments &args_r)
int | close ()
| Close any open connection.
void | send (const PluginFrame &frame_r) const
| Send a PluginFrame.
PluginFrame | receive () const
| Receive a PluginFrame.

## Get/set the global timeout settings.
Timeout when sending/receiving data to/from a plugin default to 30 sec. The value (in seconds) my be changed via the environment variables `ZYPP_PLUGIN_SEND_TIMEOUT`, `ZYPP_PLUGIN_RECEIVE_TIMEOUT` or `ZYPP_PLUGIN_TIMEOUT` (both: send and receive).
static long | defaultSendTimeout ()
| Global default timeout (sec.) when sending data.
static long | defaultReceiveTimeout ()
| Global default timeout (sec.) when receiving data.
static void | defaultSendTimeout (long newval_r)
| Set global default timeout (sec.) when sending data.
static void | defaultReceiveTimeout (long newval_r)
| Set global default timeout (sec.) when receiving data.
static void | defaultTimeout (long newval_r)
| Set global default timeout (sec.) (both: send and receive).
| PluginScript ()
| Default ctor.
| PluginScript (Pathname script_r)
| Ctor taking script path and no arguments.
| PluginScript (Pathname script_r, Arguments args_r)
| Ctor taking script path and script arguments.
const Pathname & | script () const
| Return the script path if set.
const Arguments & | args () const
| Return the script arguments if set.
bool | isOpen () const
| Whether we are connected to a script.
pid_t | getPid () const
| Return a connected scripts pid or NotConnected.
int | lastReturn () const
| Remembers a scripts return value after close until next open.
const std::string & | lastExecError () const
| Remembers a scripts execError string after close until next open.

## Detailed Description

Interface to plugin scripts using a `Stomp` inspired communication protocol.

Note
  PluginScript is copyable and assignable, but the connection is shared among multiple copies. It gets automatically closed if the last copy goes out of scope.

Timeout when sending/receiving data to/from a plugin default to 30 sec. The value (in seconds) my be changed via the environment variables `ZYPP_PLUGIN_SEND_TIMEOUT`, `ZYPP_PLUGIN_RECEIVE_TIMEOUT` or `ZYPP_PLUGIN_TIMEOUT` (both: send and receive).

// Setup comnnection to plugin script
PluginScript scr;
PluginScript::Arguments args;
args.push_back( "-v" );
scr.open( "/soem/testplugin", args );
// send frame to plugin
PluginFrame f( "COMMAND" );
f.setHeader( "key", "value" );
f.setBody( "some\ndata" );
scr.send( f );
// receive frame from plugin
PluginFrame r( scr.receive() );
// explicitly close or let PluginScript go out of scope
scr.close();
zypp::PluginFrame
Command frame for communication with PluginScript.
Definition PluginFrame.h:42
zypp::PluginScript::receive
PluginFrame receive() const
Receive a PluginFrame.
Definition PluginScript.cc:522
zypp::PluginScript::Arguments
std::vector< std::string > Arguments
Commandline arguments passed to a script on open.
Definition PluginScript.h:68
zypp::PluginScript::send
void send(const PluginFrame &frame_r) const
Send a PluginFrame.
Definition PluginScript.cc:519
zypp::PluginScript::PluginScript
PluginScript()
Default ctor.
Definition PluginScript.cc:477
zypp::PluginScript::close
int close()
Close any open connection.
Definition PluginScript.cc:516
zypp::PluginScript::open
void open()
Setup connection and execute script.
Definition PluginScript.cc:507
zypp::PluginScript::args
const Arguments & args() const
Return the script arguments if set.
Definition PluginScript.cc:492

See also
  https://stomp.github.io

Definition at line 62 of file PluginScript.h.

## Member Typedef Documentation

## ◆ Arguments

using zypp::PluginScript::Arguments = std::vector<std::string>

Commandline arguments passed to a script on open.

Definition at line 68 of file PluginScript.h.

## Constructor & Destructor Documentation

## ◆ PluginScript() [1/3]

zypp::PluginScript::PluginScript | ( |  | ) |

Default ctor.

Definition at line 477 of file PluginScript.cc.

## ◆ PluginScript() [2/3]

zypp::PluginScript::PluginScript | ( | Pathname | script_r | ) |

Ctor taking script path and no arguments.

Definition at line 481 of file PluginScript.cc.

## ◆ PluginScript() [3/3]

zypp::PluginScript::PluginScript | ( | Pathname | script_r,
|  | Arguments | args_r )

Ctor taking script path and script arguments.

Definition at line 485 of file PluginScript.cc.

## Member Function Documentation

## ◆ defaultSendTimeout() [1/2]

long zypp::PluginScript::defaultSendTimeout | ( |  | ) |
| static

Global default timeout (sec.) when sending data.

Definition at line 453 of file PluginScript.cc.

## ◆ defaultReceiveTimeout() [1/2]

long zypp::PluginScript::defaultReceiveTimeout | ( |  | ) |
| static

Global default timeout (sec.) when receiving data.

Definition at line 456 of file PluginScript.cc.

## ◆ defaultSendTimeout() [2/2]

void zypp::PluginScript::defaultSendTimeout | ( | long | newval_r | ) |
| static

Set global default timeout (sec.) when sending data.

Definition at line 459 of file PluginScript.cc.

## ◆ defaultReceiveTimeout() [2/2]

void zypp::PluginScript::defaultReceiveTimeout | ( | long | newval_r | ) |
| static

Set global default timeout (sec.) when receiving data.

Definition at line 462 of file PluginScript.cc.

## ◆ defaultTimeout()

void zypp::PluginScript::defaultTimeout | ( | long | newval_r | ) |
| inlinestatic

Set global default timeout (sec.) (both: send and receive).

Definition at line 93 of file PluginScript.h.

## ◆ script()

const Pathname & zypp::PluginScript::script | ( |  | ) | const

Return the script path if set.

Definition at line 489 of file PluginScript.cc.

## ◆ args()

const PluginScript::Arguments & zypp::PluginScript::args | ( |  | ) | const

Return the script arguments if set.

Definition at line 492 of file PluginScript.cc.

## ◆ isOpen()

bool zypp::PluginScript::isOpen | ( |  | ) | const

Whether we are connected to a script.

Definition at line 495 of file PluginScript.cc.

## ◆ getPid()

pid_t zypp::PluginScript::getPid | ( |  | ) | const

Return a connected scripts pid or NotConnected.

Definition at line 498 of file PluginScript.cc.

## ◆ lastReturn()

int zypp::PluginScript::lastReturn | ( |  | ) | const

Remembers a scripts return value after close until next open.

Definition at line 501 of file PluginScript.cc.

## ◆ lastExecError()

const std::string & zypp::PluginScript::lastExecError | ( |  | ) | const

Remembers a scripts execError string after close until next open.

See also
  ExternalProgram::execError.

Definition at line 504 of file PluginScript.cc.

## ◆ sendTimeout() [1/2]

long zypp::PluginScript::sendTimeout | ( |  | ) | const

Local default timeout (sec.) when sending data.

Definition at line 465 of file PluginScript.cc.

## ◆ receiveTimeout() [1/2]

long zypp::PluginScript::receiveTimeout | ( |  | ) | const

Local default timeout (sec.) when receiving data.

Definition at line 468 of file PluginScript.cc.

## ◆ sendTimeout() [2/2]

void zypp::PluginScript::sendTimeout | ( | long | newval_r | ) |

Set local default timeout (sec.) when sending data.

Definition at line 471 of file PluginScript.cc.

## ◆ receiveTimeout() [2/2]

void zypp::PluginScript::receiveTimeout | ( | long | newval_r | ) |

Set local default timeout (sec.) when receiving data.

Definition at line 474 of file PluginScript.cc.

## ◆ timeout()

void zypp::PluginScript::timeout | ( | long | newval_r | ) |
| inline

Set local default timeout (sec.) (both: send and receive).

Definition at line 144 of file PluginScript.h.

## ◆ open() [1/3]

void zypp::PluginScript::open | ( |  | ) |

Setup connection and execute script.

Exceptions

  PluginScriptException | if already connected to a script
  PluginScriptException | if script does not exist or is not executable
  PluginScriptException | on error

Definition at line 507 of file PluginScript.cc.

## ◆ open() [2/3]

void zypp::PluginScript::open | ( | const Pathname & | script_r | ) |

Definition at line 510 of file PluginScript.cc.

## ◆ open() [3/3]

void zypp::PluginScript::open | ( | const Pathname & | script_r,
|  | const Arguments & | args_r )

Definition at line 513 of file PluginScript.cc.

## ◆ close()

int zypp::PluginScript::close | ( |  | ) |

Close any open connection.

Definition at line 516 of file PluginScript.cc.

## ◆ send()

void zypp::PluginScript::send | ( | const PluginFrame & | frame_r | ) | const

Send a PluginFrame.

Exceptions

  PluginScriptNotConnected |
  PluginScriptSendTimeout |
  PluginScriptDiedUnexpectedly | (does not close)
  PluginScriptException | on error

Definition at line 519 of file PluginScript.cc.

## ◆ receive()

PluginFrame zypp::PluginScript::receive | ( |  | ) | const

Receive a PluginFrame.

Exceptions

  PluginScriptNotConnected |
  PluginScriptReceiveTimeout |
  PluginScriptDiedUnexpectedly | (does not close)
  PluginScriptException | on error

Definition at line 522 of file PluginScript.cc.

## Friends And Related Symbol Documentation

## ◆ operator<<

std::ostream & operator<< | ( | std::ostream & | str,
|  | const PluginScript & | obj )
| friend

relates: PluginScript Stream output

Definition at line 527 of file PluginScript.cc.

## Member Data Documentation

## ◆ NotConnected

const pid_t zypp::PluginScript::NotConnected
| static

`pid_t`(-1) constant indicating no connection.

Definition at line 71 of file PluginScript.h.

## ◆ _pimpl

RW_pointer<Impl> zypp::PluginScript::_pimpl
| private

Pointer to implementation.

Definition at line 188 of file PluginScript.h.

The documentation for this class was generated from the following files:

- zypp/PluginScript.h
- zypp/PluginScript.cc