2014-09-19 18:42:07 +03:00
|
|
|
// 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"
|
2014-10-01 09:25:24 +03:00
|
|
|
#include "interface/server.h"
|
|
|
|
#include "interface/module.h"
|
2014-09-18 02:09:53 +03:00
|
|
|
#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-19 02:22:53 +03:00
|
|
|
PeerInfo::Id sender = 0;
|
2014-09-19 00:53:06 +03:00
|
|
|
ss_ name;
|
2014-09-17 16:43:05 +03:00
|
|
|
ss_ data;
|
2014-09-19 02:22:53 +03:00
|
|
|
Packet(PeerInfo::Id sender, const ss_ &name, const ss_ &data):
|
|
|
|
sender(sender), name(name), data(data){}
|
2014-09-17 16:43:05 +03:00
|
|
|
};
|
|
|
|
|
2014-09-17 20:24:06 +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;
|
|
|
|
|
2014-09-17 20:24:06 +03:00
|
|
|
NewClient(const PeerInfo &info): info(info){}
|
2014-09-17 20:15:46 +03:00
|
|
|
};
|
2014-09-17 20:49:30 +03:00
|
|
|
|
2014-09-20 00:50:43 +03:00
|
|
|
struct OldClient: public interface::Event::Private
|
|
|
|
{
|
|
|
|
PeerInfo info;
|
|
|
|
|
|
|
|
OldClient(const PeerInfo &info): info(info){}
|
|
|
|
};
|
|
|
|
|
2014-09-17 23:22:00 +03:00
|
|
|
struct Interface
|
2014-09-17 20:49:30 +03:00
|
|
|
{
|
2014-09-17 23:22:00 +03:00
|
|
|
virtual void send(PeerInfo::Id recipient, const ss_ &name,
|
2014-10-08 00:48:30 +03:00
|
|
|
const ss_ &data) = 0;
|
2014-09-24 10:58:46 +03:00
|
|
|
virtual sv_<PeerInfo::Id> list_peers() = 0;
|
2014-09-17 23:00:31 +03:00
|
|
|
};
|
2014-09-17 23:22:00 +03:00
|
|
|
|
2014-09-18 02:09:53 +03:00
|
|
|
inline bool access(interface::Server *server,
|
2014-10-08 00:48:30 +03:00
|
|
|
std::function<void(network::Interface*)> cb)
|
2014-09-17 23:22:00 +03:00
|
|
|
{
|
2014-10-06 16:43:27 +03:00
|
|
|
return server->access_module("network", [&](interface::Module *module){
|
2014-10-08 00:48:30 +03:00
|
|
|
cb((network::Interface*)module->check_interface());
|
|
|
|
});
|
2014-09-17 23:22:00 +03:00
|
|
|
}
|
2014-09-17 16:43:05 +03:00
|
|
|
}
|
|
|
|
|
2014-09-24 14:53:57 +03:00
|
|
|
// vim: set noet ts=4 sw=4:
|