Skip to content

Commit

Permalink
Minor mythzoneminder changes for std::chrono.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Jan 25, 2021
1 parent b55f6c7 commit 4aee859
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mythplugins/mythzoneminder/mythzmserver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ int main(int argc, char **argv)
while (!quit)
{
// the maximum time select() should wait
struct timeval timeout {DB_CHECK_TIME, 0};
struct timeval timeout {DB_CHECK_TIME.count(), 0};

read_fds = master; // copy it
int res = select(fdmax+1, &read_fds, nullptr, nullptr, &timeout);
Expand Down
6 changes: 3 additions & 3 deletions mythplugins/mythzoneminder/mythzmserver/zmserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int g_majorVersion = 0;
int g_minorVersion = 0;
int g_revisionVersion = 0;

time_t g_lastDBKick = 0;
TimePoint g_lastDBKick {};

// returns true if the ZM version >= the requested version
bool checkVersion(int major, int minor, int revision)
Expand Down Expand Up @@ -200,13 +200,13 @@ void connectToDatabase(void)

void kickDatabase(bool debug)
{
if (time(nullptr) < g_lastDBKick + DB_CHECK_TIME)
if (Clock::now() < g_lastDBKick + DB_CHECK_TIME)
return;

if (debug)
std::cout << "Kicking database connection" << std::endl;

g_lastDBKick = time(nullptr);
g_lastDBKick = Clock::now();

if (mysql_query(&g_dbConn, "SELECT NULL;") == 0)
{
Expand Down
8 changes: 6 additions & 2 deletions mythplugins/mythzoneminder/mythzmserver/zmserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
#ifndef ZMSERVER_H
#define ZMSERVER_H

#include <chrono>
#include <cstdint>
#include <map>
#include <mysql/mysql.h>
#include <sstream>
#include <string>
#include <unistd.h>
#include <vector>
using namespace std::chrono_literals;
using Clock = std::chrono::system_clock;
using TimePoint = std::chrono::time_point<Clock>;

// the maximum image size we are ever likely to get from ZM
#define MAX_IMAGE_SIZE (2048*1536*3)
Expand All @@ -47,8 +51,8 @@ extern int g_majorVersion;
extern int g_minorVersion;
extern int g_revisionVersion;

#define DB_CHECK_TIME 60
extern time_t g_lastDBKick;
static constexpr std::chrono::seconds DB_CHECK_TIME { 60s };
extern TimePoint g_lastDBKick;

const std::string FUNCTION_MONITOR = "Monitor";
const std::string FUNCTION_MODECT = "Modect";
Expand Down
2 changes: 1 addition & 1 deletion mythplugins/mythzoneminder/mythzoneminder/zmliveplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// the maximum image size we are ever likely to get from ZM
#define MAX_IMAGE_SIZE (2048*1536*3)

const int FRAME_UPDATE_TIME = 1000 / 10; // try to update the frame 10 times a second
static constexpr std::chrono::milliseconds FRAME_UPDATE_TIME { 100ms }; // try to update the frame 10 times a second

ZMLivePlayer::ZMLivePlayer(MythScreenStack *parent, bool isMiniPlayer)
:MythScreenType(parent, "zmliveview"),
Expand Down
2 changes: 1 addition & 1 deletion mythplugins/mythzoneminder/mythzoneminder/zmminiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// the maximum image size we are ever likely to get from ZM
#define MAX_IMAGE_SIZE (2048*1536*3)

const int FRAME_UPDATE_TIME = 1000 / 10; // try to update the frame 10 times a second
static constexpr std::chrono::milliseconds FRAME_UPDATE_TIME { 100ms }; // try to update the frame 10 times a second

ZMMiniPlayer::ZMMiniPlayer(MythScreenStack *parent)
: ZMLivePlayer(parent, true),
Expand Down

0 comments on commit 4aee859

Please sign in to comment.