ocpp 0.24.1
A C++ implementation of the Open Charge Point Protocol
Public Member Functions | Protected Member Functions | List of all members
ocpp::v2::InitDeviceModelDb Class Reference

Class to initialize the device model db using the component config files. More...

#include <init_device_model_db.hpp>

Inheritance diagram for ocpp::v2::InitDeviceModelDb:
ocpp::common::DatabaseHandlerCommon

Public Member Functions

 InitDeviceModelDb (const std::filesystem::path &database_path, const std::filesystem::path &migration_files_path)
 Constructor. More...
 
virtual ~InitDeviceModelDb ()
 Destructor.
 
void initialize_database (const std::filesystem::path &config_path, const bool delete_db_if_exists)
 Initialize the database schema and component config. More...
 
- Public Member Functions inherited from ocpp::common::DatabaseHandlerCommon
 DatabaseHandlerCommon (std::unique_ptr< DatabaseConnectionInterface > database, const fs::path &sql_migration_files_path, uint32_t target_schema_version) noexcept
 Common database handler class Class handles some common database functionality like inserting and removing transaction messages. More...
 
void open_connection ()
 Opens connection to database file and performs the initialization by calling init_sql()
 
void close_connection ()
 Closes the database connection.
 
virtual std::vector< DBTransactionMessageget_message_queue_messages (const QueueType queue_type=QueueType::Transaction)
 Get messages from messages queue table specified by queue_type. More...
 
virtual void insert_message_queue_message (const DBTransactionMessage &message, const QueueType queue_type=QueueType::Transaction)
 Insert a new message into messages queue table specified by queue_type. More...
 
virtual void remove_message_queue_message (const std::string &unique_id, const QueueType queue_type=QueueType::Transaction)
 Remove a message from the messages queue table specified by queue_type. More...
 
virtual void clear_message_queue (const QueueType queue_type=QueueType::Transaction)
 Deletes all entries from message queue table specified by queue_type. More...
 

Protected Member Functions

virtual void init_sql () override
 Init database: set foreign keys on (so when a component is removed or updated, all variables, characteristics and attributes belonging to that component are also removed or updated, for example). More...
 
virtual void init_sql ()=0
 Perform the initialization needed to use the database. Will be called by open_connection() More...
 

Additional Inherited Members

- Protected Attributes inherited from ocpp::common::DatabaseHandlerCommon
std::unique_ptr< DatabaseConnectionInterfacedatabase
 
const fs::path sql_migration_files_path
 
const uint32_t target_schema_version
 

Detailed Description

Class to initialize the device model db using the component config files.

This class will read the device model config files and put them in the device model database.

If the database already exists and there are some changes on components, this class will make the changes in the database accordingly.

It will also re-apply the component config. Config items will only be replaced if they are changed and the value in the database is not set by an external source, like the CSMS.

The data from the component config json files or database are read into some structs. Some structs could be reused from the DeviceModelStorage class, but some members are missing there and and to prevent too many database reads, some structs are 'redefined' in this class with the proper members.

Since the DeviceModel class creates a map based on the device model database in the constructor, this class should first be finished with the initialization before creating the DeviceModel class.

The config values are updated every startup as well, as long as the initial / default values are set in the database. If the value is set by the user or csms or some other process, the value will not be overwritten.

Almost every function throws exceptions, because this class should be used only when initializing the chargepoint and the database must be correct before starting the application.

Constructor & Destructor Documentation

◆ InitDeviceModelDb()

ocpp::v2::InitDeviceModelDb::InitDeviceModelDb ( const std::filesystem::path &  database_path,
const std::filesystem::path &  migration_files_path 
)

Constructor.

Parameters
database_pathPath to the database.
migration_files_pathPath to the migration files.

Member Function Documentation

◆ init_sql()

void ocpp::v2::InitDeviceModelDb::init_sql ( )
overrideprotectedvirtual

Init database: set foreign keys on (so when a component is removed or updated, all variables, characteristics and attributes belonging to that component are also removed or updated, for example).

Exceptions
InitDeviceModelDbErrorWhen foreign key pragma could not be set to 'ON'.

Implements ocpp::common::DatabaseHandlerCommon.

◆ initialize_database()

void ocpp::v2::InitDeviceModelDb::initialize_database ( const std::filesystem::path &  config_path,
const bool  delete_db_if_exists = true 
)

Initialize the database schema and component config.

Parameters
config_pathPath to the component config.
delete_db_if_existsSet to true to delete the database if it already exists.
Exceptions
InitDeviceModelDbError- When database could not be initialized or
  • Foreign keys could not be turned on or
  • Something could not be added to, retrieved or removed from the database
std::runtime_errorIf something went wrong during migration
DatabaseMigrationExceptionIf something went wrong during migration
DatabaseConnectionExceptionIf the database could not be opened
std::filesystem::filesystem_errorIf the component config path does not exist

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