blob: d9164ae60efc7b7c6dacb8aea00f027c76235eb2 [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 Gupta1dc91782018-04-19 16:47:12 +053018using IPAddress = std::string;
19using ClientList = std::map<IPAddress, std::unique_ptr<Client>>;
Ratan Gupta212f53e2018-04-30 17:28:05 +053020namespace fs = std::experimental::filesystem;
Ratan Gupta1dc91782018-04-19 16:47:12 +053021
22namespace details
23{
24
25using CreateIface = sdbusplus::server::object::object<
26 sdbusplus::xyz::openbmc_project::Network::Client::server::Create>;
27
28} // namespace details
29
30class TestSNMPConfManager;
31/** @class Manager
32 * @brief OpenBMC SNMP config implementation.
33 */
34class ConfManager : public details::CreateIface
35{
36 public:
37 ConfManager() = delete;
38 ConfManager(const ConfManager&) = delete;
39 ConfManager& operator=(const ConfManager&) = delete;
40 ConfManager(ConfManager&&) = delete;
41 ConfManager& operator=(ConfManager&&) = delete;
42 virtual ~ConfManager() = default;
43
Ratan Gupta212f53e2018-04-30 17:28:05 +053044 /** @brief Constructor to put object onto bus at a D-Bus path.
Ratan Gupta1dc91782018-04-19 16:47:12 +053045 * @param[in] bus - Bus to attach to.
46 * @param[in] objPath - Path to attach at.
47 */
48 ConfManager(sdbusplus::bus::bus& bus, const char* objPath);
49
50 /** @brief Function to create snmp manager details D-Bus object.
51 * @param[in] address- IP address/Hostname.
52 * @param[in] port - network port.
53 */
54 void client(std::string address, uint16_t port) override;
55
Ratan Gupta212f53e2018-04-30 17:28:05 +053056 /* @brief delete the D-Bus object of the given ipaddress.
Ratan Gupta1dc91782018-04-19 16:47:12 +053057 * @param[in] address - IP address/Hostname.
58 */
59 void deleteSNMPClient(const std::string& address);
60
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 protected:
70 /** @brief generates the id by doing hash of ipaddress, port
71 * @param[in] address - IP address/Hostname.
72 * @param[in] port - network port.
73 * @return hash string.
74 */
75 static std::string generateId(const std::string& address, uint16_t port);
76
77 private:
78 /** @brief sdbusplus DBus bus object. */
79 sdbusplus::bus::bus& bus;
80
81 /** @brief Path of Object. */
82 std::string objectPath;
83
84 /** @brief map of IPAddress dbus objects and their names */
85 ClientList clients;
86
87 friend class TestSNMPConfManager;
88};
89
90} // namespace snmp
91} // namespace network
92} // namespace phosphor