v1.1.0 : Multithreading & UX update
This commit is contained in:
@@ -16,35 +16,39 @@
|
||||
|
||||
#include <configuration.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <stream_model.h>
|
||||
#include <vector>
|
||||
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
|
||||
//! The interface a cache_manager should implement to be valid
|
||||
// The interface a cache_manager should implement to be valid
|
||||
class cache_manager_iface {
|
||||
public:
|
||||
virtual ~cache_manager_iface() {}
|
||||
|
||||
//! Launches the manager configuration
|
||||
//! \return false if failed
|
||||
// Launches the manager configuration
|
||||
// \return false if failed
|
||||
virtual bool configure(std::shared_ptr<etix::cameradar::configuration> configuration) = 0;
|
||||
|
||||
//! get the name of the cache manager
|
||||
// get the name of the cache manager
|
||||
virtual const std::string& get_name() const = 0;
|
||||
|
||||
//! Replaces all cached streams by the content of the vector given as
|
||||
//! parameter
|
||||
// Replaces all cached streams by the content of the vector given as
|
||||
// parameter
|
||||
virtual void set_streams(std::vector<etix::cameradar::stream_model> model) = 0;
|
||||
|
||||
//! Inserts a single stream to the cache
|
||||
// Inserts a single stream to the cache
|
||||
virtual void update_stream(const etix::cameradar::stream_model& newmodel) = 0;
|
||||
|
||||
//! Gets all cached streams
|
||||
// Returns true if the stream passed as a parameter has changed in the cache
|
||||
virtual bool has_changed(const etix::cameradar::stream_model&) = 0;
|
||||
|
||||
// Gets all cached streams
|
||||
virtual std::vector<etix::cameradar::stream_model> get_streams() = 0;
|
||||
|
||||
//! Gets all valid streams which have been accessed
|
||||
// Gets all valid streams which have been accessed
|
||||
virtual std::vector<etix::cameradar::stream_model> get_valid_streams() = 0;
|
||||
};
|
||||
|
||||
@@ -53,27 +57,30 @@ public:
|
||||
cache_manager_base() = default;
|
||||
virtual ~cache_manager_base() = default;
|
||||
|
||||
//! Launches the cache manager configuration
|
||||
//! \return false if failed
|
||||
// Launches the cache manager configuration
|
||||
// \return false if failed
|
||||
virtual bool configure(std::shared_ptr<etix::cameradar::configuration> configuration) = 0;
|
||||
|
||||
//! get the name of the cache manager
|
||||
// get the name of the cache manager
|
||||
virtual const std::string& get_name() const = 0;
|
||||
|
||||
//! Replaces all cached streams by the content of the vector given as
|
||||
//! parameter
|
||||
// Replaces all cached streams by the content of the vector given as
|
||||
// parameter
|
||||
virtual void set_streams(std::vector<etix::cameradar::stream_model> model) = 0;
|
||||
|
||||
//! Updates a single stream to the cache
|
||||
// Returns true if the stream passed as a parameter has changed in the cache
|
||||
virtual bool has_changed(const etix::cameradar::stream_model&) = 0;
|
||||
|
||||
// Updates a single stream to the cache
|
||||
virtual void update_stream(const etix::cameradar::stream_model& newmodel) = 0;
|
||||
|
||||
//! Gets all cached streams
|
||||
// Gets all cached streams
|
||||
virtual std::vector<etix::cameradar::stream_model> get_streams() = 0;
|
||||
|
||||
//! Gets all valid streams which have been accessed
|
||||
// Gets all valid streams which have been accessed
|
||||
virtual std::vector<etix::cameradar::stream_model> get_valid_streams() = 0;
|
||||
|
||||
//! Get the manager's instance
|
||||
// Get the manager's instance
|
||||
cache_manager_base& get_instance();
|
||||
|
||||
template <typename I, typename T>
|
||||
@@ -87,59 +94,62 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//! The representation of a cache manager
|
||||
//!
|
||||
//! This class loads a shared library, and tries to call an extern "C"
|
||||
//! function which should instanciate a new instance of the plugin.
|
||||
// The representation of a cache manager
|
||||
//
|
||||
// This class loads a shared library, and tries to call an extern "C"
|
||||
// function which should instanciate a new instance of the plugin.
|
||||
class cache_manager {
|
||||
private:
|
||||
static const std::string PLUGIN_EXT;
|
||||
static const std::string default_symbol;
|
||||
|
||||
//! the name of the cache manager
|
||||
// The name of the cache manager
|
||||
std::string name;
|
||||
|
||||
//! The path where the manager is located
|
||||
//! should be specified in the configuration file
|
||||
// The write mutex to avoid conflicts when multithreading
|
||||
std::mutex m;
|
||||
|
||||
// The path where the manager is located
|
||||
// should be specified in the configuration file
|
||||
std::string path;
|
||||
|
||||
//! The symbol entry point of the manager to
|
||||
//! call to create an instance from the shared library
|
||||
// The symbol entry point of the manager to
|
||||
// call to create an instance from the shared library
|
||||
std::string symbol;
|
||||
|
||||
//! The handle to the shared library where is stored the manager
|
||||
// The handle to the shared library where is stored the manager
|
||||
void* handle = nullptr;
|
||||
|
||||
//! The cache manager instance if it is successfully loaded
|
||||
// The cache manager instance if it is successfully loaded
|
||||
cache_manager_iface* ptr = nullptr;
|
||||
|
||||
//! Internal function that creates the full path of the cache manager
|
||||
//!
|
||||
//! full path is composed of: the path, the name, the string "_cache-manager"
|
||||
//! and the extension PLUGIN_EXT depending of the platform
|
||||
// Internal function that creates the full path of the cache manager
|
||||
//
|
||||
// full path is composed of: the path, the name, the string "_cache-manager"
|
||||
// and the extension PLUGIN_EXT depending of the platform
|
||||
std::string make_full_path();
|
||||
|
||||
public:
|
||||
//! Delete constructor
|
||||
// Delete constructor
|
||||
cache_manager() = delete;
|
||||
|
||||
//! The manager needs a path and a symbol to be instantiated.
|
||||
//! The symbol can be changed if the plugin entry point
|
||||
//! is different than the standard one.
|
||||
// The manager needs a path and a symbol to be instantiated.
|
||||
// The symbol can be changed if the plugin entry point
|
||||
// is different than the standard one.
|
||||
cache_manager(const std::string& path,
|
||||
const std::string& name,
|
||||
const std::string& symbol = default_symbol);
|
||||
|
||||
// //! Copy constructor
|
||||
// // Copy constructor
|
||||
// cache_manager(cache_manager &other);
|
||||
|
||||
//! Move constructor
|
||||
// Move constructor
|
||||
cache_manager(cache_manager&& old);
|
||||
|
||||
~cache_manager();
|
||||
|
||||
//! Creates the instance of the cache_manager
|
||||
//!
|
||||
// Creates the instance of the cache_manager
|
||||
//
|
||||
// \return false if the cache_manager failed to be instantiated or if
|
||||
// the cache_manager is not a valid cache manager, true otherwise
|
||||
bool make_instance();
|
||||
@@ -152,23 +162,23 @@ public:
|
||||
return this->get<I, T>();
|
||||
}
|
||||
|
||||
//! Helper to access internal loaded cache_manager
|
||||
//!
|
||||
//! Gives access to the methods of the cache_manager using the operator
|
||||
//! -> (e.g.: cache_manager->get_name());
|
||||
// Helper to access internal loaded cache_manager
|
||||
//
|
||||
// Gives access to the methods of the cache_manager using the operator
|
||||
// -> (e.g.: cache_manager->get_name());
|
||||
cache_manager_iface* operator->();
|
||||
const cache_manager_iface* operator->() const;
|
||||
|
||||
//! helper function to check if a cache_manager is instantiated or not
|
||||
// helper function to check if a cache_manager is instantiated or not
|
||||
friend bool operator==(std::nullptr_t nullp, const cache_manager& p);
|
||||
|
||||
//! helper function to check if a cache_manager is instantiated or not
|
||||
// helper function to check if a cache_manager is instantiated or not
|
||||
friend bool operator==(const cache_manager& p, std::nullptr_t nullp);
|
||||
|
||||
//! helper function to check if a cache_manager is instantiated or not
|
||||
// helper function to check if a cache_manager is instantiated or not
|
||||
friend bool operator!=(std::nullptr_t nullp, const cache_manager& p);
|
||||
|
||||
//! helper function to check if a cache_manager is instantiated or not
|
||||
// helper function to check if a cache_manager is instantiated or not
|
||||
friend bool operator!=(const cache_manager& p, std::nullptr_t nullp);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,19 +14,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <json/reader.h> // Json::Value
|
||||
#include <json/value.h> // Json::Value
|
||||
#include <logger.h> // _LOG_
|
||||
#include <opt_parse.h> // parsing opt
|
||||
#include <string> // std::string
|
||||
#include <utility> // std::pair
|
||||
#include <logger.h> // _LOG_
|
||||
#include <json/value.h> // Json::Value
|
||||
#include <json/reader.h> // Json::Value
|
||||
|
||||
namespace etix {
|
||||
|
||||
namespace cameradar {
|
||||
|
||||
static const std::string default_configuration_path = "conf/cameradar.conf.json";
|
||||
static const std::string default_ids_file_path_ = "conf/ids.json";
|
||||
static const std::string default_urls_file_path_ = "conf/url.json";
|
||||
|
||||
static const std::string default_ports = "554,8554";
|
||||
static const std::string default_subnets = "localhost,168.0.0.0/24";
|
||||
static const std::string default_thumbnail_storage_path = "/tmp";
|
||||
static const std::string default_rtsp_url_file = "conf/url.json";
|
||||
static const std::string default_rtsp_ids_file = "conf/ids.json";
|
||||
static const std::string default_cache_manager_path = "../cache_managers/dumb_cache_manager";
|
||||
static const std::string default_cache_manager_name = "dumb";
|
||||
|
||||
struct configuration {
|
||||
std::string thumbnail_storage_path;
|
||||
@@ -49,7 +56,7 @@ struct configuration {
|
||||
const std::string& rtsp_ids_file,
|
||||
const std::string& cache_manager_path,
|
||||
const std::string& cache_manager_name,
|
||||
const std::string& ports = "1-65535")
|
||||
const std::string& ports)
|
||||
: thumbnail_storage_path(thumbnail_storage_path)
|
||||
, subnets(subnets)
|
||||
, rtsp_url_file(rtsp_url_file)
|
||||
@@ -67,6 +74,6 @@ struct configuration {
|
||||
};
|
||||
|
||||
std::pair<bool, std::string> read_file(const std::string& path);
|
||||
std::pair<bool, configuration> load(const std::string& path);
|
||||
std::pair<bool, configuration> load(const std::pair<bool, etix::tool::opt_parse>& args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ std::string decode64(const std::string& str_to_decode);
|
||||
std::string base64_encode(unsigned char const*, unsigned int len);
|
||||
std::string base64_decode(std::string const& s);
|
||||
|
||||
} //! encode
|
||||
} // encode
|
||||
|
||||
} //! tool
|
||||
} // tool
|
||||
|
||||
} //! etix
|
||||
} // etix
|
||||
|
||||
@@ -24,8 +24,8 @@ namespace tool {
|
||||
|
||||
static std::mutex mutex;
|
||||
|
||||
//! Format a string with the given arguments
|
||||
//! same behavior as sprintf.
|
||||
// Format a string with the given arguments
|
||||
// same behavior as sprintf.
|
||||
template <class... Args>
|
||||
std::string
|
||||
fmt(const std::string& base, Args... args) {
|
||||
|
||||
@@ -34,8 +34,8 @@ bool create_folder(const std::string& folder);
|
||||
bool create_recursive_folder(const std::string& folder);
|
||||
std::string home();
|
||||
|
||||
//! this functions take a copy because we need to make some operations on the string
|
||||
//! for example, we need to apply std::string::pop_back
|
||||
// this functions take a copy because we need to make some operations on the string
|
||||
// for example, we need to apply std::string::pop_back
|
||||
std::string get_file_folder(std::string full_file_path);
|
||||
|
||||
bool copy(const std::string& src, const std::string& dst);
|
||||
|
||||
@@ -23,20 +23,13 @@ namespace etix {
|
||||
|
||||
namespace tool {
|
||||
|
||||
//! Parse command line arguments
|
||||
class opt_parse {
|
||||
private:
|
||||
//! An argumetn representation to be passed to the program
|
||||
struct opt_param {
|
||||
//! is it required
|
||||
bool required;
|
||||
//! Does he needs arguments
|
||||
bool need_arg;
|
||||
//! What is its name
|
||||
std::string name;
|
||||
//! Description
|
||||
std::string desc;
|
||||
//! the argument of the arguments !
|
||||
std::string argument;
|
||||
bool is_passed = false;
|
||||
|
||||
@@ -44,22 +37,14 @@ private:
|
||||
: required(required), need_arg(need_arg), name(name), desc(desc) {}
|
||||
};
|
||||
|
||||
//! Map of the different possibles argument as string and their
|
||||
//! rertpresntation
|
||||
std::unordered_map<std::string, opt_param> params;
|
||||
//! The total count of arguments for this program
|
||||
int argc;
|
||||
//! The list of arguments as a String
|
||||
char** argv;
|
||||
//! The total count of params
|
||||
int params_cnt = 0;
|
||||
|
||||
public:
|
||||
//! An iterator to iterate over all the arguments of
|
||||
//! the program
|
||||
class iterator {
|
||||
private:
|
||||
//! The arguments vector and their argumetns
|
||||
std::vector<std::pair<std::string, std::string>> args;
|
||||
unsigned int opt_pos = 0;
|
||||
|
||||
@@ -71,65 +56,40 @@ public:
|
||||
return *this;
|
||||
}
|
||||
std::pair<std::string, std::string>& operator*() { return this->args.at(this->opt_pos); }
|
||||
bool operator==(const iterator& rhs) const { return this->opt_pos == rhs.opt_pos; }
|
||||
bool operator!=(const iterator& rhs) const { return this->opt_pos != rhs.opt_pos; }
|
||||
bool
|
||||
operator==(const iterator& rhs) const {
|
||||
return this->opt_pos == rhs.opt_pos;
|
||||
}
|
||||
bool
|
||||
operator!=(const iterator& rhs) const {
|
||||
return this->opt_pos != rhs.opt_pos;
|
||||
}
|
||||
};
|
||||
|
||||
opt_parse() = delete;
|
||||
|
||||
//! \param argc Total count of arguements
|
||||
//! \param argv Cmdline arguments from program startup
|
||||
opt_parse(int argc, char* argv[]);
|
||||
|
||||
~opt_parse();
|
||||
|
||||
//! Add a argument required for your program
|
||||
//!
|
||||
//! If the specified argument is not given in cmdline, a error will be
|
||||
//! generated
|
||||
//! \param name The name of the parameter as a string (e.g "-l")
|
||||
//! \param desc A description that will be used by the function `print_help`
|
||||
//! \param need_arg Does the argument require a parameter
|
||||
void required(const std::string& name, const std::string& desc = "", bool need_arg = true);
|
||||
|
||||
//! Add an optional argument for your program
|
||||
//!
|
||||
//! If the specified argument is not given in cmdline, a error will be
|
||||
//! generated
|
||||
//! \param name The name of the parameter as a string (e.g "-l")
|
||||
//! \param desc A description that will be used by the function `print_help`
|
||||
//! \param need_arg Does the argument require a parameter
|
||||
void optional(const std::string& name, const std::string& desc = "", bool need_arg = true);
|
||||
|
||||
//! Process the parsing of the arguments
|
||||
bool execute();
|
||||
|
||||
//! \return an iterator on the begin of the arguments
|
||||
iterator begin() const;
|
||||
|
||||
//! \return the iterator on the end of the arguments
|
||||
iterator end() const;
|
||||
|
||||
//! Print the usage using the parameter setted when referencing the arguments
|
||||
//! for the program
|
||||
void print_usage() const;
|
||||
|
||||
//! Print an help message generated using all the specified arguments
|
||||
void print_help() const;
|
||||
|
||||
//! Is there on the parameters (missing parameter ? unknows ? missing
|
||||
//! arguments ?)
|
||||
//! \return true if there is error, false otherwise
|
||||
bool has_error() const;
|
||||
|
||||
//! Does the option exist or not ?
|
||||
//! \param opt The name of the option to check
|
||||
//! \return true if the param exist, false otherwise
|
||||
bool exist(const std::string& opt) const;
|
||||
|
||||
//! Acces to an argument from its name
|
||||
//! \param opt The name of the option to check
|
||||
//! \return the the argument of the param as a string
|
||||
std::string operator[](const std::string& opt) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cameradar_task.h> // task interface
|
||||
#include <cachemanager.h> // cacheManager
|
||||
#include <cameradar_task.h> // task interface
|
||||
#include <describe.h> // send DESCRIBE through cURL
|
||||
#include <future> // std::async & std::future
|
||||
#include <signal_handler.h> // signals
|
||||
#include <stream_model.h> // data model
|
||||
|
||||
@@ -41,6 +42,7 @@ public:
|
||||
bool test_ids(const etix::cameradar::stream_model& cit,
|
||||
const std::string& pit,
|
||||
const std::string& uit) const;
|
||||
bool bruteforce_camera(const stream_model& stream) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cachemanager.h> // cacheManager
|
||||
#include <cameradar_task.h> // task interface
|
||||
#include <memory> // std::shared_ptr
|
||||
#include <logger.h> // LOG
|
||||
#include <curl/curl.h> // cURL client for discovery
|
||||
#include <describe.h> // send DESCRIBE through cURL
|
||||
#include <future> // std::async & std::future
|
||||
#include <logger.h> // LOG
|
||||
#include <memory> // std::shared_ptr
|
||||
#include <signal_handler.h> // signals
|
||||
#include <stream_model.h> // data model
|
||||
#include <cachemanager.h> // cacheManager
|
||||
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
@@ -42,6 +43,7 @@ public:
|
||||
virtual bool run() const;
|
||||
|
||||
bool test_path(const etix::cameradar::stream_model& cit, const std::string& it) const;
|
||||
bool bruteforce_camera(const stream_model& stream) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cachemanager.h> // cacheManager
|
||||
#include <cameradar_task.h> // task interface
|
||||
#include <fmt.h> // fmt
|
||||
#include <future> // std::async & std::future
|
||||
#include <launch_command.h> // launch_command
|
||||
#include <rtsp_path.h> // make_path
|
||||
#include <signal_handler.h> // signals
|
||||
#include <stream_model.h> // data model
|
||||
#include <cachemanager.h> // cacheManager
|
||||
#include <fmt.h> // fmt
|
||||
#include <rtsp_path.h> // make_path
|
||||
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
@@ -41,6 +42,7 @@ public:
|
||||
virtual bool run() const;
|
||||
|
||||
std::string build_output_file_path(const std::string& path) const;
|
||||
bool generate_thumbnail(const stream_model& stream) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ distribution.
|
||||
#pragma warning(disable : 4786)
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
// Help out windows:
|
||||
#if defined(_DEBUG) && !defined(DEBUG)
|
||||
@@ -43,9 +43,9 @@ distribution.
|
||||
#endif
|
||||
|
||||
#ifdef TIXML_USE_STL
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#define TIXML_STRING std::string
|
||||
#else
|
||||
#include "tinystr.h"
|
||||
@@ -1086,9 +1086,18 @@ public:
|
||||
return const_cast<TiXmlAttribute*>((const_cast<const TiXmlAttribute*>(this))->Previous());
|
||||
}
|
||||
|
||||
bool operator==(const TiXmlAttribute& rhs) const { return rhs.name == name; }
|
||||
bool operator<(const TiXmlAttribute& rhs) const { return name < rhs.name; }
|
||||
bool operator>(const TiXmlAttribute& rhs) const { return name > rhs.name; }
|
||||
bool
|
||||
operator==(const TiXmlAttribute& rhs) const {
|
||||
return rhs.name == name;
|
||||
}
|
||||
bool
|
||||
operator<(const TiXmlAttribute& rhs) const {
|
||||
return name < rhs.name;
|
||||
}
|
||||
bool
|
||||
operator>(const TiXmlAttribute& rhs) const {
|
||||
return name > rhs.name;
|
||||
}
|
||||
|
||||
/* Attribute parsing starts: first letter of the name
|
||||
returns: the next char after the
|
||||
@@ -1171,7 +1180,6 @@ private:
|
||||
//*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute
|
||||
//(sentinel-element),
|
||||
//*ME: this class must be also use a hidden/disabled copy-constructor
|
||||
//!!!
|
||||
TiXmlAttributeSet(const TiXmlAttributeSet&); // not allowed
|
||||
void operator=(const TiXmlAttributeSet&); // not allowed (as TiXmlAttribute)
|
||||
|
||||
@@ -1509,7 +1517,8 @@ public:
|
||||
#endif
|
||||
|
||||
TiXmlText(const TiXmlText& copy) : TiXmlNode(TiXmlNode::TINYXML_TEXT) { copy.CopyTo(this); }
|
||||
TiXmlText& operator=(const TiXmlText& base) {
|
||||
TiXmlText&
|
||||
operator=(const TiXmlText& base) {
|
||||
base.CopyTo(this);
|
||||
return *this;
|
||||
}
|
||||
@@ -1664,7 +1673,8 @@ public:
|
||||
TiXmlUnknown(const TiXmlUnknown& copy) : TiXmlNode(TiXmlNode::TINYXML_UNKNOWN) {
|
||||
copy.CopyTo(this);
|
||||
}
|
||||
TiXmlUnknown& operator=(const TiXmlUnknown& copy) {
|
||||
TiXmlUnknown&
|
||||
operator=(const TiXmlUnknown& copy) {
|
||||
copy.CopyTo(this);
|
||||
return *this;
|
||||
}
|
||||
@@ -2039,7 +2049,8 @@ public:
|
||||
TiXmlHandle(TiXmlNode* _node) { this->node = _node; }
|
||||
/// Copy constructor
|
||||
TiXmlHandle(const TiXmlHandle& ref) { this->node = ref.node; }
|
||||
TiXmlHandle operator=(const TiXmlHandle& ref) {
|
||||
TiXmlHandle
|
||||
operator=(const TiXmlHandle& ref) {
|
||||
if (&ref != this) this->node = ref.node;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user