60 lines
1.2 KiB
C
Raw Normal View History

// http://www.apache.org/licenses/LICENSE-2.0
// Copyright 2014 Perttu Ahola <celeron55@gmail.com>
2014-09-18 21:54:29 +03:00
#pragma once
2014-09-17 16:43:05 +03:00
#include "interface/event.h"
#include "interface/server.h"
#include "interface/module.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;
PeerInfo::Id sender = 0;
ss_ name;
2014-09-17 16:43:05 +03:00
ss_ data;
Packet(PeerInfo::Id sender, const ss_ &name, const ss_ &data):
sender(sender), name(name), 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 OldClient: public interface::Event::Private
{
PeerInfo info;
OldClient(const PeerInfo &info): info(info){}
};
struct Interface
{
virtual void send(PeerInfo::Id recipient, const ss_ &name,
const ss_ &data) = 0;
virtual sv_<PeerInfo::Id> list_peers() = 0;
2014-09-17 23:00:31 +03:00
};
inline bool access(interface::Server *server,
std::function<void(network::Interface*)> cb)
{
2014-10-06 16:43:27 +03:00
return server->access_module("network", [&](interface::Module *module){
cb((network::Interface*)module->check_interface());
});
}
2014-09-17 16:43:05 +03:00
}
2014-09-24 14:53:57 +03:00
// vim: set noet ts=4 sw=4: