61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
/*! \file pistreampacker.h
|
|
* \brief Simple packet wrap aroud any PIIODevice
|
|
*/
|
|
/*
|
|
PIP - Platform Independent Primitives
|
|
Simple packet wrap aroud any PIIODevice
|
|
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 PISTREAMPACKER_H
|
|
#define PISTREAMPACKER_H
|
|
|
|
#include "piobject.h"
|
|
#include "piethutilbase.h"
|
|
|
|
|
|
class PIIODevice;
|
|
|
|
class PIStreamPacker: public PIObject, public PIEthUtilBase {
|
|
PIOBJECT(PIStreamPacker)
|
|
public:
|
|
PIStreamPacker(PIIODevice * dev = 0);
|
|
|
|
int maxPacketSize() {return max_packet_size;}
|
|
void setMaxPacketSize(int max_size) {max_packet_size = max_size;}
|
|
|
|
ushort packetSign() {return packet_sign;}
|
|
void setPacketSign(ushort sign_) {packet_sign = sign_;}
|
|
|
|
void send(const PIByteArray & data);
|
|
void received(const PIByteArray & data);
|
|
EVENT_HANDLER2(void, received, uchar * , readed, int, size) {received(PIByteArray(readed, size));}
|
|
|
|
void assignDevice(PIIODevice * dev);
|
|
|
|
EVENT1(packetReceiveEvent, PIByteArray, data)
|
|
EVENT1(sendRequest, PIByteArray, data)
|
|
|
|
protected:
|
|
PIByteArray stream, packet;
|
|
int packet_size;
|
|
ushort packet_sign;
|
|
int max_packet_size;
|
|
|
|
};
|
|
|
|
#endif // PISTREAMPACKER_H
|