#include <SocketManager.h>
Public Types | |
typedef std::function< void()> | Callback |
typedef std::function< void(const ManagedSocketPtr &)> | IncomingHandler |
Public Member Functions | |
ADCHPP_DLL void | addJob (const std::string &time, const Callback &callback) |
execute a function after the specified amount of time | |
ADCHPP_DLL void | addJob (const long msec, const Callback &callback) |
execute a function after the specified amount of time | |
ADCHPP_DLL void | addJob (const Callback &callback) throw () |
execute a function asynchronously | |
ADCHPP_DLL Callback | addTimedJob (const std::string &time, const Callback &callback) |
execute a function at regular intervals | |
ADCHPP_DLL Callback | addTimedJob (const long msec, const Callback &callback) |
execute a function at regular intervals | |
ADCHPP_DLL void | join () throw () |
void | setIncomingHandler (const IncomingHandler &handler) |
void | setServers (const ServerInfoList &servers_) |
void | shutdown () |
ADCHPP_DLL void | start () throw (ThreadException) |
void | startup () throw (ThreadException) |
Static Public Member Functions | |
static void | deleteInstance () |
static SocketManager * | getInstance () |
static void | newInstance () |
Public Attributes | |
std::map< std::string, int > | errors |
Static Protected Member Functions | |
static void * | starter (void *p) |
Protected Attributes | |
pthread_t | t |
Private Types | |
typedef shared_ptr < boost::asio::deadline_timer > | timer_ptr |
Private Member Functions | |
void | addJob (const boost::asio::deadline_timer::duration_type &duration, const Callback &callback) |
Callback | addTimedJob (const boost::asio::deadline_timer::duration_type &duration, const Callback &callback) |
void | cancelTimer (timer_ptr timer, Callback *callback) |
void | closeFactories () |
void | handleWait (timer_ptr timer, const boost::asio::deadline_timer::duration_type &duration, const boost::system::error_code &error, Callback *callback) |
void | onLoad (const SimpleXML &xml) throw () |
virtual int | run () |
void | setTimer (timer_ptr timer, const boost::asio::deadline_timer::duration_type &duration, Callback *callback) |
SocketManager () | |
virtual | ~SocketManager () |
Private Attributes | |
std::vector< SocketFactoryPtr > | factories |
IncomingHandler | incomingHandler |
boost::asio::io_service | io |
ServerInfoList | servers |
std::unique_ptr < boost::asio::io_service::work > | work |
Static Private Attributes | |
static const std::string | className = "SocketManager" |
static ADCHPP_DLL SocketManager * | instance = 0 |
Friends | |
class | ManagedSocket |
class | Singleton< SocketManager > |
class | SocketFactory |
Definition at line 33 of file SocketManager.h.
typedef std::function<void()> adchpp::SocketManager::Callback |
Definition at line 35 of file SocketManager.h.
typedef std::function<void (const ManagedSocketPtr&)> adchpp::SocketManager::IncomingHandler |
Definition at line 62 of file SocketManager.h.
typedef shared_ptr<boost::asio::deadline_timer> adchpp::SocketManager::timer_ptr [private] |
Definition at line 88 of file SocketManager.h.
adchpp::SocketManager::SocketManager | ( | ) | [private] |
Definition at line 41 of file SocketManager.cpp.
adchpp::SocketManager::~SocketManager | ( | ) | [private, virtual] |
Definition at line 45 of file SocketManager.cpp.
void adchpp::SocketManager::addJob | ( | const boost::asio::deadline_timer::duration_type & | duration, | |
const Callback & | callback | |||
) | [private] |
void adchpp::SocketManager::addJob | ( | const std::string & | time, | |
const Callback & | callback | |||
) |
execute a function after the specified amount of time
time | a string that obeys to the "[-]h[h][:mm][:ss][.fff]" format |
Definition at line 255 of file SocketManager.cpp.
References addJob().
void adchpp::SocketManager::addJob | ( | const long | msec, | |
const Callback & | callback | |||
) |
execute a function after the specified amount of time
msec | milliseconds |
Definition at line 251 of file SocketManager.cpp.
References addJob().
void adchpp::SocketManager::addJob | ( | const Callback & | callback | ) | throw () |
execute a function asynchronously
Definition at line 247 of file SocketManager.cpp.
Referenced by addJob(), adchpp::ManagedSocket::disconnect(), adchpp::Bot::disconnect(), and shutdown().
Callback adchpp::SocketManager::addTimedJob | ( | const boost::asio::deadline_timer::duration_type & | duration, | |
const Callback & | callback | |||
) | [private] |
SocketManager::Callback adchpp::SocketManager::addTimedJob | ( | const std::string & | time, | |
const Callback & | callback | |||
) |
execute a function at regular intervals
time | a string that obeys to the "[-]h[h][:mm][:ss][.fff]" format |
Definition at line 263 of file SocketManager.cpp.
References addTimedJob().
SocketManager::Callback adchpp::SocketManager::addTimedJob | ( | const long | msec, | |
const Callback & | callback | |||
) |
execute a function at regular intervals
msec | milliseconds |
Definition at line 259 of file SocketManager.cpp.
Referenced by addTimedJob().
Definition at line 301 of file SocketManager.cpp.
void adchpp::SocketManager::closeFactories | ( | ) | [private] |
Definition at line 240 of file SocketManager.cpp.
References factories.
Referenced by shutdown().
static void adchpp::Singleton< SocketManager >::deleteInstance | ( | ) | [inline, static, inherited] |
Definition at line 49 of file Singleton.h.
static SocketManager * adchpp::Singleton< SocketManager >::getInstance | ( | ) | [inline, static, inherited] |
Definition at line 37 of file Singleton.h.
Referenced by adchpp::ManagedSocket::disconnect(), adchpp::Bot::disconnect(), adchpp::ManagedSocket::failSocket(), and adchpp::SocketFactory::prepareAccept().
void adchpp::SocketManager::handleWait | ( | timer_ptr | timer, | |
const boost::asio::deadline_timer::duration_type & | duration, | |||
const boost::system::error_code & | error, | |||
Callback * | callback | |||
) | [private] |
void adchpp::Thread::join | ( | ) | throw () [inherited] |
Definition at line 68 of file Thread.cpp.
References adchpp::Thread::t.
Referenced by shutdown().
static void adchpp::Singleton< SocketManager >::newInstance | ( | ) | [inline, static, inherited] |
Definition at line 42 of file Singleton.h.
void adchpp::SocketManager::onLoad | ( | const SimpleXML & | xml | ) | throw () [private] |
Definition at line 322 of file SocketManager.cpp.
int adchpp::SocketManager::run | ( | ) | [private, virtual] |
Implements adchpp::Thread.
Definition at line 218 of file SocketManager.cpp.
References className, factories, incomingHandler, io, LOG, servers, and adchpp::Util::toString().
void adchpp::SocketManager::setIncomingHandler | ( | const IncomingHandler & | handler | ) | [inline] |
Definition at line 63 of file SocketManager.h.
References incomingHandler.
void adchpp::SocketManager::setServers | ( | const ServerInfoList & | servers_ | ) | [inline] |
Definition at line 60 of file SocketManager.h.
References servers.
void adchpp::SocketManager::setTimer | ( | timer_ptr | timer, | |
const boost::asio::deadline_timer::duration_type & | duration, | |||
Callback * | callback | |||
) | [private] |
void adchpp::SocketManager::shutdown | ( | ) |
Definition at line 315 of file SocketManager.cpp.
References addJob(), closeFactories(), io, adchpp::Thread::join(), and work.
void adchpp::Thread::start | ( | ) | throw (ThreadException) [inherited] |
Definition at line 52 of file Thread.cpp.
References _T, adchpp::Thread::starter(), adchpp::Thread::t, and adchpp::Util::translateError().
Referenced by startup().
static void* adchpp::Thread::starter | ( | void * | p | ) | [inline, static, protected, inherited] |
Definition at line 96 of file Thread.h.
References adchpp::Thread::run(), and adchpp::Thread::t.
Referenced by adchpp::Thread::start().
void adchpp::SocketManager::startup | ( | ) | throw (ThreadException) |
Definition at line 310 of file SocketManager.cpp.
References io, adchpp::Thread::start(), and work.
friend class ManagedSocket [friend] |
Definition at line 68 of file SocketManager.h.
friend class Singleton< SocketManager > [friend] |
Definition at line 85 of file SocketManager.h.
friend class SocketFactory [friend] |
Definition at line 69 of file SocketManager.h.
const string adchpp::SocketManager::className = "SocketManager" [static, private] |
Definition at line 83 of file SocketManager.h.
Referenced by run().
std::map<std::string, int> adchpp::SocketManager::errors |
Definition at line 65 of file SocketManager.h.
Referenced by adchpp::ManagedSocket::failSocket().
std::vector<SocketFactoryPtr> adchpp::SocketManager::factories [private] |
Definition at line 79 of file SocketManager.h.
Referenced by closeFactories(), and run().
Definition at line 81 of file SocketManager.h.
Referenced by run(), and setIncomingHandler().
SocketManager * adchpp::SocketManager::instance = 0 [static, private] |
Definition at line 86 of file SocketManager.h.
boost::asio::io_service adchpp::SocketManager::io [private] |
Definition at line 75 of file SocketManager.h.
Referenced by run(), shutdown(), and startup().
ServerInfoList adchpp::SocketManager::servers [private] |
Definition at line 78 of file SocketManager.h.
Referenced by run(), and setServers().
pthread_t adchpp::Thread::t [protected, inherited] |
Definition at line 95 of file Thread.h.
Referenced by adchpp::Thread::join(), adchpp::Thread::start(), and adchpp::Thread::starter().
std::unique_ptr<boost::asio::io_service::work> adchpp::SocketManager::work [private] |
Definition at line 76 of file SocketManager.h.
Referenced by shutdown(), and startup().