2017-08-08 13:53:47 +02:00
|
|
|
#ifndef HIVE_H_
|
|
|
|
#define HIVE_H_
|
|
|
|
|
2018-10-24 15:17:40 +02:00
|
|
|
#include <asio.hpp>
|
2018-10-24 13:52:27 +02:00
|
|
|
#include <atomic>
|
2018-10-24 17:58:57 +02:00
|
|
|
#include <memory>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2019-06-02 23:28:19 +10:00
|
|
|
namespace Sapphire::Common::Network
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
class Hive : public std::enable_shared_from_this< Hive >
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
asio::io_service m_io_service;
|
|
|
|
std::shared_ptr< asio::io_service::work > m_work_ptr;
|
|
|
|
std::atomic< uint32_t > m_shutdown;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
private:
|
|
|
|
Hive( const Hive& rhs );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
Hive& operator=( const Hive& rhs );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
public:
|
|
|
|
Hive();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
virtual ~Hive();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
// Returns the io_service of this object.
|
2019-03-08 09:43:56 +01:00
|
|
|
asio::io_service& getService();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
// Returns true if the Stop function has been called.
|
2019-03-08 09:43:56 +01:00
|
|
|
bool hasStopped();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
// Polls the networking subsystem once from the current thread and
|
|
|
|
// returns.
|
2019-03-08 09:43:56 +01:00
|
|
|
void poll();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
// Runs the networking system on the current thread. This function blocks
|
|
|
|
// until the networking system is stopped, so do not call on a single
|
|
|
|
// threaded application with no other means of being able to call Stop
|
|
|
|
// unless you code in such logic.
|
2019-03-08 09:43:56 +01:00
|
|
|
void run();
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
// Stops the networking system. All work is finished and no more
|
|
|
|
// networking interactions will be possible afterwards until Reset is called.
|
2019-03-08 09:43:56 +01:00
|
|
|
void stop();
|
2018-10-28 21:53:21 +01:00
|
|
|
|
|
|
|
// Restarts the networking system after Stop as been called. A new work
|
|
|
|
// object is created ad the shutdown flag is cleared.
|
2019-03-08 09:43:56 +01:00
|
|
|
void reset();
|
2018-10-28 21:53:21 +01:00
|
|
|
};
|
2018-08-29 21:40:59 +02:00
|
|
|
|
|
|
|
}
|
2018-10-24 13:52:27 +02:00
|
|
|
#endif
|