blob: d8823f391affd3b406e68280d97c101646914c9b [file] [log] [blame]
Ratan Gupta1dc91782018-04-19 16:47:12 +05301#pragma once
2
3#include "snmp_client.hpp"
4
Ratan Gupta1dc91782018-04-19 16:47:12 +05305#include <sdbusplus/bus.hpp>
Patrick Williams1334b7b2021-02-22 17:15:12 -06006#include <xyz/openbmc_project/Network/Client/Create/server.hpp>
Ratan Gupta1dc91782018-04-19 16:47:12 +05307
8#include <string>
9
10namespace phosphor
11{
12namespace network
13{
14namespace snmp
15{
Ratan Gupta212f53e2018-04-30 17:28:05 +053016
Ratan Guptaa7ff3852018-11-16 14:05:57 +053017using ClientList = std::map<Id, std::unique_ptr<Client>>;
Ratan Gupta34d129a2021-12-04 21:04:51 +053018namespace fs = std::filesystem;
Ratan Gupta1dc91782018-04-19 16:47:12 +053019
20namespace details
21{
22
Patrick Williams87d3edd2022-07-22 19:26:53 -050023using CreateIface = sdbusplus::server::object_t<
Ratan Gupta1dc91782018-04-19 16:47:12 +053024 sdbusplus::xyz::openbmc_project::Network::Client::server::Create>;
25
26} // namespace details
27
28class TestSNMPConfManager;
29/** @class Manager
30 * @brief OpenBMC SNMP config implementation.
31 */
32class 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 Gupta212f53e2018-04-30 17:28:05 +053042 /** @brief Constructor to put object onto bus at a D-Bus path.
Ratan Gupta1dc91782018-04-19 16:47:12 +053043 * @param[in] bus - Bus to attach to.
44 * @param[in] objPath - Path to attach at.
45 */
Patrick Williams87d3edd2022-07-22 19:26:53 -050046 ConfManager(sdbusplus::bus_t& bus, const char* objPath);
Ratan Gupta1dc91782018-04-19 16:47:12 +053047
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 Guptad84e3272018-09-06 16:52:52 +053051 * @returns D-Bus object path
Ratan Gupta1dc91782018-04-19 16:47:12 +053052 */
Ratan Guptad84e3272018-09-06 16:52:52 +053053 std::string client(std::string address, uint16_t port) override;
Ratan Gupta1dc91782018-04-19 16:47:12 +053054
Ratan Guptaa7ff3852018-11-16 14:05:57 +053055 /* @brief delete the D-Bus object of the given ID.
56 * @param[in] id - client identifier.
Ratan Gupta1dc91782018-04-19 16:47:12 +053057 */
Ratan Guptaa7ff3852018-11-16 14:05:57 +053058 void deleteSNMPClient(Id id);
Ratan Gupta1dc91782018-04-19 16:47:12 +053059
Ratan Gupta212f53e2018-04-30 17:28:05 +053060 /** @brief Construct manager/client D-Bus objects from their persisted
61 * representations.
62 */
63 void restoreClients();
64
Ratan Gupta9c4fed62018-11-16 17:47:54 +053065 /** @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 Gupta212f53e2018-04-30 17:28:05 +053074 /** @brief location of the persisted D-Bus object.*/
75 fs::path dbusPersistentLocation;
76
Ratan Gupta1dc91782018-04-19 16:47:12 +053077 private:
78 /** @brief sdbusplus DBus bus object. */
Patrick Williams87d3edd2022-07-22 19:26:53 -050079 sdbusplus::bus_t& bus;
Ratan Gupta1dc91782018-04-19 16:47:12 +053080
81 /** @brief Path of Object. */
82 std::string objectPath;
83
Ratan Guptaa7ff3852018-11-16 14:05:57 +053084 /** @brief map of SNMP Client dbus objects and their ID */
Ratan Gupta1dc91782018-04-19 16:47:12 +053085 ClientList clients;
86
Ratan Guptaa7ff3852018-11-16 14:05:57 +053087 /** @brief Id of the last SNMP manager entry */
88 Id lastClientId = 0;
89
Ratan Gupta1dc91782018-04-19 16:47:12 +053090 friend class TestSNMPConfManager;
91};
92
93} // namespace snmp
94} // namespace network
95} // namespace phosphor