code format
This commit is contained in:
@@ -5,22 +5,22 @@
|
||||
* \~russian Извлекатель пакетов
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Packets extractor
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Packets extractor
|
||||
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 Lesser 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 free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIPACKETEXTRACTOR_H
|
||||
@@ -41,43 +41,42 @@ typedef std::function<bool(const uchar *, int)> PacketExtractorPayloadFunc;
|
||||
/// Return true if packet is correct, false otherwise.
|
||||
typedef std::function<bool(const uchar *, const uchar *, int)> PacketExtractorFooterFunc;
|
||||
|
||||
class PIP_EXPORT PIPacketExtractor: public PIIODevice
|
||||
{
|
||||
class PIP_EXPORT PIPacketExtractor: public PIIODevice {
|
||||
PIIODEVICE(PIPacketExtractor, "pckext");
|
||||
friend class PIConnection;
|
||||
public:
|
||||
|
||||
public:
|
||||
//! Extract algorithms
|
||||
enum SplitMode {
|
||||
None /** No data processing */ ,
|
||||
Header /** Detect packets with \a header() and following \a payloadSize() */ ,
|
||||
Footer /** Detect packets with \a footer() and leading \a payloadSize() */ ,
|
||||
HeaderAndFooter /** Detect packets with \a header() and \a footer() without \a payloadSize() */ ,
|
||||
Size /** Detect packets with \a packetSize() */ ,
|
||||
None /** No data processing */,
|
||||
Header /** Detect packets with \a header() and following \a payloadSize() */,
|
||||
Footer /** Detect packets with \a footer() and leading \a payloadSize() */,
|
||||
HeaderAndFooter /** Detect packets with \a header() and \a footer() without \a payloadSize() */,
|
||||
Size /** Detect packets with \a packetSize() */,
|
||||
Timeout /** Wait for first read, then read for \a timeout() milliseconds */
|
||||
};
|
||||
|
||||
//! Contructs extractor with child device "device_" and extract algorithm "mode"
|
||||
explicit PIPacketExtractor(PIIODevice * device_ = nullptr, SplitMode mode = None);
|
||||
|
||||
virtual ~PIPacketExtractor() {stop();}
|
||||
virtual ~PIPacketExtractor() { stop(); }
|
||||
|
||||
|
||||
//! Returns child %device
|
||||
PIIODevice * device() {return dev;}
|
||||
PIIODevice * device() { return dev; }
|
||||
|
||||
//! Set child %device to "device_"
|
||||
void setDevice(PIIODevice * device_);
|
||||
|
||||
ssize_t bytesAvailable() const override;
|
||||
|
||||
void setHeaderCheckSlot(PacketExtractorHeaderFunc f) {func_header = f;}
|
||||
void setPayloadCheckSlot(PacketExtractorPayloadFunc f) {func_payload = f;}
|
||||
void setFooterCheckSlot(PacketExtractorFooterFunc f) {func_footer = f;}
|
||||
void setHeaderCheckSlot(PacketExtractorHeaderFunc f) { func_header = f; }
|
||||
void setPayloadCheckSlot(PacketExtractorPayloadFunc f) { func_payload = f; }
|
||||
void setFooterCheckSlot(PacketExtractorFooterFunc f) { func_footer = f; }
|
||||
|
||||
|
||||
//! Set extract algorithm
|
||||
void setSplitMode(SplitMode mode) {setProperty("splitMode", int(mode));}
|
||||
void setSplitMode(SplitMode mode) { setProperty("splitMode", int(mode)); }
|
||||
|
||||
//! Set payload size, used for PIPacketExtractor::Header and PIPacketExtractor::Footer algorithms
|
||||
void setPayloadSize(int size);
|
||||
@@ -89,45 +88,45 @@ public:
|
||||
void setFooter(const PIByteArray & data);
|
||||
|
||||
//! Set timeout in milliseconds, used for PIPacketExtractor::Timeout algorithm
|
||||
void setTimeout(double msecs) {setProperty("timeout", msecs);}
|
||||
void setTimeout(double msecs) { setProperty("timeout", msecs); }
|
||||
|
||||
|
||||
//! Returns current extract algorithm
|
||||
SplitMode splitMode() const {return mode_;}
|
||||
SplitMode splitMode() const { return mode_; }
|
||||
|
||||
//! Returns current payload size, used for PIPacketExtractor::Header and PIPacketExtractor::Footer and PIPacketExtractor::Size algorithms
|
||||
int payloadSize() const {return dataSize;}
|
||||
//! Returns current payload size, used for PIPacketExtractor::Header and PIPacketExtractor::Footer and PIPacketExtractor::Size
|
||||
//! algorithms
|
||||
int payloadSize() const { return dataSize; }
|
||||
|
||||
//! Returns current header data, used for PIPacketExtractor::Header and PIPacketExtractor::HeaderAndFooter algorithms
|
||||
PIByteArray header() const {return src_header;}
|
||||
PIByteArray header() const { return src_header; }
|
||||
|
||||
//! Returns current footer data, used for PIPacketExtractor::Footer and PIPacketExtractor::HeaderAndFooter algorithms
|
||||
PIByteArray footer() const {return src_footer;}
|
||||
PIByteArray footer() const { return src_footer; }
|
||||
|
||||
//! Returns current timeout in milliseconds, used for PIPacketExtractor::Timeout algorithm
|
||||
double timeout() const {return time_;}
|
||||
double timeout() const { return time_; }
|
||||
|
||||
//! Returns missed by validating functions bytes count
|
||||
ullong missedBytes() const {return missed;}
|
||||
ullong missedBytes() const { return missed; }
|
||||
|
||||
//! Add data to extractor, raise \a packetReceived() if packet is ready
|
||||
void appendData(const uchar * d, int s) {threadedRead(d, s);}
|
||||
void appendData(const uchar * d, int s) { threadedRead(d, s); }
|
||||
|
||||
//! Add data to extractor, raise \a packetReceived() if packet is ready
|
||||
void appendData(const PIByteArray & data) {threadedRead(data.data(), data.size_s());}
|
||||
void appendData(const PIByteArray & data) { threadedRead(data.data(), data.size_s()); }
|
||||
|
||||
EVENT2(packetReceived, const uchar * , data, int, size);
|
||||
EVENT2(packetReceived, const uchar *, data, int, size);
|
||||
|
||||
//! \events
|
||||
//! \{
|
||||
//! \events
|
||||
//! \{
|
||||
|
||||
//! \fn void packetReceived(const uchar * data, int size)
|
||||
//! \brief Raise on successfull \a packetValidate() function
|
||||
|
||||
//! \}
|
||||
//! \}
|
||||
|
||||
protected:
|
||||
|
||||
/** \brief Function to validate header
|
||||
* \param src Your header content
|
||||
* \param rec Received header
|
||||
@@ -152,7 +151,7 @@ private:
|
||||
void construct();
|
||||
void propertyChanged(const char *) override;
|
||||
ssize_t readDevice(void * read_to, ssize_t max_size) override;
|
||||
ssize_t writeDevice(const void * data, ssize_t max_size) override;
|
||||
ssize_t writeDevice(const void * data, ssize_t max_size) override;
|
||||
bool threadedRead(const uchar * readed, ssize_t size) override;
|
||||
PIString constructFullPathDevice() const override;
|
||||
bool openDevice() override;
|
||||
@@ -169,8 +168,6 @@ private:
|
||||
double time_;
|
||||
bool header_found;
|
||||
ullong missed;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // PIPACKETEXTRACTOR_H
|
||||
|
||||
Reference in New Issue
Block a user