cmake: Further refactoring and formatting
This commit is contained in:
+2
-2
@@ -38,8 +38,8 @@ typename std::enable_if<enable_bitmask_operators<Enum>::enable, Enum>::type oper
|
||||
return static_cast<Enum>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
|
||||
}
|
||||
|
||||
#define ENABLE_BITMASK_OPERATORS(x) \
|
||||
template<> \
|
||||
#define ENABLE_BITMASK_OPERATORS(x) \
|
||||
template<> \
|
||||
struct enable_bitmask_operators<x> { \
|
||||
static const bool enable = true; \
|
||||
};
|
||||
|
||||
@@ -27,5 +27,5 @@ namespace datapath {
|
||||
datapath::error connect(std::shared_ptr<datapath::isocket>& socket, std::string path);
|
||||
|
||||
datapath::error host(std::shared_ptr<datapath::iserver>& server, std::string path,
|
||||
datapath::permissions permissions, size_t max_clients = 0);
|
||||
datapath::permissions permissions, size_t max_clients = 0);
|
||||
} // namespace datapath
|
||||
|
||||
+17
-17
@@ -24,10 +24,10 @@
|
||||
namespace datapath {
|
||||
template<typename... _args>
|
||||
class event {
|
||||
std::list<std::function<void(_args...)>> listeners;
|
||||
std::list<std::function<void(_args...)>> _listeners;
|
||||
|
||||
std::function<void()> listen_cb;
|
||||
std::function<void()> silence_cb;
|
||||
std::function<void()> _listen_cb;
|
||||
std::function<void()> _silence_cb;
|
||||
|
||||
public /* functions */:
|
||||
|
||||
@@ -40,20 +40,20 @@ namespace datapath {
|
||||
// Add new listener.
|
||||
inline void add(std::function<void(_args...)> listener)
|
||||
{
|
||||
if (listeners.size() == 0) {
|
||||
if (listen_cb) {
|
||||
listen_cb();
|
||||
if (_listeners.size() == 0) {
|
||||
if (_listen_cb) {
|
||||
_listen_cb();
|
||||
}
|
||||
}
|
||||
listeners.push_back(listener);
|
||||
_listeners.push_back(listener);
|
||||
}
|
||||
|
||||
// Remove existing listener.
|
||||
inline void remove(std::function<void(_args...)> listener)
|
||||
{
|
||||
listeners.remove(listener);
|
||||
if (listeners.size() == 0) {
|
||||
if (silence_cb) {
|
||||
_listeners.remove(listener);
|
||||
if (_listeners.size() == 0) {
|
||||
if (_silence_cb) {
|
||||
silence_cb();
|
||||
}
|
||||
}
|
||||
@@ -62,15 +62,15 @@ namespace datapath {
|
||||
// Check if empty / no listeners.
|
||||
inline bool empty()
|
||||
{
|
||||
return listeners.empty();
|
||||
return _listeners.empty();
|
||||
}
|
||||
|
||||
// Remove all listeners.
|
||||
inline void clear()
|
||||
{
|
||||
listeners.clear();
|
||||
if (silence_cb) {
|
||||
silence_cb();
|
||||
_listeners.clear();
|
||||
if (_silence_cb) {
|
||||
_silence_cb();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace datapath {
|
||||
template<typename... _largs>
|
||||
inline void operator()(_args... args)
|
||||
{
|
||||
for (auto& l : listeners) {
|
||||
for (auto& l : _listeners) {
|
||||
l(args...);
|
||||
}
|
||||
}
|
||||
@@ -108,12 +108,12 @@ namespace datapath {
|
||||
public /* events */:
|
||||
void set_listen_callback(std::function<void()> cb)
|
||||
{
|
||||
this->listen_cb = cb;
|
||||
this->_listen_cb = cb;
|
||||
}
|
||||
|
||||
void set_silence_callback(std::function<void()> cb)
|
||||
{
|
||||
this->silence_cb = cb;
|
||||
this->_silence_cb = cb;
|
||||
}
|
||||
};
|
||||
}; // namespace datapath
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ namespace datapath {
|
||||
* @param std::shared_ptr<datapath::isocket> Socket.
|
||||
* @return void
|
||||
*/
|
||||
datapath::event<bool&, std::shared_ptr<datapath::isocket>> on_accept;
|
||||
datapath::event<bool&, std::shared_ptr<datapath::isocket>> _on_accept;
|
||||
|
||||
public:
|
||||
virtual datapath::error close() = 0;
|
||||
|
||||
+2
-2
@@ -24,9 +24,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
namespace datapath {
|
||||
class isocket {
|
||||
public /*events*/:
|
||||
datapath::event<const std::vector<char>&> on_message;
|
||||
datapath::event<const std::vector<char>&> _on_message;
|
||||
|
||||
datapath::event<> on_close;
|
||||
datapath::event<> _on_close;
|
||||
|
||||
public:
|
||||
virtual bool good() = 0;
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
namespace datapath {
|
||||
class itask : public waitable {
|
||||
public /*event*/:
|
||||
datapath::event<datapath::error> on_failure;
|
||||
datapath::event<datapath::error> _on_failure;
|
||||
|
||||
datapath::event<datapath::error, const std::vector<char>&> on_success;
|
||||
datapath::event<datapath::error, const std::vector<char>&> _on_success;
|
||||
|
||||
public:
|
||||
virtual datapath::error cancel() = 0;
|
||||
|
||||
@@ -21,12 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "bitmask.hpp"
|
||||
|
||||
namespace datapath {
|
||||
enum class permissions : int8_t {
|
||||
None,
|
||||
User,
|
||||
Group,
|
||||
World,
|
||||
Reserved
|
||||
};
|
||||
enum class permissions : int8_t { None, User, Group, World, Reserved };
|
||||
ENABLE_BITMASK_OPERATORS(datapath::permissions);
|
||||
} // namespace datapath
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
@@ -28,7 +29,7 @@
|
||||
|
||||
namespace datapath {
|
||||
namespace threadpool {
|
||||
typedef uint64_t affinity_t;
|
||||
typedef uint64_t affinity_t;
|
||||
|
||||
constexpr affinity_t default_mask = std::numeric_limits<affinity_t>::max();
|
||||
|
||||
@@ -58,7 +59,7 @@ namespace datapath {
|
||||
void push(std::shared_ptr<task> task);
|
||||
};
|
||||
|
||||
std::map<affinity_t, std::shared_ptr<worker>> workers;
|
||||
std::map<affinity_t, std::shared_ptr<worker>> _workers;
|
||||
|
||||
public:
|
||||
pool();
|
||||
|
||||
@@ -25,9 +25,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
namespace datapath {
|
||||
class waitable {
|
||||
public /*events*/:
|
||||
datapath::event<datapath::error> on_wait_error;
|
||||
datapath::event<datapath::error> _on_wait_error;
|
||||
|
||||
datapath::event<datapath::error> on_wait_success;
|
||||
datapath::event<datapath::error> _on_wait_success;
|
||||
|
||||
public:
|
||||
virtual void* get_waitable() = 0;
|
||||
@@ -40,22 +40,22 @@ namespace datapath {
|
||||
public /*static*/:
|
||||
|
||||
static datapath::error wait(datapath::waitable* obj,
|
||||
std::chrono::nanoseconds duration = std::chrono::nanoseconds(0));
|
||||
std::chrono::nanoseconds duration = std::chrono::nanoseconds(0));
|
||||
|
||||
static datapath::error wait(datapath::waitable** objs, size_t count,
|
||||
std::chrono::nanoseconds duration = std::chrono::nanoseconds(0));
|
||||
std::chrono::nanoseconds duration = std::chrono::nanoseconds(0));
|
||||
|
||||
static inline datapath::error wait(std::vector<datapath::waitable*> objs,
|
||||
std::chrono::nanoseconds duration = std::chrono::nanoseconds(0))
|
||||
std::chrono::nanoseconds duration = std::chrono::nanoseconds(0))
|
||||
{
|
||||
return datapath::waitable::wait(objs.data(), objs.size(), duration);
|
||||
}
|
||||
|
||||
static datapath::error wait_any(datapath::waitable** objs, size_t count, size_t& index,
|
||||
std::chrono::nanoseconds duration = std::chrono::nanoseconds(0));
|
||||
std::chrono::nanoseconds duration = std::chrono::nanoseconds(0));
|
||||
|
||||
static inline datapath::error wait_any(std::vector<datapath::waitable*> objs, size_t& index,
|
||||
std::chrono::nanoseconds duration = std::chrono::nanoseconds(0))
|
||||
std::chrono::nanoseconds duration = std::chrono::nanoseconds(0))
|
||||
{
|
||||
return datapath::waitable::wait_any(objs.data(), objs.size(), index, duration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user