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