51 lines
1.0 KiB
C
Raw Normal View History

2014-09-17 16:43:05 +03:00
#include "interface/event.h"
#include <functional>
2014-09-17 16:43:05 +03:00
namespace network
{
struct PeerInfo
{
typedef size_t Id;
2014-09-17 20:15:46 +03:00
2014-09-17 16:43:05 +03:00
Id id = 0;
ss_ address;
};
struct Packet: public interface::Event::Private
{
typedef size_t Type;
2014-09-17 20:15:46 +03:00
PeerInfo::Id recipient;
Type type;
2014-09-17 16:43:05 +03:00
ss_ data;
Packet(PeerInfo::Id recipient, const Type &type, const ss_ &data):
recipient(recipient), type(type), data(data){}
2014-09-17 16:43:05 +03:00
};
struct NewClient: public interface::Event::Private
2014-09-17 16:43:05 +03:00
{
2014-09-17 20:15:46 +03:00
PeerInfo info;
NewClient(const PeerInfo &info): info(info){}
2014-09-17 20:15:46 +03:00
};
struct Interface
{
2014-09-17 23:00:31 +03:00
virtual Packet::Type packet_type(const ss_ &name) = 0;
virtual void send(PeerInfo::Id recipient, const Packet::Type &type,
const ss_ &data) = 0;
virtual void send(PeerInfo::Id recipient, const ss_ &name,
const ss_ &data) = 0;
2014-09-17 23:00:31 +03:00
};
inline bool access(interface::Server *server,
std::function<void(network::Interface*)> cb)
{
return server->access_module("network", [&](interface::Module * module){
cb((network::Interface*)module->check_interface());
});
}
2014-09-17 16:43:05 +03:00
}