Commit 17d0cca2 authored by Matthieu Kermagoret's avatar Matthieu Kermagoret
Browse files

Connector SSH: commander is ready to receive events.

parent 9baa8071
......@@ -23,6 +23,8 @@
# include "com/centreon/connector/ssh/namespace.hh"
# include "com/centreon/handle_listener.hh"
# include "com/centreon/io/standard_input.hh"
# include "com/centreon/io/standard_output.hh"
CCCS_BEGIN()
......@@ -32,14 +34,27 @@ CCCS_BEGIN()
*
* Handle check execution command from the monitoring engine.
*/
class commander : public com::centreon::handle_listener {
class commander : public handle_listener {
public:
commander();
~commander() throw ();
void close(handle& h);
void error(handle& h);
void read(handle& h);
void reg();
void unreg(bool all = true);
bool want_read(handle& h);
bool want_write(handle& h);
void write(handle& h);
private:
commander(commander const& c);
commander& operator=(commander const& c);
io::standard_input
_si;
io::standard_output
_so;
};
CCCS_END()
......
......@@ -19,9 +19,15 @@
*/
#include <assert.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "com/centreon/connector/ssh/commander.hh"
#include "com/centreon/connector/ssh/multiplexer.hh"
#include "com/centreon/exceptions/basic.hh"
#include "com/centreon/logging/logger.hh"
using namespace com::centreon;
using namespace com::centreon::connector::ssh;
/**************************************
......@@ -38,7 +44,101 @@ commander::commander() {}
/**
* Destructor.
*/
commander::~commander() throw () {}
commander::~commander() throw () {
unreg();
}
/**
* Close callback.
*
* @param[in,out] h Handle.
*/
void commander::close(handle& h) {
if (&h == &_so)
throw (basic_error() << "received close request on output");
else {
logging::error(logging::high) << "received close request on input";
logging::info(logging::high) << "sending termination request";
kill(getpid(), SIGTERM);
}
return ;
}
/**
* Error callback.
*
* @param[in,out] h Handle.
*/
void commander::error(handle& h) {
if (&h == &_so)
throw (basic_error() << "received error on output");
else {
logging::error(logging::high) << "received error on input";
logging::info(logging::high) << "sending termination request";
kill(getpid(), SIGTERM);
}
return ;
}
/**
* Read callback.
*
* @param[in,out] h Handle.
*/
void commander::read(handle& h) {
// XXX
}
/**
* Register commander with multiplexer.
*/
void commander::reg() {
unreg();
multiplexer::instance().handle_manager::add(&_si, this);
multiplexer::instance().handle_manager::add(&_so, this);
return ;
}
/**
* Unregister commander with multiplexer.
*
* @param[in] all Set to true to remove both input and output. Set to
* false to remove only input.
*/
void commander::unreg(bool all) {
if (all)
multiplexer::instance().handle_manager::remove(this);
else
multiplexer::instance().handle_manager::remove(&_si);
return ;
}
/**
* Do we want to monitor handle for reading ?
*
* @param[in] h Handle.
*/
bool commander::want_read(handle& h) {
return (&h == &_si);
}
/**
* Do we want to monitor handle for writing ?
*
* @param[in] h Handle.
*/
bool commander::want_write(handle& h) {
// XXX
}
/**
* Write callback.
*
* @param[in,out] h Handle.
*/
void commander::write(handle& h) {
// XXX
}
/**************************************
* *
......
......@@ -21,6 +21,7 @@
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include "com/centreon/connector/ssh/commander.hh"
#include "com/centreon/connector/ssh/multiplexer.hh"
#include "com/centreon/exceptions/basic.hh"
#include "com/centreon/logging/logger.hh"
......@@ -61,10 +62,6 @@ int main() {
logging::engine::load();
multiplexer::load();
// Set termination handler.
logging::info(logging::medium) << "installing termination handler";
signal(SIGTERM, term_handler);
#if LIBSSH2_VERSION_NUM >= 0x010205
// Initialize libssh2.
logging::info(logging::medium) << "initializing libssh2";
......@@ -72,12 +69,32 @@ int main() {
throw (basic_error() << "libssh2 initialization failed");
#endif /* libssh2 version >= 1.2.5 */
// Set termination handler.
logging::info(logging::medium) << "installing termination handler";
signal(SIGTERM, term_handler);
// Listener of commands.
commander c;
c.reg();
// Multiplexing loop.
logging::info(logging::medium) << "starting multiplexing loop";
/*while (!should_exit && multiplex())
;*/
while (!should_exit)
multiplexer::instance().multiplex();
logging::info(logging::medium) << "multiplexing loop terminated";
// Remove command listener on input.
logging::debug(logging::high)
<< "commander will stop listening on input";
c.unreg(false);
// Wait for remaining sessions.
// XXX
// Remove command listener totally.
logging::debug(logging::high) << "removing command listener";
c.unreg();
// Set return value.
retval = EXIT_SUCCESS;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment