Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Ping.h"
- #include "System.h"
- Ping *Ping::self = NULL;
- Ping::Ping()
- {
- m_thread = NULL;
- self = this;
- }
- Ping::~Ping()
- {
- Ping::process::iterator it;
- for ( it = m_processes.begin(); it != m_processes.end(); ++it )
- {
- if ( NULL != it->second )
- {
- delete it->second;
- }
- }
- m_processes.clear();
- delete m_thread;
- KSVC_LOG_INF ( PING_SERVICE ) << "Ping service is gracefully shutdowned";
- }
- /*Ping& Ping::operator= ( const Ping& other )
- {
- }*/
- /*bool Ping::operator== ( const Ping& other ) const
- {
- }*/
- bool Ping::Init()
- {
- // Register signal handlers so that the daemon may be shut down.
- //m_signals->async_wait ( boost::bind ( &boost::asio::io_service::stop, &m_io_service ) );
- KSVC_LOG_INF ( PING_SERVICE ) << "Pinger has started";
- return true;
- }
- void Ping::AddPingProcess ( std::string destination, std::string uuid )
- {
- try {
- PingProcess *npp = new PingProcess ( this );
- m_processes [ destination ] = npp;
- npp->SetUUID ( uuid );
- npp->SetPingProcessID ( m_processes.size() );
- npp->Init();
- npp->Query ( destination );
- KSVC_LOG_INF ( PING_SERVICE ) << "New ping process for host " << destination << " was added";
- } catch ( std::exception &e ) {
- KSVC_LOG_ERR ( PING_SERVICE ) << "EXCEPTION: " << __FILE__ << "::" << __LINE__ << "::" << __FUNCTION__ << " " << e.what() << std::endl;
- }
- }
- void Ping::Worker()
- {
- try {
- self->Init();
- Configuration& conf = Configuration::Instance();
- boost::property_tree::ptree cameras = conf.GetCameras().get_child ( "Sources" );
- BOOST_FOREACH ( boost::property_tree::ptree::value_type &v, cameras )
- {
- std::string uuid = v.first,
- ip = v.second.get < std::string > ( "ip" );
- //std::cout << " here " << ip << std::endl;
- self->AddPingProcess ( ip, uuid );
- //boost::property_tree::write_json ( std::cout, v.second );
- }
- // Blocking function. The boost::asio got his job and starts working here
- self->m_io_service.run();
- } catch ( std::exception &e ) {
- KSVC_LOG_ERR ( PING_SERVICE ) << "EXCEPTION: " << __FILE__ << "::" << __LINE__ << "::" << __FUNCTION__ << " " << e.what() << std::endl;
- }
- }
- int Ping::Exec()
- {
- try
- {
- m_thread = new boost::thread ( boost::bind ( &Ping::Worker, this ) );
- //Worker();
- } catch ( std::exception &e ) {
- KSVC_LOG_ERR ( PING_SERVICE ) << "EXCEPTION: " << __FILE__ << "::" << __LINE__ << "::" << __FUNCTION__ << " " << e.what() << std::endl;
- return 1;
- }
- return 0;
- }
- void Ping::Stop()
- {
- m_io_service.stop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement