OpenCPN Partial API docs
Loading...
Searching...
No Matches
PluginHandler Class Reference

Handle plugin install from remote repositories and local operations to Uninstall and list plugins. More...

#include <plugin_handler.h>

Public Member Functions

 PluginHandler (const PluginHandler &)=delete
 
PluginHandleroperator= (const PluginHandler &)=delete
 
bool IsPluginWritable (std::string name)
 Check if given plugin can be installed/updated.
 
const std::vector< PluginMetadataGetInstalled ()
 Return list of all installed and loaded plugins.
 
std::vector< std::string > GetInstalldataPlugins ()
 Return list of installed plugins lower case names, not necessarily loaded.
 
void SetInstalledMetadata (const PluginMetadata &pm)
 Set metadata for an installed plugin.
 
const std::vector< PluginMetadataGetAvailable ()
 Update catalog and return list of available, not installed plugins.
 
std::vector< PluginMetadatagetCompatiblePlugins ()
 Return list of available, unique and compatible plugins from configured XML catalog.
 
const std::map< std::string, int > GetCountByTarget ()
 Map of available plugin targets -> number of occurences.
 
std::string GetPluginByLibrary (const std::string &filename)
 Return plugin containing given filename or "" if not found.
 
std::string GetMetadataPath ()
 Return path to metadata XML file.
 
std::string GetUserMetadataPath ()
 Return path to user, writable metadata XML file.
 
void setMetadata (std::string path)
 Set path to metadata XML file.
 
bool InstallPlugin (PluginMetadata plugin)
 Download and install a new, not installed plugin.
 
bool InstallPlugin (PluginMetadata plugin, std::string path)
 Install a new, downloaded but not installed plugin tarball.
 
bool ExtractMetadata (const std::string &path, PluginMetadata &metadata)
 Extract metadata in given tarball path.
 
bool InstallPlugin (const std::string &path)
 
bool Uninstall (const std::string plugin)
 Uninstall an installed and loaded plugin.
 
bool ClearInstallData (const std::string plugin_name)
 Remove installation data for not loaded plugin.
 
bool InstallPluginFromCache (PluginMetadata plugin)
 Install plugin tarball from local cache.
 
CatalogDataGetCatalogData ()
 

Static Public Member Functions

static PluginHandlerGetInstance ()
 Singleton factory.
 
static void Cleanup (const std::string &filelist, const std::string &plugname)
 Cleanup failed installation attempt using filelist for plugin.
 
static void CleanupFiles (const std::string &manifestFile, const std::string &plugname)
 
static std::string PluginsInstallDataPath ()
 Return base directory for installation data.
 
static std::string FileListPath (std::string name)
 Return path to installation manifest for given plugin.
 
static std::string VersionPath (std::string name)
 Return path to file containing version for given plugin.
 
static std::string ImportedMetadataPath (std::string name)
 Return path to imported metadata for given plugin.
 
static std::vector< std::string > GetImportPaths ()
 List of paths for imported plugins metadata.
 
static bool IsCompatible (const PluginMetadata &metadata, const char *os=PKG_TARGET, const char *os_version=PKG_TARGET_VERSION)
 Return true if given plugin is loadable on given os/version.
 

Public Attributes

obs::EventVar evt_download_ok
 Notified with plugin name + version string after successful download from repository.
 
obs::EventVar evt_download_failed
 Notified with plugin name after failed download attempt.
 

Detailed Description

Handle plugin install from remote repositories and local operations to Uninstall and list plugins.

The plugin maintains an internal list and is a singleton.

Remote repositories are based on XML files describing metadata and addresses to tarballs with compiled and installed files, basically under there different directories.

  • The plugin directory e. g., /usr/lib/opencpn/
  • The data directory e. g., /usr/share/data/opencpn/plugins.
  • The binary directory (additional program) e. g, /usr/bin.

The compiled plugins are installed to user-writable location(s)

  • Linux: under ~/.local, possibly relocated by environment variables.
  • Windows: under &GetWinPluginBaseDir() which is configurable, defaults to APPDATA%/Local/opencpn
  • Flatpak: under ~/.var/app/org.opencpn.OpenCPN

However, plugins are loaded from multiple locations basically corresponding to new and old lacations:

  • Windows: GetSharedDataDirPtr():GetWinPluginBaseDir()
  • linux: As defined by XDG_DATA_DIRS, defaulting to ~/.local/lib/opencpn:/usr/local/lib/opencpn:/usr/lib/opencpn
  • flatpak: /app/lib/opencpn:/app/extensions/lib/opencpn:~/.var/app/opencpn/lib

Definition at line 85 of file plugin_handler.h.

Constructor & Destructor Documentation

◆ PluginHandler()

PluginHandler::PluginHandler ( )
protected

Definition at line 366 of file plugin_handler.cpp.

Member Function Documentation

◆ Cleanup()

void PluginHandler::Cleanup ( const std::string &  filelist,
const std::string &  plugname 
)
static

Cleanup failed installation attempt using filelist for plugin.

Definition at line 1096 of file plugin_handler.cpp.

◆ CleanupFiles()

void PluginHandler::CleanupFiles ( const std::string &  manifestFile,
const std::string &  plugname 
)
static

Definition at line 1067 of file plugin_handler.cpp.

◆ ClearInstallData()

bool PluginHandler::ClearInstallData ( const std::string  plugin_name)

Remove installation data for not loaded plugin.

Definition at line 1285 of file plugin_handler.cpp.

◆ ExtractMetadata()

bool PluginHandler::ExtractMetadata ( const std::string &  path,
PluginMetadata metadata 
)

Extract metadata in given tarball path.

Definition at line 1250 of file plugin_handler.cpp.

◆ FileListPath()

std::string PluginHandler::FileListPath ( std::string  name)
static

Return path to installation manifest for given plugin.

Definition at line 421 of file plugin_handler.cpp.

◆ GetAvailable()

const std::vector< PluginMetadata > PluginHandler::GetAvailable ( )

Update catalog and return list of available, not installed plugins.

Definition at line 1146 of file plugin_handler.cpp.

◆ GetCatalogData()

CatalogData * PluginHandler::GetCatalogData ( )
inline

Definition at line 188 of file plugin_handler.h.

◆ getCompatiblePlugins()

std::vector< PluginMetadata > PluginHandler::getCompatiblePlugins ( )

Return list of available, unique and compatible plugins from configured XML catalog.

Compare two PluginMetadata objects, a named c++ requirement.

Definition at line 1123 of file plugin_handler.cpp.

◆ GetCountByTarget()

const std::map< std::string, int > PluginHandler::GetCountByTarget ( )

Map of available plugin targets -> number of occurences.

Definition at line 1044 of file plugin_handler.cpp.

◆ GetImportPaths()

std::vector< std::string > PluginHandler::GetImportPaths ( )
static

List of paths for imported plugins metadata.

Definition at line 1063 of file plugin_handler.cpp.

◆ GetInstalldataPlugins()

std::vector< std::string > PluginHandler::GetInstalldataPlugins ( )

Return list of installed plugins lower case names, not necessarily loaded.

Definition at line 1163 of file plugin_handler.cpp.

◆ GetInstalled()

const std::vector< PluginMetadata > PluginHandler::GetInstalled ( )

Return list of all installed and loaded plugins.

Definition at line 1174 of file plugin_handler.cpp.

◆ GetInstance()

PluginHandler * PluginHandler::GetInstance ( )
static

Singleton factory.

Definition at line 940 of file plugin_handler.cpp.

◆ GetMetadataPath()

std::string PluginHandler::GetMetadataPath ( )

Return path to metadata XML file.

Definition at line 1029 of file plugin_handler.cpp.

◆ GetPluginByLibrary()

std::string PluginHandler::GetPluginByLibrary ( const std::string &  filename)

Return plugin containing given filename or "" if not found.

Definition at line 1467 of file plugin_handler.cpp.

◆ GetUserMetadataPath()

std::string PluginHandler::GetUserMetadataPath ( )

Return path to user, writable metadata XML file.

Definition at line 1038 of file plugin_handler.cpp.

◆ ImportedMetadataPath()

std::string PluginHandler::ImportedMetadataPath ( std::string  name)
static

Return path to imported metadata for given plugin.

Definition at line 431 of file plugin_handler.cpp.

◆ InstallPlugin() [1/3]

bool PluginHandler::InstallPlugin ( const std::string &  path)

Definition at line 1241 of file plugin_handler.cpp.

◆ InstallPlugin() [2/3]

bool PluginHandler::InstallPlugin ( PluginMetadata  plugin)

Download and install a new, not installed plugin.

Definition at line 1225 of file plugin_handler.cpp.

◆ InstallPlugin() [3/3]

bool PluginHandler::InstallPlugin ( PluginMetadata  plugin,
std::string  path 
)

Install a new, downloaded but not installed plugin tarball.

Definition at line 1209 of file plugin_handler.cpp.

◆ InstallPluginFromCache()

bool PluginHandler::InstallPluginFromCache ( PluginMetadata  plugin)

Install plugin tarball from local cache.

Definition at line 1477 of file plugin_handler.cpp.

◆ IsCompatible()

bool PluginHandler::IsCompatible ( const PluginMetadata metadata,
const char *  os = PKG_TARGET,
const char *  os_version = PKG_TARGET_VERSION 
)
static

Return true if given plugin is loadable on given os/version.

Definition at line 368 of file plugin_handler.cpp.

◆ IsPluginWritable()

bool PluginHandler::IsPluginWritable ( std::string  name)

Check if given plugin can be installed/updated.

Definition at line 948 of file plugin_handler.cpp.

◆ PluginsInstallDataPath()

std::string PluginHandler::PluginsInstallDataPath ( )
static

Return base directory for installation data.

Definition at line 177 of file plugin_handler.cpp.

◆ SetInstalledMetadata()

void PluginHandler::SetInstalledMetadata ( const PluginMetadata pm)

Set metadata for an installed plugin.

Definition at line 1200 of file plugin_handler.cpp.

◆ setMetadata()

void PluginHandler::setMetadata ( std::string  path)
inline

Set path to metadata XML file.

Definition at line 165 of file plugin_handler.h.

◆ Uninstall()

bool PluginHandler::Uninstall ( const std::string  plugin)

Uninstall an installed and loaded plugin.

Definition at line 1323 of file plugin_handler.cpp.

◆ VersionPath()

std::string PluginHandler::VersionPath ( std::string  name)
static

Return path to file containing version for given plugin.

Definition at line 426 of file plugin_handler.cpp.

Member Data Documentation

◆ evt_download_failed

obs::EventVar PluginHandler::evt_download_failed

Notified with plugin name after failed download attempt.

Definition at line 100 of file plugin_handler.h.

◆ evt_download_ok

obs::EventVar PluginHandler::evt_download_ok

Notified with plugin name + version string after successful download from repository.

Definition at line 97 of file plugin_handler.h.


The documentation for this class was generated from the following files: