Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "snmp_client.hpp" |
| 4 | |
| 5 | #include <xyz/openbmc_project/Network/Client/Create/server.hpp> |
| 6 | #include <sdbusplus/bus.hpp> |
| 7 | |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 8 | #include <experimental/filesystem> |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 9 | #include <string> |
| 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace network |
| 14 | { |
| 15 | namespace snmp |
| 16 | { |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 17 | |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 18 | using IPAddress = std::string; |
| 19 | using ClientList = std::map<IPAddress, std::unique_ptr<Client>>; |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 20 | namespace fs = std::experimental::filesystem; |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 21 | |
| 22 | namespace details |
| 23 | { |
| 24 | |
| 25 | using CreateIface = sdbusplus::server::object::object< |
| 26 | sdbusplus::xyz::openbmc_project::Network::Client::server::Create>; |
| 27 | |
| 28 | } // namespace details |
| 29 | |
| 30 | class TestSNMPConfManager; |
| 31 | /** @class Manager |
| 32 | * @brief OpenBMC SNMP config implementation. |
| 33 | */ |
| 34 | class ConfManager : public details::CreateIface |
| 35 | { |
| 36 | public: |
| 37 | ConfManager() = delete; |
| 38 | ConfManager(const ConfManager&) = delete; |
| 39 | ConfManager& operator=(const ConfManager&) = delete; |
| 40 | ConfManager(ConfManager&&) = delete; |
| 41 | ConfManager& operator=(ConfManager&&) = delete; |
| 42 | virtual ~ConfManager() = default; |
| 43 | |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 44 | /** @brief Constructor to put object onto bus at a D-Bus path. |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 45 | * @param[in] bus - Bus to attach to. |
| 46 | * @param[in] objPath - Path to attach at. |
| 47 | */ |
| 48 | ConfManager(sdbusplus::bus::bus& bus, const char* objPath); |
| 49 | |
| 50 | /** @brief Function to create snmp manager details D-Bus object. |
| 51 | * @param[in] address- IP address/Hostname. |
| 52 | * @param[in] port - network port. |
| 53 | */ |
| 54 | void client(std::string address, uint16_t port) override; |
| 55 | |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 56 | /* @brief delete the D-Bus object of the given ipaddress. |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 57 | * @param[in] address - IP address/Hostname. |
| 58 | */ |
| 59 | void deleteSNMPClient(const std::string& address); |
| 60 | |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 61 | /** @brief Construct manager/client D-Bus objects from their persisted |
| 62 | * representations. |
| 63 | */ |
| 64 | void restoreClients(); |
| 65 | |
| 66 | /** @brief location of the persisted D-Bus object.*/ |
| 67 | fs::path dbusPersistentLocation; |
| 68 | |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 69 | protected: |
| 70 | /** @brief generates the id by doing hash of ipaddress, port |
| 71 | * @param[in] address - IP address/Hostname. |
| 72 | * @param[in] port - network port. |
| 73 | * @return hash string. |
| 74 | */ |
| 75 | static std::string generateId(const std::string& address, uint16_t port); |
| 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 IPAddress dbus objects and their names */ |
| 85 | ClientList clients; |
| 86 | |
| 87 | friend class TestSNMPConfManager; |
| 88 | }; |
| 89 | |
| 90 | } // namespace snmp |
| 91 | } // namespace network |
| 92 | } // namespace phosphor |