Convert more char array buffers to std::string
Remove now unused ZM_SQL_*SIZE defines
This commit is contained in:
parent
fc15afefcf
commit
c60b577aec
|
@ -38,10 +38,7 @@
|
|||
#define ZM_SCALE_BASE 100 // The factor by which we bump up 'scale' to simulate FP
|
||||
#define ZM_RATE_BASE 100 // The factor by which we bump up 'rate' to simulate FP
|
||||
|
||||
#define ZM_SQL_BATCH_SIZE 50 // Limit the size of multi-row SQL statements
|
||||
#define ZM_SQL_SML_BUFSIZ 256 // Size of SQL buffer
|
||||
#define ZM_SQL_MED_BUFSIZ 1024 // Size of SQL buffer
|
||||
#define ZM_SQL_LGE_BUFSIZ 8192 // Size of SQL buffer
|
||||
|
||||
#define ZM_NETWORK_BUFSIZ 32768 // Size of network buffer
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "zm_group.h"
|
||||
|
||||
#include "zm_logger.h"
|
||||
#include "zm_utils.h"
|
||||
#include <cstring>
|
||||
|
||||
Group::Group() {
|
||||
|
@ -42,16 +43,16 @@ Group::Group(unsigned int p_id) {
|
|||
id = 0;
|
||||
|
||||
if (p_id) {
|
||||
char sql[ZM_SQL_SML_BUFSIZ];
|
||||
snprintf(sql, sizeof(sql), "SELECT `Id`, `ParentId`, `Name` FROM `Group` WHERE `Id`=%u", p_id);
|
||||
Debug(2,"Loading Group for %u using %s", p_id, sql);
|
||||
std::string sql = stringtf("SELECT `Id`, `ParentId`, `Name` FROM `Group` WHERE `Id`=%u", p_id);
|
||||
Debug(2, "Loading Group for %u using %s", p_id, sql.c_str());
|
||||
zmDbRow dbrow;
|
||||
if ( !dbrow.fetch(sql) ) {
|
||||
if (!dbrow.fetch(sql.c_str())) {
|
||||
Error("Unable to load group for id %u: %s", p_id, mysql_error(&dbconn));
|
||||
} else {
|
||||
unsigned int index = 0;
|
||||
id = atoi(dbrow[index++]);
|
||||
parent_id = dbrow[index] ? atoi(dbrow[index]): 0; index++;
|
||||
parent_id = dbrow[index] ? atoi(dbrow[index]) : 0;
|
||||
index++;
|
||||
strncpy(name, dbrow[index++], sizeof(name) - 1);
|
||||
Debug(1, "Loaded Group area %d '%s'", id, this->Name());
|
||||
}
|
||||
|
|
|
@ -1287,17 +1287,15 @@ void Monitor::actionReload() {
|
|||
void Monitor::actionEnable() {
|
||||
shared_data->action |= RELOAD;
|
||||
|
||||
char sql[ZM_SQL_SML_BUFSIZ];
|
||||
snprintf(sql, sizeof(sql), "UPDATE `Monitors` SET `Enabled` = 1 WHERE `Id` = %u", id);
|
||||
zmDbDo(sql);
|
||||
std::string sql = stringtf("UPDATE `Monitors` SET `Enabled` = 1 WHERE `Id` = %u", id);
|
||||
zmDbDo(sql.c_str());
|
||||
}
|
||||
|
||||
void Monitor::actionDisable() {
|
||||
shared_data->action |= RELOAD;
|
||||
|
||||
char sql[ZM_SQL_SML_BUFSIZ];
|
||||
snprintf(sql, sizeof(sql), "UPDATE `Monitors` SET `Enabled` = 0 WHERE `Id` = %u", id);
|
||||
zmDbDo(sql);
|
||||
std::string sql = stringtf("UPDATE `Monitors` SET `Enabled` = 0 WHERE `Id` = %u", id);
|
||||
zmDbDo(sql.c_str());
|
||||
}
|
||||
|
||||
void Monitor::actionSuspend() {
|
||||
|
|
|
@ -86,11 +86,10 @@ bool RtspThread::recvResponse(std::string &response) {
|
|||
|
||||
int RtspThread::requestPorts() {
|
||||
if ( !smMinDataPort ) {
|
||||
char sql[ZM_SQL_SML_BUFSIZ];
|
||||
//FIXME Why not load specifically by Id? This will get ineffeicient with a lot of monitors
|
||||
strncpy(sql, "SELECT `Id` FROM `Monitors` WHERE `Function` != 'None' AND `Type` = 'Remote' AND `Protocol` = 'rtsp' AND `Method` = 'rtpUni' ORDER BY `Id` ASC", sizeof(sql));
|
||||
std::string sql = "SELECT `Id` FROM `Monitors` WHERE `Function` != 'None' AND `Type` = 'Remote' AND `Protocol` = 'rtsp' AND `Method` = 'rtpUni' ORDER BY `Id` ASC";
|
||||
|
||||
MYSQL_RES *result = zmDbFetch(sql);
|
||||
MYSQL_RES *result = zmDbFetch(sql.c_str());
|
||||
|
||||
int nMonitors = mysql_num_rows(result);
|
||||
int position = 0;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "zm_db.h"
|
||||
#include "zm_logger.h"
|
||||
#include "zm_utils.h"
|
||||
#include <cstring>
|
||||
|
||||
Storage::Storage() : id(0) {
|
||||
|
@ -55,13 +56,11 @@ Storage::Storage(MYSQL_ROW &dbrow) {
|
|||
|
||||
/* If a zero or invalid p_id is passed, then the old default path will be assumed. */
|
||||
Storage::Storage(unsigned int p_id) : id(p_id) {
|
||||
|
||||
if (id) {
|
||||
char sql[ZM_SQL_SML_BUFSIZ];
|
||||
snprintf(sql, sizeof(sql), "SELECT `Id`, `Name`, `Path`, `Type`, `Scheme` FROM `Storage` WHERE `Id`=%u", id);
|
||||
Debug(2, "Loading Storage for %u using %s", id, sql);
|
||||
std::string sql = stringtf("SELECT `Id`, `Name`, `Path`, `Type`, `Scheme` FROM `Storage` WHERE `Id`=%u", id);
|
||||
Debug(2, "Loading Storage for %u using %s", id, sql.c_str());
|
||||
zmDbRow dbrow;
|
||||
if ( !dbrow.fetch(sql) ) {
|
||||
if (!dbrow.fetch(sql.c_str())) {
|
||||
Error("Unable to load storage area for id %d: %s", id, mysql_error(&dbconn));
|
||||
} else {
|
||||
unsigned int index = 0;
|
||||
|
|
|
@ -116,8 +116,7 @@ Zone::~Zone() {
|
|||
}
|
||||
|
||||
void Zone::RecordStats(const Event *event) {
|
||||
static char sql[ZM_SQL_MED_BUFSIZ];
|
||||
snprintf(sql, sizeof(sql),
|
||||
std::string sql = stringtf(
|
||||
"INSERT INTO Stats SET MonitorId=%d, ZoneId=%d, EventId=%" PRIu64 ", FrameId=%d, "
|
||||
"PixelDiff=%d, AlarmPixels=%d, FilterPixels=%d, BlobPixels=%d, "
|
||||
"Blobs=%d, MinBlobSize=%d, MaxBlobSize=%d, "
|
||||
|
@ -136,7 +135,7 @@ void Zone::RecordStats(const Event *event) {
|
|||
stats.alarm_box_.Hi().y_,
|
||||
stats.score_
|
||||
);
|
||||
zmDbDo(sql);
|
||||
zmDbDo(sql.c_str());
|
||||
} // end void Zone::RecordStats( const Event *event )
|
||||
|
||||
bool Zone::CheckOverloadCount() {
|
||||
|
|
14
src/zmc.cpp
14
src/zmc.cpp
|
@ -232,7 +232,6 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
while (!zm_terminate) {
|
||||
result = 0;
|
||||
static char sql[ZM_SQL_SML_BUFSIZ];
|
||||
|
||||
for (const std::shared_ptr<Monitor> &monitor : monitors) {
|
||||
monitor->LoadCamera();
|
||||
|
@ -244,11 +243,11 @@ int main(int argc, char *argv[]) {
|
|||
monitor->SetStartupTime(now);
|
||||
monitor->SetHeartbeatTime(now);
|
||||
|
||||
snprintf(sql, sizeof(sql),
|
||||
std::string sql = stringtf(
|
||||
"INSERT INTO Monitor_Status (MonitorId,Status,CaptureFPS,AnalysisFPS)"
|
||||
" VALUES (%u, 'Running',0,0) ON DUPLICATE KEY UPDATE Status='Running',CaptureFPS=0,AnalysisFPS=0",
|
||||
monitor->Id());
|
||||
zmDbDo(sql);
|
||||
zmDbDo(sql.c_str());
|
||||
|
||||
Seconds sleep_time = Seconds(0);
|
||||
while (monitor->PrimeCapture() <= 0) {
|
||||
|
@ -273,10 +272,10 @@ int main(int argc, char *argv[]) {
|
|||
break;
|
||||
}
|
||||
|
||||
snprintf(sql, sizeof(sql),
|
||||
sql = stringtf(
|
||||
"INSERT INTO Monitor_Status (MonitorId,Status) VALUES (%u, 'Connected') ON DUPLICATE KEY UPDATE Status='Connected'",
|
||||
monitor->Id());
|
||||
zmDbDo(sql);
|
||||
zmDbDo(sql.c_str());
|
||||
} // end foreach monitor
|
||||
|
||||
if (zm_terminate){
|
||||
|
@ -360,11 +359,10 @@ int main(int argc, char *argv[]) {
|
|||
} // end while ! zm_terminate outer connection loop
|
||||
|
||||
for (std::shared_ptr<Monitor> &monitor : monitors) {
|
||||
static char sql[ZM_SQL_SML_BUFSIZ];
|
||||
snprintf(sql, sizeof(sql),
|
||||
std::string sql = stringtf(
|
||||
"INSERT INTO Monitor_Status (MonitorId,Status) VALUES (%u, 'NotRunning') ON DUPLICATE KEY UPDATE Status='NotRunning'",
|
||||
monitor->Id());
|
||||
zmDbDo(sql);
|
||||
zmDbDo(sql.c_str());
|
||||
}
|
||||
|
||||
Image::Deinitialise();
|
||||
|
|
Loading…
Reference in New Issue