blob: faa9954cc8868d54e8004db8a6577cd9a006008f [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
Ratan Gupta212f53e2018-04-30 17:28:05 +05308#include <experimental/filesystem>
Ratan Gupta1dc91782018-04-19 16:47:12 +05309#include <string>
10
11namespace phosphor
12{
13namespace network
14{
15namespace snmp
16{
Ratan Gupta212f53e2018-04-30 17:28:05 +053017
Ratan Guptaa7ff3852018-11-16 14:05:57 +053018using ClientList = std::map<Id, std::unique_ptr<Client>>;
Ratan Gupta212f53e2018-04-30 17:28:05 +053019namespace fs = std::experimental::filesystem;
Ratan Gupta1dc91782018-04-19 16:47:12 +053020
21namespace details
22{
23
24using CreateIface = sdbusplus::server::object::object<
25 sdbusplus::xyz::openbmc_project::Network::Client::server::Create>;
26
27} // namespace details
28
29class TestSNMPConfManager;
30/** @class Manager
31 * @brief OpenBMC SNMP config implementation.
32 */
33class 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 Gupta212f53e2018-04-30 17:28:05 +053043 /** @brief Constructor to put object onto bus at a D-Bus path.
Ratan Gupta1dc91782018-04-19 16:47:12 +053044 * @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 Guptad84e3272018-09-06 16:52:52 +053052 * @returns D-Bus object path
Ratan Gupta1dc91782018-04-19 16:47:12 +053053 */
Ratan Guptad84e3272018-09-06 16:52:52 +053054 std::string client(std::string address, uint16_t port) override;
Ratan Gupta1dc91782018-04-19 16:47:12 +053055
Ratan Guptaa7ff3852018-11-16 14:05:57 +053056 /* @brief delete the D-Bus object of the given ID.
57 * @param[in] id - client identifier.
Ratan Gupta1dc91782018-04-19 16:47:12 +053058 */
Ratan Guptaa7ff3852018-11-16 14:05:57 +053059 void deleteSNMPClient(Id id);
Ratan Gupta1dc91782018-04-19 16:47:12 +053060
Ratan Gupta212f53e2018-04-30 17:28:05 +053061 /** @brief Construct manager/client D-Bus objects from their persisted
62 * representations.
63 */
64 void restoreClients();
65
Ratan Gupta9c4fed62018-11-16 17:47:54 +053066 /** @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 Gupta212f53e2018-04-30 17:28:05 +053075 /** @brief location of the persisted D-Bus object.*/
76 fs::path dbusPersistentLocation;
77
Ratan Gupta1dc91782018-04-19 16:47:12 +053078 private:
79 /** @brief sdbusplus DBus bus object. */
80 sdbusplus::bus::bus& bus;
81
82 /** @brief Path of Object. */
83 std::string objectPath;
84
Ratan Guptaa7ff3852018-11-16 14:05:57 +053085 /** @brief map of SNMP Client dbus objects and their ID */
Ratan Gupta1dc91782018-04-19 16:47:12 +053086 ClientList clients;
87
Ratan Guptaa7ff3852018-11-16 14:05:57 +053088 /** @brief Id of the last SNMP manager entry */
89 Id lastClientId = 0;
90
Ratan Gupta1dc91782018-04-19 16:47:12 +053091 friend class TestSNMPConfManager;
92};
93
94} // namespace snmp
95} // namespace network
96} // namespace phosphor