PIIODevice::bytesAvailible()
fix pistringlist pibinarystream write pibinarystream::binaryStreamSize() PIByteArray pibinarystream read with more size fix pistring pibinarystream read optimization fix bug in PIIOBinaryStream read and write if failed workaround in PIIOString::readDevice PISPI readDevice bug Fixed
This commit is contained in:
@@ -7,19 +7,19 @@ class SomeIO: public PIIODevice {
|
|||||||
public:
|
public:
|
||||||
SomeIO(): PIIODevice() {}
|
SomeIO(): PIIODevice() {}
|
||||||
protected:
|
protected:
|
||||||
bool openDevice() {
|
bool openDevice() override {
|
||||||
// open your device here
|
// open your device here
|
||||||
return if_success;
|
return if_success;
|
||||||
}
|
}
|
||||||
int read(void * read_to, int max_size) {
|
int readDevice(void * read_to, int max_size) override {
|
||||||
// read from your device here
|
// read from your device here
|
||||||
return readed_bytes;
|
return readed_bytes;
|
||||||
}
|
}
|
||||||
int write(const void * data, int max_size) {
|
int writeDevice(const void * data, int max_size) override {
|
||||||
// write to your device here
|
// write to your device here
|
||||||
return written_bytes;
|
return written_bytes;
|
||||||
}
|
}
|
||||||
void configureFromFullPath(const PIString & full_path) {
|
void configureFromFullPathDevice(const PIString & full_path) override {
|
||||||
// parse full_path and configure device here
|
// parse full_path and configure device here
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -38,7 +38,7 @@ ser.configure("example.conf", "dev");
|
|||||||
//! [configureDevice]
|
//! [configureDevice]
|
||||||
class SomeIO: public PIIODevice {
|
class SomeIO: public PIIODevice {
|
||||||
...
|
...
|
||||||
bool configureDevice(const void * e_main, const void * e_parent) {
|
bool configureDevice(const void * e_main, const void * e_parent) override {
|
||||||
PIConfig::Entry * em = (PIConfig::Entry * )e_main;
|
PIConfig::Entry * em = (PIConfig::Entry * )e_main;
|
||||||
PIConfig::Entry * ep = (PIConfig::Entry * )e_parent;
|
PIConfig::Entry * ep = (PIConfig::Entry * )e_parent;
|
||||||
setStringParam(readDeviceSetting<PIString>("stringParam", stringParam(), em, ep));
|
setStringParam(readDeviceSetting<PIString>("stringParam", stringParam(), em, ep));
|
||||||
|
|||||||
@@ -42,16 +42,17 @@ public:
|
|||||||
void setServerName(const PIString & server_name);
|
void setServerName(const PIString & server_name);
|
||||||
void setKeepConnection(bool on);
|
void setKeepConnection(bool on);
|
||||||
bool isConnected() const {return is_connected;}
|
bool isConnected() const {return is_connected;}
|
||||||
|
ssize_t bytesAvailible() const override {return buff.size();}
|
||||||
|
|
||||||
EVENT(connected);
|
EVENT(connected);
|
||||||
EVENT(disconnected);
|
EVENT(disconnected);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int size) override;
|
int writeDevice(const void * data, int size) override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EVENT_HANDLER1(void, _readed, PIByteArray &, data);
|
EVENT_HANDLER1(void, _readed, PIByteArray &, data);
|
||||||
|
|||||||
@@ -45,11 +45,12 @@ public:
|
|||||||
Client(PICloudServer * srv = nullptr, uint id = 0);
|
Client(PICloudServer * srv = nullptr, uint id = 0);
|
||||||
virtual ~Client();
|
virtual ~Client();
|
||||||
protected:
|
protected:
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int size) override;
|
int writeDevice(const void * data, int size) override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
||||||
|
ssize_t bytesAvailible() const override {return buff.size();}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void pushBuffer(const PIByteArray & ba);
|
void pushBuffer(const PIByteArray & ba);
|
||||||
@@ -68,10 +69,10 @@ public:
|
|||||||
EVENT1(newConnection, PICloudServer::Client * , client);
|
EVENT1(newConnection, PICloudServer::Client * , client);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int max_size) override;
|
int writeDevice(const void * data, int max_size) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EVENT_HANDLER1(void, _readed, PIByteArray &, ba);
|
EVENT_HANDLER1(void, _readed, PIByteArray &, ba);
|
||||||
|
|||||||
@@ -205,9 +205,9 @@ public:
|
|||||||
static PIKbdListener * instance() {return _object;}
|
static PIKbdListener * instance() {return _object;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void begin();
|
void begin() override;
|
||||||
void run() {readKeyboard();}
|
void run() override {readKeyboard();}
|
||||||
void end();
|
void end() override;
|
||||||
|
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
struct PIP_EXPORT EscSeq {
|
struct PIP_EXPORT EscSeq {
|
||||||
|
|||||||
@@ -134,9 +134,9 @@ private:
|
|||||||
PIVector<PIVector<PIScreenTypes::Cell> > cells, pcells;
|
PIVector<PIVector<PIScreenTypes::Cell> > cells, pcells;
|
||||||
};
|
};
|
||||||
|
|
||||||
void begin();
|
void begin() override;
|
||||||
void run();
|
void run() override;
|
||||||
void end();
|
void end() override;
|
||||||
void key_event(PIKbdListener::KeyEvent key);
|
void key_event(PIKbdListener::KeyEvent key);
|
||||||
EVENT_HANDLER1(void, mouse_event, PIKbdListener::MouseEvent, me);
|
EVENT_HANDLER1(void, mouse_event, PIKbdListener::MouseEvent, me);
|
||||||
EVENT_HANDLER1(void, wheel_event, PIKbdListener::WheelEvent, we);
|
EVENT_HANDLER1(void, wheel_event, PIKbdListener::WheelEvent, we);
|
||||||
@@ -145,9 +145,9 @@ private:
|
|||||||
PIVector<PIScreenTile*> prepareMouse(PIKbdListener::MouseEvent * e);
|
PIVector<PIScreenTile*> prepareMouse(PIKbdListener::MouseEvent * e);
|
||||||
PIVector<PIScreenTile*> tilesUnderMouse(int x, int y);
|
PIVector<PIScreenTile*> tilesUnderMouse(int x, int y);
|
||||||
bool nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key = PIKbdListener::KeyEvent());
|
bool nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key = PIKbdListener::KeyEvent());
|
||||||
void tileEventInternal(PIScreenTile * t, PIScreenTypes::TileEvent e);
|
void tileEventInternal(PIScreenTile * t, PIScreenTypes::TileEvent e) override;
|
||||||
void tileRemovedInternal(PIScreenTile * t);
|
void tileRemovedInternal(PIScreenTile * t) override;
|
||||||
void tileSetFocusInternal(PIScreenTile * t);
|
void tileSetFocusInternal(PIScreenTile * t) override;
|
||||||
|
|
||||||
bool mouse_;
|
bool mouse_;
|
||||||
SystemConsole console;
|
SystemConsole console;
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ protected:
|
|||||||
};
|
};
|
||||||
PIVector<Variable> variables;
|
PIVector<Variable> variables;
|
||||||
PIScreenTypes::Alignment alignment;
|
PIScreenTypes::Alignment alignment;
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ public:
|
|||||||
PIVector<Row> content;
|
PIVector<Row> content;
|
||||||
PIScreenTypes::Alignment alignment;
|
PIScreenTypes::Alignment alignment;
|
||||||
protected:
|
protected:
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -62,9 +62,9 @@ public:
|
|||||||
int thickness;
|
int thickness;
|
||||||
protected:
|
protected:
|
||||||
void _check();
|
void _check();
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
bool mouseEvent(PIKbdListener::MouseEvent me);
|
bool mouseEvent(PIKbdListener::MouseEvent me) override;
|
||||||
int minimum_, maximum_, value_;
|
int minimum_, maximum_, value_;
|
||||||
PIChar line_char;
|
PIChar line_char;
|
||||||
};
|
};
|
||||||
@@ -93,12 +93,12 @@ public:
|
|||||||
PISet<int> selected;
|
PISet<int> selected;
|
||||||
int lhei, cur, offset;
|
int lhei, cur, offset;
|
||||||
protected:
|
protected:
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void resizeEvent(int w, int h);
|
void resizeEvent(int w, int h) override;
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||||||
bool mouseEvent(PIKbdListener::MouseEvent me);
|
bool mouseEvent(PIKbdListener::MouseEvent me) override;
|
||||||
bool wheelEvent(PIKbdListener::WheelEvent we);
|
bool wheelEvent(PIKbdListener::WheelEvent we) override;
|
||||||
TileScrollBar * scroll;
|
TileScrollBar * scroll;
|
||||||
bool mouse_sel;
|
bool mouse_sel;
|
||||||
};
|
};
|
||||||
@@ -115,10 +115,10 @@ public:
|
|||||||
PIScreenTypes::CellFormat format;
|
PIScreenTypes::CellFormat format;
|
||||||
PIString text;
|
PIString text;
|
||||||
protected:
|
protected:
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||||||
bool mouseEvent(PIKbdListener::MouseEvent me);
|
bool mouseEvent(PIKbdListener::MouseEvent me) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -137,10 +137,10 @@ public:
|
|||||||
PIVector<Button> content;
|
PIVector<Button> content;
|
||||||
int cur;
|
int cur;
|
||||||
protected:
|
protected:
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||||||
bool mouseEvent(PIKbdListener::MouseEvent me);
|
bool mouseEvent(PIKbdListener::MouseEvent me) override;
|
||||||
struct Rect {
|
struct Rect {
|
||||||
Rect(int _x0 = 0, int _y0 = 0, int _x1 = 0, int _y1 = 0): x0(_x0),y0(_y0),x1(_x1),y1(_y1) {}
|
Rect(int _x0 = 0, int _y0 = 0, int _x1 = 0, int _y1 = 0): x0(_x0),y0(_y0),x1(_x1),y1(_y1) {}
|
||||||
int x0,y0,x1,y1;
|
int x0,y0,x1,y1;
|
||||||
@@ -161,10 +161,10 @@ public:
|
|||||||
PIString text;
|
PIString text;
|
||||||
bool toggled;
|
bool toggled;
|
||||||
protected:
|
protected:
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||||||
bool mouseEvent(PIKbdListener::MouseEvent me);
|
bool mouseEvent(PIKbdListener::MouseEvent me) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -179,8 +179,8 @@ public:
|
|||||||
double maximum;
|
double maximum;
|
||||||
double value;
|
double value;
|
||||||
protected:
|
protected:
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -192,8 +192,8 @@ public:
|
|||||||
PIScreenTypes::CellFormat format;
|
PIScreenTypes::CellFormat format;
|
||||||
int max_lines;
|
int max_lines;
|
||||||
protected:
|
protected:
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -206,9 +206,9 @@ public:
|
|||||||
PIString text;
|
PIString text;
|
||||||
int max_length;
|
int max_length;
|
||||||
protected:
|
protected:
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||||||
void reserCursor();
|
void reserCursor();
|
||||||
int cur, offset;
|
int cur, offset;
|
||||||
bool inv;
|
bool inv;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ private:
|
|||||||
void readConsole();
|
void readConsole();
|
||||||
void getCursor(int & x, int & y);
|
void getCursor(int & x, int & y);
|
||||||
uchar invertColor(uchar c);
|
uchar invertColor(uchar c);
|
||||||
void run();
|
void run() override;
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
void parseInput(const PIString & s);
|
void parseInput(const PIString & s);
|
||||||
bool isCompleteEscSeq(const PIString & es);
|
bool isCompleteEscSeq(const PIString & es);
|
||||||
|
|||||||
@@ -51,8 +51,9 @@ class PIBinaryStream {
|
|||||||
public:
|
public:
|
||||||
// one should implement next methods:
|
// one should implement next methods:
|
||||||
//
|
//
|
||||||
// bool binaryStreamAppendImp(const void * d, size_t s);
|
// bool binaryStreamAppendImp (const void * d, size_t s);
|
||||||
// bool binaryStreamTakeImp ( void * d, size_t s);
|
// bool binaryStreamTakeImp (void * d, size_t s);
|
||||||
|
// ssize_t binaryStreamSizeImp () const;
|
||||||
|
|
||||||
bool binaryStreamAppend(const void * d, size_t s) {
|
bool binaryStreamAppend(const void * d, size_t s) {
|
||||||
if (!static_cast<P*>(this)->binaryStreamAppendImp(d, s)) {
|
if (!static_cast<P*>(this)->binaryStreamAppendImp(d, s)) {
|
||||||
@@ -68,24 +69,16 @@ public:
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t binaryStreamSize() const {
|
||||||
|
return static_cast<P*>(this)->binaryStreamSizeImp();
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void binaryStreamAppend(T v) {binaryStreamAppend(&v, sizeof(v));}
|
void binaryStreamAppend(T v) {binaryStreamAppend(&v, sizeof(v));}
|
||||||
uchar binaryStreamTakeByte(bool * ok = nullptr) {
|
int binaryStreamTakeInt() {
|
||||||
uchar r = 0;
|
|
||||||
if (binaryStreamTake(&r, sizeof(r))) {
|
|
||||||
if (ok) *ok = true;
|
|
||||||
} else {
|
|
||||||
if (ok) *ok = false;
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
int binaryStreamTakeInt(bool * ok = nullptr) {
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
if (binaryStreamTake(&r, sizeof(r))) {
|
binaryStreamTake(&r, sizeof(r));
|
||||||
if (ok) *ok = true;
|
|
||||||
} else {
|
|
||||||
if (ok) *ok = false;
|
|
||||||
}
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -100,13 +93,27 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename P, typename T> inline PIBinaryStream<P> & operator <<(PIBinaryStreamTrivialRef<P> s, const T & v) {s.p << v; return s.p;}
|
template<typename P, typename T> inline PIBinaryStream<P> & operator <<(PIBinaryStreamTrivialRef<P> s, const T & v) {
|
||||||
template<typename P, typename T> inline PIBinaryStream<P> & operator >>(PIBinaryStreamTrivialRef<P> s, T & v) {s.p >> v; return s.p;}
|
s.p << v;
|
||||||
|
return s.p;
|
||||||
|
}
|
||||||
|
template<typename P, typename T> inline PIBinaryStream<P> & operator >>(PIBinaryStreamTrivialRef<P> s, T & v) {
|
||||||
|
s.p >> v;
|
||||||
|
return s.p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// specify types
|
// specify types
|
||||||
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const bool v) {s.binaryStreamAppend((uchar)v); return s;}
|
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const bool v) {
|
||||||
template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, bool & v) {v = s.binaryStreamTakeByte(); return s;}
|
s.binaryStreamAppend((uchar)v);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, bool & v) {
|
||||||
|
uchar c;
|
||||||
|
s.binaryStreamTake(&c, sizeof(c));
|
||||||
|
v = c;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIMemoryBlock v) {
|
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIMemoryBlock v) {
|
||||||
s.binaryStreamAppend(v.data(), v.size());
|
s.binaryStreamAppend(v.data(), v.size());
|
||||||
|
|||||||
@@ -1136,13 +1136,15 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool binaryStreamTakeImp(void * d_, size_t s) {
|
bool binaryStreamTakeImp(void * d_, size_t s) {
|
||||||
if (size() < s)
|
size_t rs = size();
|
||||||
return false;
|
if (rs > s) rs = s;
|
||||||
memcpy(d_, data(), s);
|
memcpy(d_, data(), rs);
|
||||||
remove(0, s);
|
remove(0, rs);
|
||||||
return true;
|
return rs == s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t binaryStreamSizeImp() const {return size();}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PIDeque<uchar> d;
|
PIDeque<uchar> d;
|
||||||
|
|
||||||
|
|||||||
@@ -1511,7 +1511,7 @@ BINARY_STREAM_WRITE(PIString) {s << v.d; return s;}
|
|||||||
//! \relatesalso PIByteArray
|
//! \relatesalso PIByteArray
|
||||||
//! \~english Restore operator.
|
//! \~english Restore operator.
|
||||||
//! \~russian Оператор извлечения.
|
//! \~russian Оператор извлечения.
|
||||||
BINARY_STREAM_READ(PIString) {v.d.clear(); s >> v.d; return s;}
|
BINARY_STREAM_READ(PIString) {s >> v.d; return s;}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns concatenated string.
|
//! \~english Returns concatenated string.
|
||||||
|
|||||||
@@ -127,15 +127,11 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
BINARY_STREAM_WRITE(PIStringList) {
|
BINARY_STREAM_WRITE(PIStringList) {
|
||||||
s.binaryStreamAppend(v.size());
|
s << static_cast<const PIDeque<PIString> &>(v);
|
||||||
for (int i = 0; i < v.size_s(); ++i)
|
|
||||||
s << v[i];
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
BINARY_STREAM_READ(PIStringList) {
|
BINARY_STREAM_READ(PIStringList) {
|
||||||
v.resize(s.binaryStreamTakeInt());
|
s >> static_cast<PIDeque<PIString> &>(v);
|
||||||
for (int i = 0; i < v.size_s(); ++i)
|
|
||||||
s >> v[i];
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,8 +147,8 @@ public:
|
|||||||
//! \~english Read character
|
//! \~english Read character
|
||||||
//! \~russian Читает символ
|
//! \~russian Читает символ
|
||||||
char takeChar(bool * rok) {
|
char takeChar(bool * rok) {
|
||||||
bool ok = true;
|
char ret;
|
||||||
char ret = (char)s->binaryStreamTakeByte(&ok);
|
bool ok = s->binaryStreamTake(&ret, sizeof(ret));
|
||||||
if (!ok) is_end = true;
|
if (!ok) is_end = true;
|
||||||
if (rok) *rok = ok;
|
if (rok) *rok = ok;
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -409,8 +409,9 @@ int PIBinaryLog::readDevice(void *read_to, int max_size) {
|
|||||||
if (max_size <= 0 || read_to == 0) return -1;
|
if (max_size <= 0 || read_to == 0) return -1;
|
||||||
BinLogRecord br;
|
BinLogRecord br;
|
||||||
br.id = 0;
|
br.id = 0;
|
||||||
if (filterID.isEmpty()) br = readRecord();
|
if (filterID.isEmpty()) {
|
||||||
else {
|
br = readRecord();
|
||||||
|
} else {
|
||||||
while (!filterID.contains(br.id) && !isEnd()) br = readRecord();
|
while (!filterID.contains(br.id) && !isEnd()) br = readRecord();
|
||||||
}
|
}
|
||||||
if (br.id == -1) {
|
if (br.id == -1) {
|
||||||
|
|||||||
@@ -301,18 +301,18 @@ public:
|
|||||||
static bool joinBinLogsSerial(const PIStringList & src, const PIString & dst);
|
static bool joinBinLogsSerial(const PIStringList & src, const PIString & dst);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
virtual void configureFromFullPathDevice(const PIString & full_path) override;
|
void configureFromFullPathDevice(const PIString & full_path) override;
|
||||||
virtual PIPropertyStorage constructVariantDevice() const override;
|
PIPropertyStorage constructVariantDevice() const override;
|
||||||
virtual void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
||||||
virtual int readDevice(void *read_to, int max_size) override;
|
int readDevice(void *read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int size) override;
|
int writeDevice(const void * data, int size) override;
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual void propertyChanged(const char * s) override;
|
void propertyChanged(const char * s) override;
|
||||||
virtual bool threadedRead(const uchar *readed, int size) override;
|
bool threadedRead(const uchar *readed, int size) override;
|
||||||
virtual void threadedReadTerminated() override {pausemutex.unlock();}
|
void threadedReadTerminated() override {pausemutex.unlock();}
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct PIP_EXPORT BinLogRecord {
|
struct PIP_EXPORT BinLogRecord {
|
||||||
|
|||||||
@@ -41,15 +41,15 @@ public:
|
|||||||
int readedCANID() const;
|
int readedCANID() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int max_size) override;
|
int writeDevice(const void * data, int max_size) override;
|
||||||
virtual PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
virtual void configureFromFullPathDevice(const PIString & full_path) override;
|
void configureFromFullPathDevice(const PIString & full_path) override;
|
||||||
virtual PIPropertyStorage constructVariantDevice() const override;
|
PIPropertyStorage constructVariantDevice() const override;
|
||||||
virtual void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int sock;
|
int sock;
|
||||||
|
|||||||
@@ -462,24 +462,24 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
explicit PIEthernet(int sock, PIString ip_port);
|
explicit PIEthernet(int sock, PIString ip_port);
|
||||||
|
|
||||||
virtual void propertyChanged(const char * name) override;
|
void propertyChanged(const char * name) override;
|
||||||
|
|
||||||
virtual PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
virtual void configureFromFullPathDevice(const PIString & full_path) override;
|
void configureFromFullPathDevice(const PIString & full_path) override;
|
||||||
virtual PIPropertyStorage constructVariantDevice() const override;
|
PIPropertyStorage constructVariantDevice() const override;
|
||||||
virtual void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
||||||
virtual bool configureDevice(const void * e_main, const void * e_parent = 0) override;
|
bool configureDevice(const void * e_main, const void * e_parent = 0) override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int max_size) override;
|
int writeDevice(const void * data, int max_size) override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override;
|
DeviceInfoFlags deviceInfoFlags() const override;
|
||||||
|
|
||||||
//! Executes when any read function was successful. Default implementation does nothing
|
//! Executes when any read function was successful. Default implementation does nothing
|
||||||
virtual void received(const void * data, int size) {;}
|
virtual void received(const void * data, int size) {;}
|
||||||
|
|
||||||
void construct();
|
void construct();
|
||||||
virtual bool init() override;
|
bool init() override;
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
void closeSocket(int & sd);
|
void closeSocket(int & sd);
|
||||||
void applyTimeouts();
|
void applyTimeouts();
|
||||||
void applyTimeout(int fd, int opt, double ms);
|
void applyTimeout(int fd, int opt, double ms);
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ public:
|
|||||||
|
|
||||||
//! \~english Immediate write all buffered data to disk
|
//! \~english Immediate write all buffered data to disk
|
||||||
//! \~russian Немедленно записывает все буферизированные данные на диск
|
//! \~russian Немедленно записывает все буферизированные данные на диск
|
||||||
virtual void flush() override;
|
void flush() override;
|
||||||
|
|
||||||
//! \~english Move read/write position to "position"
|
//! \~english Move read/write position to "position"
|
||||||
//! \~russian Перемещает позицию чтения/записи на "position"
|
//! \~russian Перемещает позицию чтения/записи на "position"
|
||||||
@@ -226,6 +226,8 @@ public:
|
|||||||
//! \~english Returns file size in bytes
|
//! \~english Returns file size in bytes
|
||||||
//! \~russian Возвращает размер файла в байтах
|
//! \~russian Возвращает размер файла в байтах
|
||||||
llong size() const;
|
llong size() const;
|
||||||
|
|
||||||
|
ssize_t bytesAvailible() const override {return size() - pos();}
|
||||||
|
|
||||||
//! \~english Returns read/write position
|
//! \~english Returns read/write position
|
||||||
//! \~russian Возвращает позицию чтения/записи
|
//! \~russian Возвращает позицию чтения/записи
|
||||||
@@ -324,15 +326,15 @@ public:
|
|||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
virtual void configureFromFullPathDevice(const PIString & full_path) override;
|
void configureFromFullPathDevice(const PIString & full_path) override;
|
||||||
virtual PIPropertyStorage constructVariantDevice() const override;
|
PIPropertyStorage constructVariantDevice() const override;
|
||||||
virtual void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int max_size) override;
|
int writeDevice(const void * data, int max_size) override;
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential | PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential | PIIODevice::Reliable;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PIString strType(const PIIODevice::DeviceMode type);
|
PIString strType(const PIIODevice::DeviceMode type);
|
||||||
|
|||||||
@@ -112,9 +112,9 @@ private:
|
|||||||
void exportGPIO(int gpio_num);
|
void exportGPIO(int gpio_num);
|
||||||
void openGPIO(GPIOData & g);
|
void openGPIO(GPIOData & g);
|
||||||
bool getPinState(int gpio_num);
|
bool getPinState(int gpio_num);
|
||||||
void begin();
|
void begin() override;
|
||||||
void run();
|
void run() override;
|
||||||
void end();
|
void end() override;
|
||||||
|
|
||||||
static PIString GPIOName(int gpio_num);
|
static PIString GPIOName(int gpio_num);
|
||||||
|
|
||||||
|
|||||||
@@ -83,12 +83,17 @@ public:
|
|||||||
//! \~english Insert data "ba" into content at current position
|
//! \~english Insert data "ba" into content at current position
|
||||||
//! \~russian Вставляет данные "ba" в содержимое буфера в текущую позицию
|
//! \~russian Вставляет данные "ba" в содержимое буфера в текущую позицию
|
||||||
int writeByteArray(const PIByteArray & ba);
|
int writeByteArray(const PIByteArray & ba);
|
||||||
|
|
||||||
|
ssize_t bytesAvailible() const override {
|
||||||
|
if (data_) return data_->size();
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual int readDevice(void * read_to, int size) override;
|
int readDevice(void * read_to, int size) override;
|
||||||
virtual int writeDevice(const void * data_, int size) override;
|
int writeDevice(const void * data_, int size) override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential | PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential | PIIODevice::Reliable;}
|
||||||
|
|
||||||
ssize_t pos;
|
ssize_t pos;
|
||||||
PIByteArray * data_;
|
PIByteArray * data_;
|
||||||
|
|||||||
@@ -230,8 +230,7 @@ void PIIODevice::stop(bool hard) {
|
|||||||
PIByteArray PIIODevice::read(int max_size) {
|
PIByteArray PIIODevice::read(int max_size) {
|
||||||
buffer_in.resize(max_size);
|
buffer_in.resize(max_size);
|
||||||
int ret = readDevice(buffer_in.data(), max_size);
|
int ret = readDevice(buffer_in.data(), max_size);
|
||||||
if (ret < 0)
|
if (ret < 0) return PIByteArray();
|
||||||
return PIByteArray();
|
|
||||||
return buffer_in.resized(ret);
|
return buffer_in.resized(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ typedef bool (*ReadRetFunc)(const uchar *, int, void *);
|
|||||||
PIOBJECT_SUBCLASS(name, PIIODevice) \
|
PIOBJECT_SUBCLASS(name, PIIODevice) \
|
||||||
PIIODevice * copy() const override {return new name();} \
|
PIIODevice * copy() const override {return new name();} \
|
||||||
public: \
|
public: \
|
||||||
virtual PIConstChars fullPathPrefix() const override {return prefix;} \
|
PIConstChars fullPathPrefix() const override {return prefix;} \
|
||||||
static PIConstChars fullPathPrefixS() {return prefix;} \
|
static PIConstChars fullPathPrefixS() {return prefix;} \
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -284,6 +284,17 @@ public:
|
|||||||
//! \~russian Читает из устройства не более "max_size" байт и возвращает данные как PIByteArray
|
//! \~russian Читает из устройства не более "max_size" байт и возвращает данные как PIByteArray
|
||||||
PIByteArray read(int max_size);
|
PIByteArray read(int max_size);
|
||||||
|
|
||||||
|
//! \~english Returns the number of bytes that are available for reading.
|
||||||
|
//! \~russian Возвращает количество байт
|
||||||
|
//! \~\details
|
||||||
|
//! \~english This function is commonly used with sequential devices
|
||||||
|
//! to determine the number of bytes to allocate in a buffer before reading.
|
||||||
|
//! If function returns -1 it mean that number of bytes undefined.
|
||||||
|
//! \~russian Эта функция как правило используется чтобы знать какой
|
||||||
|
//! размер буфера нужен в памяти для чтения.
|
||||||
|
//! Если функция возвращает -1 это значит что количество байт для чтения не известно.
|
||||||
|
virtual ssize_t bytesAvailible() const {return -1;}
|
||||||
|
|
||||||
//! \~english Write maximum "max_size" bytes of "data" to device
|
//! \~english Write maximum "max_size" bytes of "data" to device
|
||||||
//! \~russian Пишет в устройство не более "max_size" байт из "data"
|
//! \~russian Пишет в устройство не более "max_size" байт из "data"
|
||||||
int write(const void * data, int max_size) {return writeDevice(data, max_size);}
|
int write(const void * data, int max_size) {return writeDevice(data, max_size);}
|
||||||
@@ -536,7 +547,7 @@ private:
|
|||||||
EVENT_HANDLER2(void, check_start, void * , data, int, delim);
|
EVENT_HANDLER2(void, check_start, void * , data, int, delim);
|
||||||
EVENT_HANDLER(void, write_func);
|
EVENT_HANDLER(void, write_func);
|
||||||
|
|
||||||
virtual PIIODevice * copy() const {return 0;}
|
virtual PIIODevice * copy() const {return nullptr;}
|
||||||
PIString fullPathOptions() const;
|
PIString fullPathOptions() const;
|
||||||
void _init();
|
void _init();
|
||||||
void begin() override;
|
void begin() override;
|
||||||
|
|||||||
@@ -47,12 +47,17 @@ public:
|
|||||||
|
|
||||||
bool binaryStreamAppendImp(const void * d, size_t s) {
|
bool binaryStreamAppendImp(const void * d, size_t s) {
|
||||||
if (!dev) return false;
|
if (!dev) return false;
|
||||||
return dev->write(d, s);
|
return (dev->write(d, s) == (int)s);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool binaryStreamTakeImp(void * d, size_t s) {
|
bool binaryStreamTakeImp(void * d, size_t s) {
|
||||||
if (!dev) return false;
|
if (!dev) return false;
|
||||||
return dev->read(d, s);
|
return (dev->read(d, s) == (int)s);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t binaryStreamSizeImp() const {
|
||||||
|
if (!dev) return 0;
|
||||||
|
return dev->bytesAvailible();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -56,9 +56,9 @@ bool PIIOString::open(const PIString & string) {
|
|||||||
PIString PIIOString::readLine() {
|
PIString PIIOString::readLine() {
|
||||||
if (!canRead() || !str) return PIString();
|
if (!canRead() || !str) return PIString();
|
||||||
int np = pos;
|
int np = pos;
|
||||||
while (++np < str->size_s())
|
while (++np < str->size_s()) {
|
||||||
if ((*str)[np] == '\n')
|
if ((*str)[np] == '\n') break;
|
||||||
break;
|
}
|
||||||
PIString ret = str->mid(pos, np - pos);
|
PIString ret = str->mid(pos, np - pos);
|
||||||
pos = piMini(np + 1, str->size_s());
|
pos = piMini(np + 1, str->size_s());
|
||||||
return ret;
|
return ret;
|
||||||
@@ -66,7 +66,7 @@ PIString PIIOString::readLine() {
|
|||||||
|
|
||||||
|
|
||||||
int PIIOString::readDevice(void * read_to, int max_size) {
|
int PIIOString::readDevice(void * read_to, int max_size) {
|
||||||
if (!canRead() || !str) return -1;
|
if (!canRead() || !str || max_size <= 0) return -1;
|
||||||
PIString rs = str->mid(pos, max_size);
|
PIString rs = str->mid(pos, max_size);
|
||||||
pos += max_size;
|
pos += max_size;
|
||||||
if (pos > str->size_s()) pos = str->size_s();
|
if (pos > str->size_s()) pos = str->size_s();
|
||||||
|
|||||||
@@ -88,11 +88,16 @@ public:
|
|||||||
//! \~russian Вставляет строку "string" в содержимое буфера в текущую позицию
|
//! \~russian Вставляет строку "string" в содержимое буфера в текущую позицию
|
||||||
int writeString(const PIString & string);
|
int writeString(const PIString & string);
|
||||||
|
|
||||||
|
ssize_t bytesAvailible() const override {
|
||||||
|
if (str) return str->size() - pos;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int max_size) override;
|
int writeDevice(const void * data, int max_size) override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential | PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential | PIIODevice::Reliable;}
|
||||||
|
|
||||||
ssize_t pos;
|
ssize_t pos;
|
||||||
PIString * str;
|
PIString * str;
|
||||||
|
|||||||
@@ -924,6 +924,15 @@ void PIPeer::changeName(const PIString &new_name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ssize_t PIPeer::bytesAvailible() const {
|
||||||
|
ssize_t ret = 0;
|
||||||
|
read_buffer_mutex.lock();
|
||||||
|
if (!read_buffer.isEmpty()) ret = read_buffer.back().size();
|
||||||
|
read_buffer_mutex.unlock();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int PIPeer::readDevice(void *read_to, int max_size) {
|
int PIPeer::readDevice(void *read_to, int max_size) {
|
||||||
read_buffer_mutex.lock();
|
read_buffer_mutex.lock();
|
||||||
bool empty = read_buffer.isEmpty();
|
bool empty = read_buffer.isEmpty();
|
||||||
|
|||||||
@@ -116,6 +116,8 @@ public:
|
|||||||
void setTrustPeerName(const PIString & peer_name) {trust_peer = peer_name;}
|
void setTrustPeerName(const PIString & peer_name) {trust_peer = peer_name;}
|
||||||
void setTcpServerIP(const PIString & ip) {server_ip = ip; tcpClientReconnect();}
|
void setTcpServerIP(const PIString & ip) {server_ip = ip; tcpClientReconnect();}
|
||||||
|
|
||||||
|
ssize_t bytesAvailible() const override;
|
||||||
|
|
||||||
|
|
||||||
EVENT2(dataReceivedEvent, const PIString &, from, const PIByteArray &, data);
|
EVENT2(dataReceivedEvent, const PIString &, from, const PIByteArray &, data);
|
||||||
EVENT1(peerConnectedEvent, const PIString &, name);
|
EVENT1(peerConnectedEvent, const PIString &, name);
|
||||||
@@ -164,15 +166,15 @@ private:
|
|||||||
void addToRemoved(const PeerInfo & pi) {removed[pi.name] = PIPair<int, PISystemTime>(pi.cnt, pi.time);}
|
void addToRemoved(const PeerInfo & pi) {removed[pi.name] = PIPair<int, PISystemTime>(pi.cnt, pi.time);}
|
||||||
bool isRemoved(const PeerInfo & pi) const {return (removed.value(pi.name) == PIPair<int, PISystemTime>(pi.cnt, pi.time));}
|
bool isRemoved(const PeerInfo & pi) const {return (removed.value(pi.name) == PIPair<int, PISystemTime>(pi.cnt, pi.time));}
|
||||||
|
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
virtual void configureFromFullPathDevice(const PIString &full_path) override;
|
void configureFromFullPathDevice(const PIString &full_path) override;
|
||||||
virtual PIPropertyStorage constructVariantDevice() const override;
|
PIPropertyStorage constructVariantDevice() const override;
|
||||||
virtual void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int size) override;
|
int writeDevice(const void * data, int size) override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
||||||
|
|
||||||
PeerInfo * quickestPeer(const PIString & to);
|
PeerInfo * quickestPeer(const PIString & to);
|
||||||
bool sendToNeighbour(PeerInfo * peer, const PIByteArray & ba);
|
bool sendToNeighbour(PeerInfo * peer, const PIByteArray & ba);
|
||||||
@@ -198,7 +200,7 @@ private:
|
|||||||
bool destroyed, no_timer;
|
bool destroyed, no_timer;
|
||||||
PIString trust_peer;
|
PIString trust_peer;
|
||||||
PIString server_ip;
|
PIString server_ip;
|
||||||
PIMutex read_buffer_mutex;
|
mutable PIMutex read_buffer_mutex;
|
||||||
PIQueue<PIByteArray> read_buffer;
|
PIQueue<PIByteArray> read_buffer;
|
||||||
int read_buffer_size;
|
int read_buffer_size;
|
||||||
PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex, send_mc_mutex;
|
PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex, send_mc_mutex;
|
||||||
|
|||||||
@@ -282,19 +282,19 @@ public:
|
|||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
virtual void configureFromFullPathDevice(const PIString & full_path) override;
|
void configureFromFullPathDevice(const PIString & full_path) override;
|
||||||
virtual PIPropertyStorage constructVariantDevice() const override;
|
PIPropertyStorage constructVariantDevice() const override;
|
||||||
virtual void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
||||||
virtual bool configureDevice(const void * e_main, const void * e_parent = 0) override;
|
bool configureDevice(const void * e_main, const void * e_parent = 0) override;
|
||||||
virtual void optionsChanged() override;
|
void optionsChanged() override;
|
||||||
virtual void threadedReadBufferSizeChanged() override;
|
void threadedReadBufferSizeChanged() override;
|
||||||
|
|
||||||
//! \~english Basic read function
|
//! \~english Basic read function
|
||||||
//! \~russian Базовое чтение
|
//! \~russian Базовое чтение
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int max_size) override;
|
int writeDevice(const void * data, int max_size) override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential;}
|
||||||
|
|
||||||
//! Executes when any read function was successful. Default implementation does nothing
|
//! Executes when any read function was successful. Default implementation does nothing
|
||||||
virtual void received(const void * data, int size) {;}
|
virtual void received(const void * data, int size) {;}
|
||||||
@@ -306,8 +306,8 @@ protected:
|
|||||||
bool setBit(int bit, bool on, const PIString & bname);
|
bool setBit(int bit, bool on, const PIString & bname);
|
||||||
bool isBit(int bit, const PIString & bname) const;
|
bool isBit(int bit, const PIString & bname) const;
|
||||||
|
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
|
|
||||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||||
int fd, vtime;
|
int fd, vtime;
|
||||||
|
|||||||
@@ -91,15 +91,15 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
virtual void configureFromFullPathDevice(const PIString & full_path) override;
|
void configureFromFullPathDevice(const PIString & full_path) override;
|
||||||
virtual PIPropertyStorage constructVariantDevice() const override;
|
PIPropertyStorage constructVariantDevice() const override;
|
||||||
virtual void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override {return read(read_to, max_size, 0);}
|
int readDevice(void * read_to, int max_size) override {return read(read_to, max_size, 0);}
|
||||||
virtual int writeDevice(const void * data, int max_size) override {return write(data, max_size, 0);}
|
int writeDevice(const void * data, int max_size) override {return write(data, max_size, 0);}
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initPrivate();
|
void initPrivate();
|
||||||
|
|||||||
@@ -88,6 +88,11 @@ bool PISPI::isParameterSet(PISPI::Parameters parameter) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ssize_t PISPI::bytesAvailible() const {
|
||||||
|
return recv_buf.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PISPI::openDevice() {
|
bool PISPI::openDevice() {
|
||||||
#ifdef PIP_SPI
|
#ifdef PIP_SPI
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@@ -126,7 +131,7 @@ bool PISPI::closeDevice() {
|
|||||||
int PISPI::readDevice(void * read_to, int max_size) {
|
int PISPI::readDevice(void * read_to, int max_size) {
|
||||||
int sz = piMini(recv_buf.size_s(), max_size);
|
int sz = piMini(recv_buf.size_s(), max_size);
|
||||||
memcpy(read_to, recv_buf.data(), sz);
|
memcpy(read_to, recv_buf.data(), sz);
|
||||||
recv_buf.resize(recv_buf.size_s() - sz);
|
recv_buf.remove(0, sz);
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,18 +60,19 @@ public:
|
|||||||
//! Returns parameters
|
//! Returns parameters
|
||||||
PIFlags<PISPI::Parameters> parameters() const {return spi_mode;}
|
PIFlags<PISPI::Parameters> parameters() const {return spi_mode;}
|
||||||
|
|
||||||
|
ssize_t bytesAvailible() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int max_size) override;
|
int writeDevice(const void * data, int max_size) override;
|
||||||
|
|
||||||
virtual PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
virtual void configureFromFullPathDevice(const PIString & full_path) override;
|
void configureFromFullPathDevice(const PIString & full_path) override;
|
||||||
virtual PIPropertyStorage constructVariantDevice() const override;
|
PIPropertyStorage constructVariantDevice() const override;
|
||||||
virtual void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
void configureFromVariantDevice(const PIPropertyStorage & d) override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint spi_speed;
|
uint spi_speed;
|
||||||
|
|||||||
@@ -49,6 +49,15 @@ PITransparentDevice::~PITransparentDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ssize_t PITransparentDevice::bytesAvailible() const {
|
||||||
|
ssize_t ret = 0;
|
||||||
|
que_mutex.lock();
|
||||||
|
if (que.isNotEmpty()) ret = que.back().size();
|
||||||
|
que_mutex.unlock();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int PITransparentDevice::readDevice(void * read_to, int max_size) {
|
int PITransparentDevice::readDevice(void * read_to, int max_size) {
|
||||||
if (!canRead()) return -1;
|
if (!canRead()) return -1;
|
||||||
que_mutex.lock();
|
que_mutex.lock();
|
||||||
|
|||||||
@@ -44,14 +44,16 @@ public:
|
|||||||
|
|
||||||
virtual ~PITransparentDevice();
|
virtual ~PITransparentDevice();
|
||||||
|
|
||||||
protected:
|
ssize_t bytesAvailible() const override;
|
||||||
virtual bool openDevice() override;
|
|
||||||
virtual bool closeDevice() override;
|
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
|
||||||
virtual int writeDevice(const void * data, int max_size) override;
|
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
|
||||||
|
|
||||||
PIMutex que_mutex;
|
protected:
|
||||||
|
bool openDevice() override;
|
||||||
|
bool closeDevice() override;
|
||||||
|
int readDevice(void * read_to, int max_size) override;
|
||||||
|
int writeDevice(const void * data, int max_size) override;
|
||||||
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
||||||
|
|
||||||
|
mutable PIMutex que_mutex;
|
||||||
PIQueue<PIByteArray> que;
|
PIQueue<PIByteArray> que;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -160,14 +160,14 @@ public:
|
|||||||
virtual void flush() override;
|
virtual void flush() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool configureDevice(const void * e_main, const void * e_parent = 0) override;
|
bool configureDevice(const void * e_main, const void * e_parent = 0) override;
|
||||||
virtual PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
virtual void configureFromFullPathDevice(const PIString & full_path) override;
|
void configureFromFullPathDevice(const PIString & full_path) override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int max_size) override;
|
int writeDevice(const void * data, int max_size) override;
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}
|
||||||
|
|
||||||
PIVector<PIUSB::Endpoint> eps;
|
PIVector<PIUSB::Endpoint> eps;
|
||||||
ushort vid_, pid_;
|
ushort vid_, pid_;
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ private:
|
|||||||
EVENT_HANDLER2(void, mcastRead, const uchar * , data, int, size);
|
EVENT_HANDLER2(void, mcastRead, const uchar * , data, int, size);
|
||||||
void destroyAll();
|
void destroyAll();
|
||||||
void initAll(PIVector<PIEthernet::Address> al);
|
void initAll(PIVector<PIEthernet::Address> al);
|
||||||
void run();
|
void run() override;
|
||||||
|
|
||||||
Channels _channels;
|
Channels _channels;
|
||||||
PIEthernet::Address mcast_address;
|
PIEthernet::Address mcast_address;
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ public:
|
|||||||
PIVector<PIConnection * > listeners;
|
PIVector<PIConnection * > listeners;
|
||||||
};
|
};
|
||||||
|
|
||||||
void run();
|
void run() override;
|
||||||
|
|
||||||
void deviceReaded(DeviceData * dd, const PIByteArray & data);
|
void deviceReaded(DeviceData * dd, const PIByteArray & data);
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ private:
|
|||||||
PIVector<PIIODevice * > devices;
|
PIVector<PIIODevice * > devices;
|
||||||
PIByteArray sdata;
|
PIByteArray sdata;
|
||||||
float int_;
|
float int_;
|
||||||
void tick(void * , int);
|
void tick(void * , int) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
PIMap<PIString, Extractor * > extractors;
|
PIMap<PIString, Extractor * > extractors;
|
||||||
|
|||||||
@@ -138,9 +138,9 @@ private:
|
|||||||
friend bool operator !=(const PIDiagnostics::Entry & f, const PIDiagnostics::Entry & s);
|
friend bool operator !=(const PIDiagnostics::Entry & f, const PIDiagnostics::Entry & s);
|
||||||
friend bool operator <(const PIDiagnostics::Entry & f, const PIDiagnostics::Entry & s);
|
friend bool operator <(const PIDiagnostics::Entry & f, const PIDiagnostics::Entry & s);
|
||||||
|
|
||||||
void tick(void *, int);
|
void tick(void *, int) override;
|
||||||
Entry calcHistory(PIQueue<Entry> & hist, int & cnt);
|
Entry calcHistory(PIQueue<Entry> & hist, int & cnt);
|
||||||
void propertyChanged(const char *);
|
void propertyChanged(const char *) override;
|
||||||
void changeDisconnectTimeout(float disct);
|
void changeDisconnectTimeout(float disct);
|
||||||
|
|
||||||
PIQueue<Entry> history_rec, history_send;
|
PIQueue<Entry> history_rec, history_send;
|
||||||
|
|||||||
@@ -137,6 +137,12 @@ void PIPacketExtractor::setDevice(PIIODevice * device_) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ssize_t PIPacketExtractor::bytesAvailible() const {
|
||||||
|
if (dev) return dev->bytesAvailible();
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIPacketExtractor::setBufferSize(int new_size) {
|
void PIPacketExtractor::setBufferSize(int new_size) {
|
||||||
buffer_size = new_size;
|
buffer_size = new_size;
|
||||||
buffer.resize(buffer_size);
|
buffer.resize(buffer_size);
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public:
|
|||||||
//! Set child %device to "device_"
|
//! Set child %device to "device_"
|
||||||
void setDevice(PIIODevice * device_);
|
void setDevice(PIIODevice * device_);
|
||||||
|
|
||||||
|
ssize_t bytesAvailible() const override;
|
||||||
|
|
||||||
//! Returns buffer size
|
//! Returns buffer size
|
||||||
int bufferSize() const {return buffer_size;}
|
int bufferSize() const {return buffer_size;}
|
||||||
@@ -164,14 +165,14 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void construct();
|
void construct();
|
||||||
void propertyChanged(const char *);
|
void propertyChanged(const char *) override;
|
||||||
virtual int readDevice(void * read_to, int max_size) override;
|
int readDevice(void * read_to, int max_size) override;
|
||||||
virtual int writeDevice(const void * data, int max_size) override;
|
int writeDevice(const void * data, int max_size) override;
|
||||||
virtual bool threadedRead(const uchar * readed, int size) override;
|
bool threadedRead(const uchar * readed, int size) override;
|
||||||
virtual PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
virtual bool openDevice() override;
|
bool openDevice() override;
|
||||||
virtual bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const override;
|
DeviceInfoFlags deviceInfoFlags() const override;
|
||||||
|
|
||||||
PIIODevice * dev;
|
PIIODevice * dev;
|
||||||
PIByteArray buffer, tmpbuf, src_header, src_footer, trbuf;
|
PIByteArray buffer, tmpbuf, src_header, src_footer, trbuf;
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ public:
|
|||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void run();
|
void run() override;
|
||||||
void exec_();
|
void exec_();
|
||||||
void startProc(bool detached);
|
void startProc(bool detached);
|
||||||
|
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ public:
|
|||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void begin();
|
void begin() override;
|
||||||
void run();
|
void run() override;
|
||||||
void waitFirst() const;
|
void waitFirst() const;
|
||||||
|
|
||||||
PISharedMemory * shm;
|
PISharedMemory * shm;
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void run();
|
void run() override;
|
||||||
void gatherThread(llong id);
|
void gatherThread(llong id);
|
||||||
float calcThreadUsage(PISystemTime & t_new, PISystemTime & t_old);
|
float calcThreadUsage(PISystemTime & t_new, PISystemTime & t_old);
|
||||||
|
|
||||||
|
|||||||
@@ -147,10 +147,10 @@ protected:
|
|||||||
mutable PIMutex rec_mutex;
|
mutable PIMutex rec_mutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void begin() {
|
void begin() override {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
void run() {
|
void run() override {
|
||||||
if (!isOpened()) {
|
if (!isOpened()) {
|
||||||
open();
|
open();
|
||||||
diag_.reset();
|
diag_.reset();
|
||||||
@@ -185,7 +185,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void end() {
|
void end() override {
|
||||||
stopRecord();
|
stopRecord();
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ protected:
|
|||||||
uint max_size;
|
uint max_size;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void begin() {cnt = 0;}
|
void begin() override {cnt = 0;}
|
||||||
void run() {
|
void run() override {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
while (in.isEmpty()) {
|
while (in.isEmpty()) {
|
||||||
cv.wait(mutex);
|
cv.wait(mutex);
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ private:
|
|||||||
static Pool * instance();
|
static Pool * instance();
|
||||||
void add(_PITimerImp_Pool * t);
|
void add(_PITimerImp_Pool * t);
|
||||||
void remove(_PITimerImp_Pool * t);
|
void remove(_PITimerImp_Pool * t);
|
||||||
void run();
|
void run() override;
|
||||||
PIVector<_PITimerImp_Pool * > timers, to_remove;
|
PIVector<_PITimerImp_Pool * > timers, to_remove;
|
||||||
private:
|
private:
|
||||||
explicit Pool();
|
explicit Pool();
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ private:
|
|||||||
EVENT_HANDLER(void, termTimerTick);
|
EVENT_HANDLER(void, termTimerTick);
|
||||||
|
|
||||||
void startAction(PacketType a, const PIString & dir, const PIStringList & fl);
|
void startAction(PacketType a, const PIString & dir, const PIStringList & fl);
|
||||||
void run();
|
void run() override;
|
||||||
|
|
||||||
PIDir dir_my;
|
PIDir dir_my;
|
||||||
PIVector<PIFile::FileInfo> my_filelist;
|
PIVector<PIFile::FileInfo> my_filelist;
|
||||||
@@ -140,9 +140,9 @@ private:
|
|||||||
TileButtons * buttons;
|
TileButtons * buttons;
|
||||||
PIFileTransfer * ft;
|
PIFileTransfer * ft;
|
||||||
PITimeMeasurer tm, tme;
|
PITimeMeasurer tm, tme;
|
||||||
void resizeEvent(int w, int h);
|
void resizeEvent(int w, int h) override;
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
bool rec;
|
bool rec;
|
||||||
PIString conn_name;
|
PIString conn_name;
|
||||||
EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e);
|
EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e);
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ private:
|
|||||||
TileDir();
|
TileDir();
|
||||||
void updateDir();
|
void updateDir();
|
||||||
void buildNames();
|
void buildNames();
|
||||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||||||
void sizeHint(int & w, int & h) const;
|
void sizeHint(int & w, int & h) const override;
|
||||||
void resizeEvent(int w, int h);
|
void resizeEvent(int w, int h) override;
|
||||||
void lock();
|
void lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
void showReading();
|
void showReading();
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ public:
|
|||||||
}
|
}
|
||||||
screen->unlock();
|
screen->unlock();
|
||||||
}
|
}
|
||||||
void tick(void* data_, int delimiter) {
|
void tick(void* data_, int delimiter) override {
|
||||||
if (tpeerdiag->visible || tpeer->visible)
|
if (tpeerdiag->visible || tpeer->visible)
|
||||||
updatePeerInfo();
|
updatePeerInfo();
|
||||||
if (tinfo->visible)
|
if (tinfo->visible)
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ public:
|
|||||||
EVENT(closeRequest)
|
EVENT(closeRequest)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drawEvent(PIScreenDrawer * d);
|
void drawEvent(PIScreenDrawer * d) override;
|
||||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||||||
void resizeEvent(int w, int h);
|
void resizeEvent(int w, int h) override;
|
||||||
|
|
||||||
PIVector<PIVector<PIScreenTypes::Cell> > cells;
|
PIVector<PIVector<PIScreenTypes::Cell> > cells;
|
||||||
char lastp[3];
|
char lastp[3];
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ private:
|
|||||||
PIEthernet eth;
|
PIEthernet eth;
|
||||||
bool quet_;
|
bool quet_;
|
||||||
|
|
||||||
void tick(void *, int) {
|
void tick(void *, int) override {
|
||||||
if (ft.isStarted()) {
|
if (ft.isStarted()) {
|
||||||
ftevent();
|
ftevent();
|
||||||
updatePMT();
|
updatePMT();
|
||||||
|
|||||||
Reference in New Issue
Block a user