1 #pragma once 2 3 #include "snmp_client.hpp" 4 5 #include <sdbusplus/bus.hpp> 6 #include <xyz/openbmc_project/Network/Client/Create/server.hpp> 7 8 #include <string> 9 10 namespace phosphor 11 { 12 namespace network 13 { 14 namespace snmp 15 { 16 17 using ClientList = std::map<Id, std::unique_ptr<Client>>; 18 namespace fs = std::filesystem; 19 20 namespace details 21 { 22 23 using CreateIface = sdbusplus::server::object::object< 24 sdbusplus::xyz::openbmc_project::Network::Client::server::Create>; 25 26 } // namespace details 27 28 class TestSNMPConfManager; 29 /** @class Manager 30 * @brief OpenBMC SNMP config implementation. 31 */ 32 class ConfManager : public details::CreateIface 33 { 34 public: 35 ConfManager() = delete; 36 ConfManager(const ConfManager&) = delete; 37 ConfManager& operator=(const ConfManager&) = delete; 38 ConfManager(ConfManager&&) = delete; 39 ConfManager& operator=(ConfManager&&) = delete; 40 virtual ~ConfManager() = default; 41 42 /** @brief Constructor to put object onto bus at a D-Bus path. 43 * @param[in] bus - Bus to attach to. 44 * @param[in] objPath - Path to attach at. 45 */ 46 ConfManager(sdbusplus::bus::bus& bus, const char* objPath); 47 48 /** @brief Function to create snmp manager details D-Bus object. 49 * @param[in] address- IP address/Hostname. 50 * @param[in] port - network port. 51 * @returns D-Bus object path 52 */ 53 std::string client(std::string address, uint16_t port) override; 54 55 /* @brief delete the D-Bus object of the given ID. 56 * @param[in] id - client identifier. 57 */ 58 void deleteSNMPClient(Id id); 59 60 /** @brief Construct manager/client D-Bus objects from their persisted 61 * representations. 62 */ 63 void restoreClients(); 64 65 /** @brief Check if client is already configured or not. 66 * 67 * @param[in] address - SNMP manager address. 68 * @param[in] port - SNMP manager port. 69 * 70 * @return throw exception if client is already configured. 71 */ 72 void checkClientConfigured(const std::string& address, uint16_t port); 73 74 /** @brief location of the persisted D-Bus object.*/ 75 fs::path dbusPersistentLocation; 76 77 private: 78 /** @brief sdbusplus DBus bus object. */ 79 sdbusplus::bus::bus& bus; 80 81 /** @brief Path of Object. */ 82 std::string objectPath; 83 84 /** @brief map of SNMP Client dbus objects and their ID */ 85 ClientList clients; 86 87 /** @brief Id of the last SNMP manager entry */ 88 Id lastClientId = 0; 89 90 friend class TestSNMPConfManager; 91 }; 92 93 } // namespace snmp 94 } // namespace network 95 } // namespace phosphor 96