#include "smtp.hpp" #include "message/queue_sender.hpp" namespace smtp::service { // // Constructors // Smtp::Smtp( ConnectionPtr connection, manage::Settings const& settings, manage::Mail const& mail_to ) : mSettingsStorage(settings), mMailTo(mail_to) { CreateService( connection ); CreateMessengerInterface( connection ); CreateSettingsManagerInterface( connection ); CreateMailManagerInterface( connection ); message::QueueSender sender{ mSettingsStorage, mMailTo, mMessageQueue, connection }; std::thread sender_message( &message::QueueSender::SendMessages, std::move(sender) ); sender_message.detach(); } // // Private methods // void Smtp::CreateService( ConnectionPtr connection ) { static constexpr char SMTP_BUS_NAME[] = "xyz.openbmc_project.SMTP"; connection->request_name( SMTP_BUS_NAME ); } void Smtp::CreateMessengerInterface( ConnectionPtr connection ) { static constexpr char SMTP_OBJECT_NAME[] = "/xyz/openbmc_project/SMTP/Messenger"; static constexpr char SMTP_INTERFACE_NAME[] = "xyz.openbmc_project.Messenger"; mObjectServer = std::make_shared( connection ); mMessengerInterface = mObjectServer->add_interface( SMTP_OBJECT_NAME, SMTP_INTERFACE_NAME ); AddMessengerMethods(); mMessengerInterface->initialize(); } void Smtp::CreateSettingsManagerInterface(ConnectionPtr connection) { static constexpr char SMTP_MANAGER_OBJECT_NAME[] = "/xyz/openbmc_project/SMTP/Manager"; static constexpr char SMTP_SETTINGS_MANAGER_INTERFACE_NAME[] = "xyz.openbmc_project.SettingsManager"; mObjectServer = std::make_shared( connection ); mManagerSettingsInterface = mObjectServer->add_interface( SMTP_MANAGER_OBJECT_NAME, SMTP_SETTINGS_MANAGER_INTERFACE_NAME ); AddSettingsManagerMethods(); mManagerSettingsInterface->initialize(); } void Smtp::CreateMailManagerInterface(ConnectionPtr connection) { static constexpr char SMTP_MANAGER_OBJECT_NAME[] = "/xyz/openbmc_project/SMTP/Manager"; static constexpr char SMTP_MAIL_MANAGER_INTERFACE_NAME[] = "xyz.openbmc_project.MailManager"; mObjectServer = std::make_shared( connection ); mManagerMailInterface = mObjectServer->add_interface( SMTP_MANAGER_OBJECT_NAME, SMTP_MAIL_MANAGER_INTERFACE_NAME ); AddMailManagerMethods(); mManagerMailInterface->initialize(); } void Smtp::AddMessengerMethods() { static constexpr char SMTP_SEND_MESSAGE_METHOD_NAME[] = "SendMail"; mMessengerInterface->register_method( SMTP_SEND_MESSAGE_METHOD_NAME, [this]( std::string const& theme, std::string const& text ) { mMessageQueue.Push({theme, text});}); } void Smtp::AddSettingsManagerMethods() { static constexpr char SMTP_SET_SETTINGS_METHOD_NAME[] = "SetSettings"; static constexpr char SMTP_GET_SETTINGS_METHOD_NAME[] = "GetSettings"; mManagerSettingsInterface->register_method(SMTP_SET_SETTINGS_METHOD_NAME, [this]( bool is_need_auth, bool is_need_ssl, std::string const& user, std::string const& password, std::string const& host, std::string const& port ) { return mSettingsStorage.SetSettings({ is_need_auth, is_need_ssl, user, password, host, port});}); mManagerSettingsInterface->register_method(SMTP_GET_SETTINGS_METHOD_NAME, [this](){ return mSettingsStorage.GetSettings();}); } void Smtp::AddMailManagerMethods() { static constexpr char SMTP_GET_MAILS_TO_SEND_METHOD_NAME[] = "GetMailsToSend"; static constexpr char SMTP_ADD_MAILS_TO_SEND_METHOD_NAME[] = "AddMailsToSend"; static constexpr char SMTP_DELETE_MAILS_METHOD_NAME[] = "DeleteMailsToSend"; mManagerMailInterface->register_method( SMTP_GET_MAILS_TO_SEND_METHOD_NAME, [this]() { return mMailTo.GetMailToSend();}); mManagerMailInterface->register_method( SMTP_ADD_MAILS_TO_SEND_METHOD_NAME, [this](general::MailsSet const& mails){ return mMailTo.AddMailsToSend(mails);}); mManagerMailInterface->register_method( SMTP_DELETE_MAILS_METHOD_NAME, [this](general::MailsSet const& mails_to_delete){ return mMailTo.DeleteMailToSend(mails_to_delete);}); } }