Skip to content

Commit

Permalink
test conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
dougnazar committed Aug 3, 2022
1 parent a0d99ff commit 3385d31
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 253 deletions.
13 changes: 6 additions & 7 deletions src/zm_analysis_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
#include "zm_signal.h"
#include "zm_time.h"

AnalysisThread::AnalysisThread(Monitor *monitor) :
monitor_(monitor), terminate_(false) {
AnalysisThread::AnalysisThread(Monitor *monitor) : monitor_(monitor), terminate_(false) {
thread_ = std::thread(&AnalysisThread::Run, this);
}

AnalysisThread::~AnalysisThread() {
Stop();
}
AnalysisThread::~AnalysisThread() { Stop(); }

void AnalysisThread::Start() {
if (thread_.joinable()) thread_.join();
Expand All @@ -30,8 +27,10 @@ void AnalysisThread::Run() {
// Some periodic updates are required for variable capturing framerate
if (!monitor_->Analyse()) {
if (!(terminate_ or zm_terminate)) {
// We only sleep when Analyse returns false because it is an error condition and we will spin like mad if it persists.
Microseconds sleep_for = monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE);
// We only sleep when Analyse returns false because it is an error condition and we will
// spin like mad if it persists.
Microseconds sleep_for =
monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE);
Debug(2, "Sleeping for %" PRId64 "us", int64(sleep_for.count()));
std::this_thread::sleep_for(sleep_for);
}
Expand Down
15 changes: 7 additions & 8 deletions src/zm_box.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
//
// ZoneMinder Box Class Interfaces, $Date$, $Revision$
// Copyright (C) 2001-2008 Philip Coombes
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// 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 General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
//

#ifndef ZM_BOX_H
#define ZM_BOX_H

#include "zm_line.h"
#include "zm_vector2.h"

#include <cmath>
#include <vector>

Expand Down Expand Up @@ -49,9 +50,7 @@ class Box {
}

// Get vertices of the box in a counter-clockwise order
std::vector<Vector2> Vertices() const {
return {lo_, {hi_.x_, lo_.y_}, hi_, {lo_.x_, hi_.y_}};
}
std::vector<Vector2> Vertices() const { return {lo_, {hi_.x_, lo_.y_}, hi_, {lo_.x_, hi_.y_}}; }

// Get edges of the box in a counter-clockwise order
std::vector<LineSegment> Edges() const {
Expand All @@ -77,4 +76,4 @@ class Box {
Vector2 size_;
};

#endif // ZM_BOX_H
#endif // ZM_BOX_H
25 changes: 13 additions & 12 deletions src/zm_crypt.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
// ZoneMinder General Utility Functions, $Date$, $Revision$
// Copyright (C) 2001-2008 Philip Coombes
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// 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 General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
//

#ifndef ZM_CRYPT_H
#define ZM_CRYPT_H
Expand All @@ -24,6 +24,7 @@
#include "zm_crypto_gnutls.h"
#include "zm_crypto_openssl.h"
#include "zm_define.h"

#include <string>

bool verifyPassword(const char *username, const char *input_password, const char *db_password_hash);
Expand All @@ -35,21 +36,21 @@ namespace crypto {
namespace impl {

#if defined(HAVE_LIBGNUTLS)
template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
using Hash = gnutls::GenericHashImpl<Algorithm>;
#elif defined(HAVE_LIBOPENSSL)
template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
using Hash = openssl::GenericHashImpl<Algorithm>;
#endif
}
}
}
} // namespace impl
} // namespace crypto
} // namespace zm

namespace zm {
namespace crypto {
using MD5 = impl::Hash<impl::HashAlgorithms::kMD5>;
using SHA1 = impl::Hash<impl::HashAlgorithms::kSHA1>;
}
}
} // namespace crypto
} // namespace zm

#endif // ZM_CRYPT_H
#endif // ZM_CRYPT_H
38 changes: 17 additions & 21 deletions src/zm_crypto_generics.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,30 @@

#include "zm_define.h"
#include "zm_utils.h"

#include <array>
#include <cstring>

