blob: f477b315a6e97348261fcf20f1c8ba732b83d6ac [file] [log] [blame]
Ratan Gupta1dc91782018-04-19 16:47:12 +05301#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 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
66 /** @brief location of the persisted D-Bus object.*/
67 fs::path dbusPersistentLocation;
68
Ratan Gupta1dc91782018-04-19 16:47:12 +053069 private:
70 /** @brief sdbusplus DBus bus object. */
71 sdbusplus::bus::bus& bus;
72
73 /** @brief Path of Object. */
74 std::string objectPath;
75
Ratan Guptaa7ff3852018-11-16 14:05:57 +053076 /** @brief map of SNMP Client dbus objects and their ID */
Ratan Gupta1dc91782018-04-19 16:47:12 +053077 ClientList clients;
78
Ratan Guptaa7ff3852018-11-16 14:05:57 +053079 /** @brief Id of the last SNMP manager entry */
80 Id lastClientId = 0;
81
Ratan Gupta1dc91782018-04-19 16:47:12 +053082 friend class TestSNMPConfManager;
83};
84
85} // namespace snmp
86} // namespace network
87} // namespace phosphor