|
ocpp 0.24.1
A C++ implementation of the Open Charge Point Protocol
|
Class to initialize the device model db using the component config files. More...
#include <init_device_model_db.hpp>
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< DBTransactionMessage > | get_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< DatabaseConnectionInterface > | database |
| const fs::path | sql_migration_files_path |
| const uint32_t | target_schema_version |
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.
| ocpp::v2::InitDeviceModelDb::InitDeviceModelDb | ( | const std::filesystem::path & | database_path, |
| const std::filesystem::path & | migration_files_path | ||
| ) |
Constructor.
| database_path | Path to the database. |
| migration_files_path | Path to the migration files. |
|
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).
| InitDeviceModelDbError | When foreign key pragma could not be set to 'ON'. |
Implements ocpp::common::DatabaseHandlerCommon.
| 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.
| config_path | Path to the component config. |
| delete_db_if_exists | Set to true to delete the database if it already exists. |
| InitDeviceModelDbError | - When database could not be initialized or
|
| std::runtime_error | If something went wrong during migration |
| DatabaseMigrationException | If something went wrong during migration |
| DatabaseConnectionException | If the database could not be opened |
| std::filesystem::filesystem_error | If the component config path does not exist |