xref: /openbmc/phosphor-snmp/snmp_client.cpp (revision 1334b7b3)
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::bus& bus, const char* objPath,
14                ConfManager& parent, const std::string& address, uint16_t port) :
15     Ifaces(bus, objPath, true),
16     id(std::stol(std::experimental::filesystem::path(objPath).filename())),
17     parent(parent)
18 {
19     this->address(address);
20     this->port(port);
21 
22     // Emit deferred signal.
23     emit_object_added();
24 }
25 
26 std::string Client::address(std::string value)
27 {
28     if (value == Ifaces::address())
29     {
30         return value;
31     }
32 
33     parent.checkClientConfigured(value, port());
34 
35     auto addr = Ifaces::address(value);
36     serialize(id, *this, parent.dbusPersistentLocation);
37     return addr;
38 }
39 
40 uint16_t Client::port(uint16_t value)
41 {
42     if (value == Ifaces::port())
43     {
44         return value;
45     }
46 
47     parent.checkClientConfigured(address(), value);
48 
49     auto port = Ifaces::port(value);
50     serialize(id, *this, parent.dbusPersistentLocation);
51     return port;
52 }
53 
54 void Client::delete_()
55 {
56     parent.deleteSNMPClient(id);
57 }
58 
59 } // namespace snmp
60 } // namespace network
61 } // namespace phosphor
62