PIObject::deleted now has 1 argument
PIIODevice small refactoring new PIIODevice virtual methods: threadedReadTerminated() and threadedWriteTerminated() PIIODevice::stop now accept bool "hard" instead of "wait" PIStreamPacker new features: packet size crypt and aggressive optimization
This commit is contained in:
@@ -154,21 +154,62 @@ bool PIIODevice::setOption(PIIODevice::DeviceOption o, bool yes) {
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::stopThreadedRead() {
|
||||
bool stopThread(PIThread * t, bool hard) {
|
||||
#ifdef FREERTOS
|
||||
PIThread::stop(true);
|
||||
t->stop(true);
|
||||
#else
|
||||
PIThread::terminate();
|
||||
if (hard) {
|
||||
t->terminate();
|
||||
return true;
|
||||
} else {
|
||||
t->stop();
|
||||
if (t->waitForFinish(10000)) {
|
||||
t->terminate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::stopThreadedWrite() {
|
||||
#ifdef FREERTOS
|
||||
write_thread.stop(true);
|
||||
#else
|
||||
write_thread.terminate();
|
||||
#endif
|
||||
void PIIODevice::stopThreadedRead(bool hard) {
|
||||
if (stopThread(this, hard))
|
||||
threadedReadTerminated();
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::stopThreadedWrite(bool hard) {
|
||||
if (stopThread(&write_thread, hard))
|
||||
threadedWriteTerminated();
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::clearThreadedWriteQueue() {
|
||||
write_thread.lock();
|
||||
write_queue.clear();
|
||||
write_thread.unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::start() {
|
||||
startThreadedRead();
|
||||
startThreadedWrite();
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::stop(bool hard) {
|
||||
stopThreadedRead(hard);
|
||||
stopThreadedWrite(hard);
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIODevice::read(int max_size) {
|
||||
buffer_in.resize(max_size);
|
||||
int ret = readDevice(buffer_in.data(), max_size);
|
||||
if (ret < 0)
|
||||
return PIByteArray();
|
||||
return buffer_in.resized(ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +224,7 @@ void PIIODevice::_init() {
|
||||
setReopenTimeout(1000);
|
||||
#ifdef FREERTOS
|
||||
threaded_read_buffer_size = 512;
|
||||
// setThreadedReadBufferSize(512);
|
||||
//setThreadedReadBufferSize(512);
|
||||
#else
|
||||
threaded_read_buffer_size = 4096;
|
||||
#endif
|
||||
@@ -314,6 +355,41 @@ ullong PIIODevice::writeThreaded(const PIByteArray & data) {
|
||||
}
|
||||
|
||||
|
||||
bool PIIODevice::open() {
|
||||
if (!init_) init();
|
||||
buffer_tr.resize(threaded_read_buffer_size);
|
||||
opened_ = openDevice();
|
||||
if (opened_) opened();
|
||||
return opened_;
|
||||
}
|
||||
|
||||
|
||||
bool PIIODevice::open(const PIString & _path) {
|
||||
setPath(_path);
|
||||
return open();
|
||||
}
|
||||
|
||||
|
||||
bool PIIODevice::open(DeviceMode _mode) {
|
||||
mode_ = _mode;
|
||||
return open();
|
||||
}
|
||||
|
||||
|
||||
bool PIIODevice::open(const PIString & _path, DeviceMode _mode) {
|
||||
setPath(_path);
|
||||
mode_ = _mode;
|
||||
return open();
|
||||
}
|
||||
|
||||
|
||||
bool PIIODevice::close() {
|
||||
opened_ = !closeDevice();
|
||||
if (!opened_) closed();
|
||||
return !opened_;
|
||||
}
|
||||
|
||||
|
||||
bool PIIODevice::configure(const PIString & config_file, const PIString & section, bool parent_section) {
|
||||
PIConfig conf(config_file, PIIODevice::ReadOnly);
|
||||
if (!conf.isOpened()) return false;
|
||||
|
||||
Reference in New Issue
Block a user