git-svn-id: svn://db.shs.com.ru/pip@635 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2018-09-28 07:22:36 +00:00
parent 2a48ee090a
commit 452350fcd9
3 changed files with 273 additions and 198 deletions

View File

@@ -0,0 +1,91 @@
/*! \file pibroadcast.h
* \brief Broadcast for all interfaces, including loopback
*/
/*
PIP - Platform Independent Primitives
Broadcast for all interfaces, including loopback
Copyright (C) 2018 Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIBROADCAST_H
#define PIBROADCAST_H
#include "piethutilbase.h"
#include "piethernet.h"
class PIBroadcast: public PIThread, public PIEthUtilBase {
PIOBJECT_SUBCLASS(PIBroadcast, PIThread)
public:
enum Channel {
Multicast = 0x01,
Broadcast = 0x02,
Loopback = 0x04,
All = 0xFFFF,
};
typedef PIFlags<Channel> Channels;
PIBroadcast(bool send_only = false);
~PIBroadcast();
void setChannels(Channels ch);
Channels channels() const {return _channels;}
void setMulticastGroup(const PIString & mg);
PIString multicastGroup() const {return mcast_address.ipString();}
void setMulticastPort(ushort port);
ushort multicastPort() const {return mcast_address.port();}
void setMulticastAddress(const PIEthernet::Address & addr);
PIEthernet::Address multicastAddress() const {return mcast_address;}
void setBroadcastPort(ushort port);
ushort broadcastPort() {return bcast_port;}
void setLoopbackPort(ushort port);
ushort loopbackPort() {return lo_port;}
void setLoopbackPortsCount(int count);
int loopbackPortsCount() const {return lo_pcnt;}
void startRead();
void stopRead();
void reinit();
void send(const PIByteArray & data);
EVENT1(receiveEvent, PIByteArray, data)
protected:
virtual void received(PIByteArray data) {}
private:
EVENT_HANDLER2(void, mcastRead, uchar * , data, int, size);
void destroyAll();
void initAll(PIVector<PIEthernet::Address> al);
void run();
Channels _channels;
PIEthernet::Address mcast_address;
PIMutex mcast_mutex;
PIVector<PIEthernet*> eth_mcast;
PIEthernet * eth_lo;
PIVector<PIEthernet::Address> prev_al;
ushort lo_port, bcast_port;
int lo_pcnt;
bool _started, _send_only, _reinit;
};
#endif // PIBROADCAST_H