xref: /openbmc/phosphor-snmp/snmp_client.hpp (revision ed2ee733)
1 #pragma once
2 #include "xyz/openbmc_project/Network/Client/server.hpp"
3 #include "xyz/openbmc_project/Object/Delete/server.hpp"
4 
5 #include <sdbusplus/bus.hpp>
6 #include <sdbusplus/server/object.hpp>
7 
8 #include <filesystem>
9 #include <string>
10 
11 namespace phosphor
12 {
13 namespace network
14 {
15 namespace snmp
16 {
17 
18 class ConfManager;
19 
20 using Ifaces = sdbusplus::server::object::object<
21     sdbusplus::xyz::openbmc_project::Network::server::Client,
22     sdbusplus::xyz::openbmc_project::Object::server::Delete>;
23 
24 using Id = size_t;
25 
26 /** @class Client
27  *  @brief represents the snmp client configuration
28  *  @details A concrete implementation for the
29  *  xyz.openbmc_project.Network.Client Dbus interface.
30  */
31 class Client : public Ifaces
32 {
33   public:
34     Client() = delete;
35     Client(const Client&) = delete;
36     Client& operator=(const Client&) = delete;
37     Client(Client&&) = delete;
38     Client& operator=(Client&&) = delete;
39     virtual ~Client() = default;
40 
41     /** @brief Constructor to put object onto bus at a dbus path.
42      *  @param[in] bus - Bus to attach to.
43      *  @param[in] objPath - Path to attach at.
44      *  @param[in] parent - Parent D-bus Object.
45      *  @param[in] address - IPaddress/Hostname.
46      *  @param[in] port - network port.
47      */
48     Client(sdbusplus::bus::bus& bus, const char* objPath, ConfManager& parent,
49            const std::string& address, uint16_t port);
50 
51     /** @brief Constructor to put object onto bus at a dbus path.
52      *  @param[in] bus - Bus to attach to.
53      *  @param[in] objPath - Path to attach at.
54      *  @param[in] parent - Parent D-bus Object.
55      */
56     Client(sdbusplus::bus::bus& bus, const char* objPath, ConfManager& parent) :
57         Ifaces(bus, objPath, Ifaces::action::defer_emit),
58         id(std::stol(std::filesystem::path(objPath).filename())), parent(parent)
59     {}
60 
61     /** @brief Update the address of the object.
62      *
63      *  @param[in] value - IP address
64      *
65      *  @return On success the updated IP address
66      */
67     std::string address(std::string value) override;
68 
69     /** @brief Update the port
70      *
71      *  @param[in] value - port number
72      *
73      *  @return On success the updated port number
74      */
75     uint16_t port(uint16_t value) override;
76 
77     using sdbusplus::xyz::openbmc_project::Network::server::Client::address;
78 
79     using sdbusplus::xyz::openbmc_project::Network::server::Client::port;
80 
81     /** @brief Delete this d-bus object.
82      */
83     void delete_() override;
84 
85   private:
86     /** Client ID. */
87     Id id;
88     /** @brief Parent D-Bus Object. */
89     ConfManager& parent;
90 };
91 
92 } // namespace snmp
93 } // namespace network
94 } // namespace phosphor
95