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 | |
| 8 | #include <string> |
| 9 | |
| 10 | namespace phosphor |
| 11 | { |
| 12 | namespace network |
| 13 | { |
| 14 | namespace snmp |
| 15 | { |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 16 | |
Ratan Gupta | a7ff385 | 2018-11-16 14:05:57 +0530 | [diff] [blame] | 17 | using ClientList = std::map<Id, std::unique_ptr<Client>>; |
Ratan Gupta | 34d129a | 2021-12-04 21:04:51 +0530 | [diff] [blame] | 18 | namespace fs = std::filesystem; |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 19 | |
| 20 | namespace details |
| 21 | { |
| 22 | |
Patrick Williams | 87d3edd | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 23 | using CreateIface = sdbusplus::server::object_t< |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 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 | |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 42 | /** @brief Constructor to put object onto bus at a D-Bus path. |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 43 | * @param[in] bus - Bus to attach to. |
| 44 | * @param[in] objPath - Path to attach at. |
| 45 | */ |
Patrick Williams | 87d3edd | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 46 | ConfManager(sdbusplus::bus_t& bus, const char* objPath); |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 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. |
Ratan Gupta | d84e327 | 2018-09-06 16:52:52 +0530 | [diff] [blame] | 51 | * @returns D-Bus object path |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 52 | */ |
Ratan Gupta | d84e327 | 2018-09-06 16:52:52 +0530 | [diff] [blame] | 53 | std::string client(std::string address, uint16_t port) override; |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 54 | |
Ratan Gupta | a7ff385 | 2018-11-16 14:05:57 +0530 | [diff] [blame] | 55 | /* @brief delete the D-Bus object of the given ID. |
| 56 | * @param[in] id - client identifier. |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 57 | */ |
Ratan Gupta | a7ff385 | 2018-11-16 14:05:57 +0530 | [diff] [blame] | 58 | void deleteSNMPClient(Id id); |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 59 | |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 60 | /** @brief Construct manager/client D-Bus objects from their persisted |
| 61 | * representations. |
| 62 | */ |
| 63 | void restoreClients(); |
| 64 | |
Ratan Gupta | 9c4fed6 | 2018-11-16 17:47:54 +0530 | [diff] [blame] | 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 | |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 74 | /** @brief location of the persisted D-Bus object.*/ |
| 75 | fs::path dbusPersistentLocation; |
| 76 | |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 77 | private: |
| 78 | /** @brief sdbusplus DBus bus object. */ |
Patrick Williams | 87d3edd | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 79 | sdbusplus::bus_t& bus; |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 80 | |
| 81 | /** @brief Path of Object. */ |
| 82 | std::string objectPath; |
| 83 | |
Ratan Gupta | a7ff385 | 2018-11-16 14:05:57 +0530 | [diff] [blame] | 84 | /** @brief map of SNMP Client dbus objects and their ID */ |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 85 | ClientList clients; |
| 86 | |
Ratan Gupta | a7ff385 | 2018-11-16 14:05:57 +0530 | [diff] [blame] | 87 | /** @brief Id of the last SNMP manager entry */ |
| 88 | Id lastClientId = 0; |
| 89 | |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 90 | friend class TestSNMPConfManager; |
| 91 | }; |
| 92 | |
| 93 | } // namespace snmp |
| 94 | } // namespace network |
| 95 | } // namespace phosphor |