Multithreading & UX update

This commit is contained in:
Brendan LE GLAUNEC
2016-10-28 09:50:37 +02:00
committed by Brendan Le Glaunec
parent de757e848d
commit 509d68f023
39 changed files with 572 additions and 407 deletions
@@ -29,6 +29,8 @@ private:
std::vector<etix::cameradar::stream_model> streams;
std::shared_ptr<etix::cameradar::configuration> configuration;
std::mutex m;
public:
using cache_manager_base::cache_manager_base;
~dumb_cache_manager();
@@ -38,6 +40,8 @@ public:
bool load_dumb_conf(std::shared_ptr<etix::cameradar::configuration> configuration);
bool configure(std::shared_ptr<etix::cameradar::configuration> configuration) override;
bool has_changed(const etix::cameradar::stream_model&);
void set_streams(std::vector<etix::cameradar::stream_model> model);
void update_stream(const etix::cameradar::stream_model& newmodel);
@@ -47,12 +47,14 @@ dumb_cache_manager::load_dumb_conf(std::shared_ptr<etix::cameradar::configuratio
//! parameter
void
dumb_cache_manager::set_streams(std::vector<etix::cameradar::stream_model> model) {
std::lock_guard<std::mutex> lock(m);
this->streams = model;
}
//! Inserts a single stream to the cache
void
dumb_cache_manager::update_stream(const etix::cameradar::stream_model& newmodel) {
std::lock_guard<std::mutex> lock(m);
for (auto& stream : this->streams) {
if (stream.address == newmodel.address && stream.port == newmodel.port) {
stream = newmodel;
@@ -76,13 +78,22 @@ std::vector<etix::cameradar::stream_model>
dumb_cache_manager::get_valid_streams() {
std::vector<stream_model> ret;
for (const auto& stream : this->streams) {
if ((not stream.service_name.compare("rtsp") && not stream.state.compare("open")) &&
stream.ids_found && stream.path_found)
ret.push_back(stream);
if (stream.ids_found && stream.path_found) ret.push_back(stream);
}
return ret;
}
// Returns true if the stream passed as a parameter has changed in the cache
bool
dumb_cache_manager::has_changed(const etix::cameradar::stream_model& old) {
for (const auto& stream : this->streams) {
if (stream.address == old.address)
if (stream.path_found != old.path_found || stream.ids_found != old.ids_found)
return true;
}
return false;
}
extern "C" {
cache_manager_iface*
cache_manager_instance_new() {