xref: /openbmc/phosphor-snmp/snmp_client.cpp (revision 8de81777)
1 #include "snmp_client.hpp"
2 
3 #include "snmp_conf_manager.hpp"
4 #include "snmp_serialize.hpp"
5 
6 namespace phosphor
7 {
8 namespace network
9 {
10 namespace snmp
11 {
12 
13 Client::Client(sdbusplus::bus_t& bus, const char* objPath, ConfManager& parent,
14                const std::string& address, uint16_t port) :
15     Ifaces(bus, objPath, Ifaces::action::defer_emit),
16     id(std::stol(std::filesystem::path(objPath).filename())), parent(parent)
17 {
18     this->address(address);
19     this->port(port);
20     this->transportProtocol(sdbusplus::server::xyz::openbmc_project::network::
21                                 Client::TransportProtocol::UDP);
22 
23     // Emit deferred signal.
24     emit_object_added();
25 }
26 
27 std::string Client::address(std::string value)
28 {
29     if (value == Ifaces::address())
30     {
31         return value;
32     }
33 
34     parent.checkClientConfigured(value, port());
35 
36     auto addr = Ifaces::address(value);
37     serialize(id, *this, parent.dbusPersistentLocation);
38     return addr;
39 }
40 
41 uint16_t Client::port(uint16_t value)
42 {
43     if (value == Ifaces::port())
44     {
45         return value;
46     }
47 
48     parent.checkClientConfigured(address(), value);
49 
50     auto port = Ifaces::port(value);
51     serialize(id, *this, parent.dbusPersistentLocation);
52     return port;
53 }
54 
55 void Client::delete_()
56 {
57     parent.deleteSNMPClient(id);
58 }
59 
60 } // namespace snmp
61 } // namespace network
62 } // namespace phosphor
63