namespace zm {
namespace crypto {
namespace impl {

enum class HashAlgorithms {
kMD5,
kSHA1
};
enum class HashAlgorithms { kMD5, kSHA1 };

template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
struct HashAlgorithm;

template<>
template <>
struct HashAlgorithm<HashAlgorithms::kMD5> {
static constexpr size_t digest_length = 16;
};

template<>
template <>
struct HashAlgorithm<HashAlgorithms::kSHA1> {
static constexpr size_t digest_length = 20;
};

template<typename Impl, HashAlgorithms Algorithm>
template <typename Impl, HashAlgorithms Algorithm>
class GenericHash {
public:
static constexpr size_t DIGEST_LENGTH = HashAlgorithm<Algorithm>::digest_length;
Expand All @@ -58,8 +56,8 @@ class GenericHash {
return hash.GetDigest();
}

template<typename... Ts>
static Digest GetDigestOf(Ts &&... pack) {
template <typename... Ts>
static Digest GetDigestOf(Ts &&...pack) {
Impl hash;
UpdateData(hash, std::forward<Ts>(pack)...);
hash.Finalize();
Expand All @@ -75,34 +73,32 @@ class GenericHash {
void UpdateData(const char *str) {
UpdateData(reinterpret_cast<const uint8 *>(str), strlen(str));
}
template<typename Container>
template <typename Container>
void UpdateData(Container const &c) {
UpdateData(zm::data(c), zm::size(c));
}

void Finalize() {
static_cast<Impl &>(*this).DoFinalize();
}
void Finalize() { static_cast<Impl &>(*this).DoFinalize(); }

const Digest &GetDigest() const { return digest_; }

protected:
Digest digest_ = {};

private:
template<typename T>
template <typename T>
static void UpdateData(Impl &hash, T const &data) {
hash.UpdateData(data);
}

template<typename T, typename... TRest>
static void UpdateData(Impl &hash, T const &data, TRest &&... rest) {
template <typename T, typename... TRest>
static void UpdateData(Impl &hash, T const &data, TRest &&...rest) {
hash.UpdateData(data);
UpdateData(hash, std::forward<TRest>(rest)...);
}
};
}
}
}
} // namespace impl
} // namespace crypto
} // namespace zm

#endif //ZONEMINDER_SRC_ZM_CRYPTO_GENERICS_H_
#endif // ZONEMINDER_SRC_ZM_CRYPTO_GENERICS_H_
25 changes: 12 additions & 13 deletions src/zm_crypto_gnutls.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,28 @@

#include "zm_crypto_generics.h"
#include "zm_utils.h"

#include <gnutls/crypto.h>

namespace zm {
namespace crypto {
namespace impl {
namespace gnutls {

template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
struct HashAlgorithmMapper;

template<>
template <>
struct HashAlgorithmMapper<HashAlgorithms::kMD5> {
static constexpr gnutls_digest_algorithm_t algorithm = GNUTLS_DIG_MD5;
};

template<>
template <>
struct HashAlgorithmMapper<HashAlgorithms::kSHA1> {
static constexpr gnutls_digest_algorithm_t algorithm = GNUTLS_DIG_SHA1;
};

template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
class GenericHashImpl : public GenericHash<GenericHashImpl<Algorithm>, Algorithm> {
public:
GenericHashImpl() {
Expand All @@ -55,21 +56,19 @@ class GenericHashImpl : public GenericHash<GenericHashImpl<Algorithm>, Algorithm
ASSERT(res == 0);
}

void DoFinalize() {
gnutls_hash_deinit(handle_, digest_.data());
}
void DoFinalize() { gnutls_hash_deinit(handle_, digest_.data()); }

private:
gnutls_hash_hd_t handle_ = {};

using Base = GenericHash<GenericHashImpl<Algorithm>, Algorithm>;
using Base::digest_;
};
}
}
}
}
} // namespace gnutls
} // namespace impl
} // namespace crypto
} // namespace zm

#endif // HAVE_LIBGNUTLS
#endif // HAVE_LIBGNUTLS

#endif // ZONEMINDER_SRC_ZM_CRYPTO_GNUTLS_H_
#endif // ZONEMINDER_SRC_ZM_CRYPTO_GNUTLS_H_
21 changes: 11 additions & 10 deletions src/zm_crypto_openssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "zm_crypto_generics.h"
#include "zm_utils.h"

#include <openssl/evp.h>

namespace zm {
Expand All @@ -31,10 +32,10 @@ namespace openssl {

typedef EVP_MD const *(*HashCreator)();

template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
struct HashAlgorithmMapper;

template<>
template <>
struct HashAlgorithmMapper<HashAlgorithms::kMD5> {
// TODO: Remove conditional once Jessie and CentOS 7 are deprecated
// This is needed since GCC 4.8 is faulty (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60199)
Expand All @@ -48,7 +49,7 @@ struct HashAlgorithmMapper<HashAlgorithms::kMD5> {
#endif
};

template<>
template <>
struct HashAlgorithmMapper<HashAlgorithms::kSHA1> {
// TODO: Remove conditional once Jessie and CentOS 7 are deprecated
// This is needed since GCC 4.8 is faulty (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60199)
Expand All @@ -62,7 +63,7 @@ struct HashAlgorithmMapper<HashAlgorithms::kSHA1> {
#endif
};

template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
class GenericHashImpl : public GenericHash<GenericHashImpl<Algorithm>, Algorithm> {
public:
GenericHashImpl() {
Expand Down Expand Up @@ -98,11 +99,11 @@ class GenericHashImpl : public GenericHash<GenericHashImpl<Algorithm>, Algorithm
using Base = GenericHash<GenericHashImpl<Algorithm>, Algorithm>;
using Base::digest_;
};
}
}
}
}
} // namespace openssl
} // namespace impl
} // namespace crypto
} // namespace zm

#endif // HAVE_LIBOPENSSL
#endif // HAVE_LIBOPENSSL

#endif // ZONEMINDER_SRC_ZM_CRYPTO_OPENSSL_H_
#endif // ZONEMINDER_SRC_ZM_CRYPTO_OPENSSL_H_
13 changes: 6 additions & 7 deletions src/zm_decoder_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
#include "zm_monitor.h"
#include "zm_signal.h"

DecoderThread::DecoderThread(Monitor *monitor) :
monitor_(monitor), terminate_(false) {
DecoderThread::DecoderThread(Monitor *monitor) : monitor_(monitor), terminate_(false) {
thread_ = std::thread(&DecoderThread::Run, this);
}

DecoderThread::~DecoderThread() {
Stop();
}
DecoderThread::~DecoderThread() { Stop(); }

void DecoderThread::Start() {
if (thread_.joinable()) thread_.join();
Expand All @@ -29,8 +26,10 @@ void DecoderThread::Run() {
while (!(terminate_ or zm_terminate)) {
if (!monitor_->Decode()) {
if (!(terminate_ or zm_terminate)) {
// We only sleep when Decode returns false because it is an error condition and we will spin like mad if it persists.
Microseconds sleep_for = monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE);
// We only sleep when Decode returns false because it is an error condition and we will spin
// like mad if it persists.
Microseconds sleep_for =
monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE);
Debug(2, "Sleeping for %" PRId64 "us", int64(sleep_for.count()));
std::this_thread::sleep_for(sleep_for);
}
Expand Down
Loading

0 comments on commit 3385d31

Please sign in to comment.