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
+59 -49
View File
@@ -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);
};
}