git-svn-id: svn://db.shs.com.ru/pip@267 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -46,7 +46,7 @@ REGISTER_DEVICE(PIBinaryLog)
|
||||
|
||||
PIBinaryLog::PIBinaryLog() {
|
||||
setThreadedReadBufferSize(65536);
|
||||
is_started = is_indexed = false;
|
||||
is_started = is_indexed = is_pause = false;
|
||||
current_index = -1;
|
||||
setPlaySpeed(1.);
|
||||
setDefaultID(1);
|
||||
@@ -61,6 +61,7 @@ PIBinaryLog::PIBinaryLog() {
|
||||
setFilePrefix(PIString());
|
||||
setRapidStart(false);
|
||||
file.setName("__S__PIBinaryLog::file");
|
||||
// piCoutObj << "created";
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +72,7 @@ bool PIBinaryLog::openDevice() {
|
||||
is_started = false;
|
||||
is_thread_ok = true;
|
||||
is_indexed = false;
|
||||
is_pause = false;
|
||||
index.clear();
|
||||
index_pos.clear();
|
||||
if (mode_ == ReadWrite) {
|
||||
@@ -121,6 +123,7 @@ bool PIBinaryLog::openDevice() {
|
||||
if (!rapidStart()) is_started = true;
|
||||
}
|
||||
startlogtime = PISystemTime::current();
|
||||
pause_time = PISystemTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -146,10 +149,18 @@ bool PIBinaryLog::threadedRead(uchar *readed, int size) {
|
||||
double delay;
|
||||
switch (play_mode) {
|
||||
case PlayRealTime:
|
||||
pausemutex.lock();
|
||||
if (is_pause) {
|
||||
piMSleep(100);
|
||||
pausemutex.unlock();
|
||||
return false;
|
||||
} else if (pause_time > PISystemTime()) {
|
||||
startlogtime += pause_time;
|
||||
pause_time = PISystemTime();
|
||||
}
|
||||
pausemutex.unlock();
|
||||
pt = PISystemTime::current() - startlogtime;
|
||||
if (is_started) {
|
||||
if ((lastrecord.timestamp - pt).toSeconds() > 100. || (lastrecord.timestamp - pt).toSeconds() < -100.)
|
||||
piCoutObj << PISystemTime::current() << startlogtime << pt << lastrecord.timestamp << (lastrecord.timestamp - pt);
|
||||
if (lastrecord.timestamp > pt)
|
||||
(lastrecord.timestamp - pt).sleep();
|
||||
} else {
|
||||
@@ -163,6 +174,10 @@ bool PIBinaryLog::threadedRead(uchar *readed, int size) {
|
||||
double cdelay;
|
||||
int dtc;
|
||||
if (is_started) {
|
||||
if (is_pause) {
|
||||
piMSleep(100);
|
||||
return false;
|
||||
}
|
||||
if (delay > 0) {
|
||||
cdelay = delay * play_speed;
|
||||
dtc = int(cdelay) /100;
|
||||
@@ -182,8 +197,13 @@ bool PIBinaryLog::threadedRead(uchar *readed, int size) {
|
||||
play_time = lastrecord.timestamp.toMilliseconds();
|
||||
break;
|
||||
case PlayStaticDelay:
|
||||
if (is_started) play_delay.sleep();
|
||||
else is_started = true;
|
||||
if (is_started) {
|
||||
if (is_pause) {
|
||||
piMSleep(100);
|
||||
return false;
|
||||
}
|
||||
play_delay.sleep();
|
||||
} else is_started = true;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@@ -229,6 +249,15 @@ void PIBinaryLog::createNewFile(const PIString &path) {
|
||||
}
|
||||
|
||||
|
||||
void PIBinaryLog::setPause(bool pause) {
|
||||
pausemutex.lock();
|
||||
is_pause = pause;
|
||||
if (pause) pause_time = PISystemTime::current();
|
||||
else pause_time = PISystemTime::current() - pause_time;
|
||||
pausemutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
int PIBinaryLog::writeBinLog(int id, const void *data, int size) {
|
||||
if (size <= 0 || !canWrite()) return -1;
|
||||
if (id == 0) {
|
||||
@@ -247,6 +276,7 @@ int PIBinaryLog::writeBinLog(int id, const void *data, int size) {
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
if (is_pause) return 0;
|
||||
PIByteArray logdata;
|
||||
logdata << id << size << (PISystemTime::current() - startlogtime) << PIByteArray::RawData(data, size);
|
||||
int res = file.write(logdata.data(), logdata.size());
|
||||
@@ -503,7 +533,21 @@ PIBinaryLog::BinLogInfo PIBinaryLog::getLogInfo(const PIString & path) {
|
||||
|
||||
PIString PIBinaryLog::constructFullPath() const {
|
||||
PIString ret(fullPathPrefix() + "://");
|
||||
ret << logDir() << ":" << filePrefix() << ":" << defaultID();
|
||||
ret << logDir() << ":" << filePrefix() << ":" << defaultID() << ":";
|
||||
switch (play_mode) {
|
||||
case PlayRealTime:
|
||||
ret << "RT";
|
||||
break;
|
||||
case PlayVariableSpeed:
|
||||
ret << PIString::fromNumber(playSpeed()) << "X";
|
||||
break;
|
||||
case PlayStaticDelay:
|
||||
ret << PIString::fromNumber(playDelay().toMilliseconds()) << "M";
|
||||
break;
|
||||
default:
|
||||
ret << "RT";
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -573,12 +617,18 @@ void PIBinaryLog::configureFromFullPath(const PIString & full_path) {
|
||||
case 0: setLogDir(p); break;
|
||||
case 1: setFilePrefix(p); break;
|
||||
case 2: setDefaultID(p.toInt()); break;
|
||||
case 3:
|
||||
if (p.toUpperCase() == "RT") setPlayRealTime();
|
||||
if (p.toUpperCase().right(1) == "X") setPlaySpeed((p.left(p.size() - 1)).toDouble());
|
||||
if (p.toUpperCase().right(1) == "M") setPlayDelay(PISystemTime::fromMilliseconds((p.left(p.size() - 1)).toDouble()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// piCoutObj << "configured";
|
||||
}
|
||||
|
||||
|
||||
void PIBinaryLog::propertyChanged(const PIString &) {
|
||||
void PIBinaryLog::propertyChanged(const PIString &s) {
|
||||
default_id = property("defaultID").toInt();
|
||||
rapid_start = property("rapidStart").toBool();
|
||||
play_mode = (PlayMode)property("playMode").toInt();
|
||||
@@ -589,5 +639,6 @@ void PIBinaryLog::propertyChanged(const PIString &) {
|
||||
split_time = property("splitTime").toSystemTime();
|
||||
split_size = property("splitFileSize").toLLong();
|
||||
split_count = property("splitRecordCount").toInt();
|
||||
// piCoutObj << "propertyChanged" << s << play_mode;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user