Files
pip/src_main/io_utils/pimulticast.h

80 lines
2.5 KiB
C++

/*! \file pimulticast.h
* \brief Multicast for all interfaces, including loopback
*/
/*
PIP - Platform Independent Primitives
Multicast 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 PIMULTICAST_H
#define PIMULTICAST_H
#include "piethutilbase.h"
#include "piethernet.h"
#define SMDEVICE_PORT 22555
class PIMulticast: public PIThread, public PIEthUtilBase {
PIOBJECT(PIMulticast)
public:
PIMulticast(bool send_only = false);
~PIMulticast();
void setMulticastGroup(const PIString & mg) {mcast_address.setIP(mg);}
PIString multicastGroup() const {return mcast_address.ipString();}
void setMulticastPort(ushort port) {mcast_address.setPort(port);}
ushort multicastPort() const {return mcast_address.port();}
void setMulticastAddress(const PIEthernet::Address & addr) {mcast_address = addr;}
PIEthernet::Address multicastAddress() const {return mcast_address;}
void setBroadcastPort(ushort port) {bcast_port = port;}
ushort broadcastPort() {return bcast_port;}
void setLoopbackPort(ushort port) {lo_port = port;}
ushort loopbackPort() {return lo_port;}
void setLoopbackPortsCount(int count) {lo_pcnt = 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();
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 // PIMULTICAST_H