change PIMap::at and add const to PIMap and PIBinaryLog
This commit is contained in:
@@ -177,8 +177,9 @@ bool PIBinaryLog::threadedRead(const uchar * readed, ssize_t size) {
|
||||
if (!canRead() || isEnd()) return PIIODevice::threadedRead(readed, size);
|
||||
is_thread_ok = false;
|
||||
logmutex.lock();
|
||||
PISystemTime pt, lastrec_timestamp = lastrecord.timestamp;
|
||||
const PISystemTime lastrec_timestamp = lastrecord.timestamp;
|
||||
logmutex.unlock();
|
||||
PISystemTime pt;
|
||||
double delay;
|
||||
switch (play_mode) {
|
||||
case PlayRealTime:
|
||||
@@ -258,7 +259,7 @@ PIString PIBinaryLog::getLogfilePath(const PIString & log_dir, const PIString &
|
||||
<< "Creating directory" << dir.path();
|
||||
dir.make(true);
|
||||
}
|
||||
PIString npath = log_dir + PIDir::separator + prefix + PIDateTime::current().toString("yyyy_MM_dd__hh_mm_ss");
|
||||
const PIString npath = log_dir + PIDir::separator + prefix + PIDateTime::current().toString("yyyy_MM_dd__hh_mm_ss");
|
||||
PIString cnpath = npath + ".binlog";
|
||||
int i = 1;
|
||||
while (PIFile::isExists(cnpath)) {
|
||||
@@ -317,7 +318,7 @@ int PIBinaryLog::writeBinLog(int id, const void * data, int size) {
|
||||
}
|
||||
if (is_pause) return 0;
|
||||
logmutex.lock();
|
||||
int res = writeRecord(id, PISystemTime::current() - startlogtime, data, size);
|
||||
const int res = writeRecord(id, PISystemTime::current() - startlogtime, data, size);
|
||||
switch (split_mode) {
|
||||
case SplitSize:
|
||||
if (log_size > split_size) createNewFile();
|
||||
@@ -341,7 +342,7 @@ int PIBinaryLog::writeBinLog(int id, const void * data, int size) {
|
||||
int PIBinaryLog::writeBinLog_raw(int id, const PISystemTime & time, const void * data, int size) {
|
||||
if (size <= 0 || !canWrite()) return -1;
|
||||
logmutex.lock();
|
||||
int res = writeRecord(id, time, data, size);
|
||||
const int res = writeRecord(id, time, data, size);
|
||||
logmutex.unlock();
|
||||
if (res > 0)
|
||||
return size;
|
||||
@@ -386,7 +387,7 @@ PIByteArray PIBinaryLog::readBinLog(int id, PISystemTime * time, int * readed_id
|
||||
|
||||
int PIBinaryLog::readBinLog(int id, void * read_to, int max_size, PISystemTime * time, int * readed_id) {
|
||||
if (max_size <= 0 || read_to == 0) return -1;
|
||||
PIByteArray ba = readBinLog(id, time, readed_id);
|
||||
const PIByteArray ba = readBinLog(id, time, readed_id);
|
||||
if (ba.isEmpty()) return -1;
|
||||
int sz = piMini(max_size, ba.size());
|
||||
memcpy(read_to, ba.data(), sz);
|
||||
@@ -404,7 +405,7 @@ void PIBinaryLog::setHeader(const PIByteArray & header) {
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIBinaryLog::getHeader() {
|
||||
PIByteArray PIBinaryLog::getHeader() const {
|
||||
return index.info.user_header;
|
||||
}
|
||||
|
||||
@@ -432,7 +433,7 @@ ssize_t PIBinaryLog::readDevice(void * read_to, ssize_t max_size) {
|
||||
piCoutObj << "Read record error";
|
||||
return -1;
|
||||
}
|
||||
ssize_t sz = piMini(max_size, br.data.size());
|
||||
const ssize_t sz = piMini(max_size, br.data.size());
|
||||
if (sz < br.data.size_s()) piCoutObj << "too small read buffer:" << max_size << ", data size:" << br.data.size();
|
||||
memcpy(read_to, br.data.data(), sz);
|
||||
return sz;
|
||||
@@ -445,7 +446,7 @@ ssize_t PIBinaryLog::writeDevice(const void * data, ssize_t size) {
|
||||
|
||||
|
||||
void PIBinaryLog::restart() {
|
||||
bool th = isThreadedRead();
|
||||
const bool th = isThreadedRead();
|
||||
if (th) stopThreadedRead();
|
||||
if (!canRead()) return;
|
||||
logmutex.unlock();
|
||||
@@ -464,9 +465,9 @@ void PIBinaryLog::restart() {
|
||||
|
||||
bool PIBinaryLog::writeFileHeader() {
|
||||
if (file.write(binlog_sig, PIBINARYLOG_SIGNATURE_SIZE) <= 0) return false;
|
||||
uchar version = PIBINARYLOG_VERSION;
|
||||
const uchar version = PIBINARYLOG_VERSION;
|
||||
if (file.write(&version, 1) <= 0) return false;
|
||||
uint32_t sz = user_header.size();
|
||||
const uint32_t sz = user_header.size();
|
||||
file.write(&sz, 4);
|
||||
file.write(user_header);
|
||||
file.flush();
|
||||
@@ -578,7 +579,7 @@ int PIBinaryLog::writeRecord(int id, PISystemTime time, const void * data, int s
|
||||
++index.info.records_count;
|
||||
is_indexed = true;
|
||||
}
|
||||
int ret = file.write(logdata.data(), logdata.size());
|
||||
const int ret = file.write(logdata.data(), logdata.size());
|
||||
file.flush();
|
||||
write_count++;
|
||||
log_size = file.size();
|
||||
@@ -638,7 +639,7 @@ void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector<
|
||||
f->read(&sz, 4);
|
||||
if (sz > 0) {
|
||||
PIByteArray user_hdr = f->read(sz);
|
||||
if (info) info->user_header = user_hdr;
|
||||
if (info) info->user_header.swap(user_hdr);
|
||||
}
|
||||
}
|
||||
PIByteArray ba;
|
||||
@@ -646,7 +647,7 @@ void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector<
|
||||
br.id = 0;
|
||||
br.size = 0;
|
||||
bool first = true;
|
||||
size_t hdr_size = sizeof(Record) - sizeof(PIByteArray);
|
||||
constexpr size_t hdr_size = sizeof(Record) - sizeof(PIByteArray);
|
||||
ba.resize(hdr_size);
|
||||
while (1) {
|
||||
ba.resize(hdr_size);
|
||||
@@ -721,7 +722,7 @@ bool PIBinaryLog::cutBinLog(const PIBinaryLog::BinLogInfo & src, const PIString
|
||||
<< "Error, can't open" << src.path;
|
||||
return false;
|
||||
}
|
||||
PIVector<int> ids = src.records.keys();
|
||||
const PIVector<int> ids = src.records.keys();
|
||||
slog.seekTo(from);
|
||||
PIBinaryLog dlog;
|
||||
dlog.createNewFile(dst);
|
||||
@@ -825,7 +826,7 @@ bool PIBinaryLog::joinBinLogsSerial(const PIStringList & src,
|
||||
|
||||
bool PIBinaryLog::createIndex() {
|
||||
logmutex.lock();
|
||||
llong cp = file.pos();
|
||||
const llong cp = file.pos();
|
||||
file.seekToBegin();
|
||||
index.clear();
|
||||
parseLog(&file, &index.info, &index.index);
|
||||
@@ -870,7 +871,7 @@ void PIBinaryLog::seekTo(int rindex) {
|
||||
|
||||
|
||||
bool PIBinaryLog::seek(const PISystemTime & time) {
|
||||
int ci = posForTime(time);
|
||||
const int ci = posForTime(time);
|
||||
if (ci >= 0) {
|
||||
seekTo(ci);
|
||||
return true;
|
||||
@@ -930,9 +931,9 @@ PIString PIBinaryLog::constructFullPathDevice() const {
|
||||
|
||||
|
||||
void PIBinaryLog::configureFromFullPathDevice(const PIString & full_path) {
|
||||
PIStringList pl = full_path.split(":");
|
||||
const PIStringList pl = full_path.split(":");
|
||||
for (int i = 0; i < pl.size_s(); ++i) {
|
||||
PIString p(pl[i]);
|
||||
const PIString p(pl[i]);
|
||||
switch (i) {
|
||||
case 0: setLogDir(p); break;
|
||||
case 1: setFilePrefix(p); break;
|
||||
@@ -979,7 +980,7 @@ void PIBinaryLog::propertyChanged(const char * s) {
|
||||
default_id = property("defaultID").toInt();
|
||||
rapid_start = property("rapidStart").toBool();
|
||||
play_mode = (PlayMode)property("playMode").toInt();
|
||||
double ps = property("playSpeed").toDouble();
|
||||
const double ps = property("playSpeed").toDouble();
|
||||
play_speed = ps > 0. ? 1. / ps : 0.;
|
||||
play_delay = property("playDelay").toSystemTime();
|
||||
split_mode = (SplitMode)property("splitMode").toInt();
|
||||
|
||||
Reference in New Issue
Block a user