code format
This commit is contained in:
@@ -5,45 +5,43 @@
|
||||
* \~russian Базовый класс для создания грабберов
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Abstract class for create grabbers
|
||||
Andrey Bychkov work.a.b@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Abstract class for create grabbers
|
||||
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 PIGRABBERBASE_H
|
||||
#define PIGRABBERBASE_H
|
||||
|
||||
#include "pithread.h"
|
||||
#include "pidiagnostics.h"
|
||||
#include "pithread.h"
|
||||
|
||||
|
||||
template<typename T = PIByteArray>
|
||||
class PIGrabberBase: public PIThread
|
||||
{
|
||||
class PIGrabberBase: public PIThread {
|
||||
PIOBJECT_SUBCLASS(PIGrabberBase, PIThread);
|
||||
|
||||
public:
|
||||
PIGrabberBase() {
|
||||
is_opened = false;
|
||||
is_opened = false;
|
||||
is_recording = false;
|
||||
}
|
||||
virtual ~PIGrabberBase() {
|
||||
stopGrabber(false);
|
||||
}
|
||||
virtual bool isOpened() const {return is_opened;}
|
||||
virtual bool isRecording() const {return is_recording;}
|
||||
virtual ~PIGrabberBase() { stopGrabber(false); }
|
||||
virtual bool isOpened() const { return is_opened; }
|
||||
virtual bool isRecording() const { return is_recording; }
|
||||
virtual void startRecord(const PIString & filename) {
|
||||
if (!isOpened()) return;
|
||||
if (isRecording()) return;
|
||||
@@ -83,20 +81,21 @@ public:
|
||||
}
|
||||
T dequeue() {
|
||||
T ret;
|
||||
// piCoutObj << "start";
|
||||
// piCoutObj << "start";
|
||||
que_mutex.lock();
|
||||
if (!que.isEmpty()) {
|
||||
// piCoutObj << "dequeue";
|
||||
// piCoutObj << "dequeue";
|
||||
ret = que.dequeue();
|
||||
}
|
||||
// piCoutObj << "end";
|
||||
// piCoutObj << "end";
|
||||
que_mutex.unlock();
|
||||
return ret;
|
||||
}
|
||||
void stopGrabber(bool wait_forever = true) {
|
||||
if (isRunning()) {
|
||||
stop();
|
||||
if (wait_forever) waitForFinish();
|
||||
if (wait_forever)
|
||||
waitForFinish();
|
||||
else {
|
||||
if (!waitForFinish(100)) terminate();
|
||||
stopRecord();
|
||||
@@ -106,8 +105,7 @@ public:
|
||||
}
|
||||
bool open() {
|
||||
bool ret = openInternal();
|
||||
if (!is_opened && ret)
|
||||
opened();
|
||||
if (!is_opened && ret) opened();
|
||||
is_opened = ret;
|
||||
return ret;
|
||||
}
|
||||
@@ -115,11 +113,10 @@ public:
|
||||
bool em = is_opened;
|
||||
closeInternal();
|
||||
last_ = T();
|
||||
if (em)
|
||||
closed();
|
||||
if (em) closed();
|
||||
is_opened = false;
|
||||
}
|
||||
const PIDiagnostics & diag() const {return diag_;}
|
||||
const PIDiagnostics & diag() const { return diag_; }
|
||||
void clear() {
|
||||
que_mutex.lock();
|
||||
que.clear();
|
||||
@@ -136,9 +133,9 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void init() {}
|
||||
virtual bool openInternal() = 0;
|
||||
virtual bool openInternal() = 0;
|
||||
virtual void closeInternal() = 0;
|
||||
virtual int get(T & val) = 0;
|
||||
virtual int get(T & val) = 0;
|
||||
virtual void record(const T & val) {}
|
||||
virtual void startRecordInternal(const PIString & filename) {}
|
||||
virtual void stopRecordInternal() {}
|
||||
@@ -147,15 +144,12 @@ protected:
|
||||
mutable PIMutex rec_mutex;
|
||||
|
||||
private:
|
||||
void begin() override {
|
||||
init();
|
||||
}
|
||||
void begin() override { init(); }
|
||||
void run() override {
|
||||
if (!isOpened()) {
|
||||
open();
|
||||
diag_.reset();
|
||||
if (!is_opened)
|
||||
piMSleep(200);
|
||||
if (!is_opened) piMSleep(200);
|
||||
}
|
||||
if (isOpened()) {
|
||||
T c;
|
||||
|
||||
Reference in New Issue
Block a user