diff options
author | eportnov <eportnov@ibs.ru> | 2022-09-12 16:46:49 +0300 |
---|---|---|
committer | eportnov <eportnov@ibs.ru> | 2022-09-12 16:46:49 +0300 |
commit | df33492b80495fd36a1a488c0b0a39753f1df415 (patch) | |
tree | c465900180840832e241ca5419dd90b429459588 /src/smtp_service.cpp | |
parent | 9fa4addff6f90a8b5697a594e034f5517d64dd25 (diff) | |
parent | cdb7ae4c729b6a6c51b57eeefd21574952a4b767 (diff) | |
download | obmc-sila-smtp-df33492b80495fd36a1a488c0b0a39753f1df415.tar.xz |
Merge branch 'feature/refactor'
Diffstat (limited to 'src/smtp_service.cpp')
-rw-r--r-- | src/smtp_service.cpp | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/src/smtp_service.cpp b/src/smtp_service.cpp deleted file mode 100644 index 6235e4c..0000000 --- a/src/smtp_service.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "smtp_service.hpp" -#include "message_sender.hpp" - -namespace smtp -{ - static constexpr char HOST_PROPERTY[] = "Host"; - static constexpr char USER_PROPERTY[] = "User"; - static constexpr char PORT_PROPERTY[] = "Port"; - - // - // Constructors - // - - SmtpService::SmtpService( ConnectionPtr connection ) - { - FillStorageByDefault(); - CreateService( connection ); - CreateInterface( connection ); - } - - // - // Private methods - // - - void SmtpService::FillStorageByDefault() - { - mStorage.host = ""; - mStorage.username = ""; - mStorage.password = ""; - mStorage.port = ""; - } - - void SmtpService::CreateService( ConnectionPtr connection ) - { - static constexpr char SMTP_BUS_NAME[] = "xyz.openbmc_project.SMTP"; - - connection->request_name( SMTP_BUS_NAME ); - } - - void SmtpService::CreateInterface( ConnectionPtr connection ) - { - static constexpr char SMTP_OBJECT_NAME[] = "/xyz/openbmc_project/SMTP"; - static constexpr char SMTP_INTERFACE_NAME[] = "xyz.openbmc_project.SMTP"; - - mObjectServer = std::make_shared<sdbusplus::asio::object_server>( connection ); - mInterface = mObjectServer->add_interface( SMTP_OBJECT_NAME, SMTP_INTERFACE_NAME ); - - AddProperties(); - AddMethods(); - - mInterface->initialize(); - } - - void SmtpService::AddProperties() - { - mInterface->register_property( HOST_PROPERTY, mStorage.host, sdbusplus::asio::PropertyPermission::readOnly ); - mInterface->register_property( USER_PROPERTY, mStorage.username, sdbusplus::asio::PropertyPermission::readOnly ); - mInterface->register_property( PORT_PROPERTY, mStorage.port, sdbusplus::asio::PropertyPermission::readOnly ); - } - - void SmtpService::AddMethods() - { - static constexpr char SMTP_SEND_MESSAGE_METHOD_NAME[] = "SendMail"; - static constexpr char SMTP_CHANGE_PARAMETERS_METHOD_NAME[] = "ChangeParameters"; - - mInterface->register_method(SMTP_SEND_MESSAGE_METHOD_NAME, [this]( std::string const& mail_from, - std::string const& mail_to, - std::list<std::string> const& cc, - std::string const& theme, - std::string const& text ) - { return MessageSender{ mStorage }.Send( mail_from, mail_to, cc, theme, text );}); - - - mInterface->register_method(SMTP_CHANGE_PARAMETERS_METHOD_NAME, [this]( std::string const& user, - std::string const& password, - std::string const& host, - std::string const& port ) - { return RefreshSettings(user, password, host, port);}); - } - - bool SmtpService::RefreshSettings(std::string const& user, - std::string const& password, - std::string const& host, - std::string const& port) - { - mStorage.username = user; - mStorage.password = password; - mStorage.host = host; - mStorage.port = port; - - mInterface->set_property(HOST_PROPERTY, host); - mInterface->set_property(USER_PROPERTY, user); - mInterface->set_property(PORT_PROPERTY, port); - return true; - } -} |