blob: 52eb7441ba755790503c8eee92c05bba7130d210 [file] [log] [blame]
Ratan Gupta1dc91782018-04-19 16:47:12 +05301#include "snmp_client.hpp"
2#include "snmp_conf_manager.hpp"
Ratan Gupta9d18e562018-11-16 17:19:34 +05303#include "snmp_serialize.hpp"
Ratan Gupta1dc91782018-04-19 16:47:12 +05304
5namespace phosphor
6{
7namespace network
8{
9namespace snmp
10{
11
12Client::Client(sdbusplus::bus::bus& bus, const char* objPath,
13 ConfManager& parent, const std::string& address, uint16_t port) :
14 Ifaces(bus, objPath, true),
Ratan Guptaa7ff3852018-11-16 14:05:57 +053015 id(std::stol(std::experimental::filesystem::path(objPath).filename())),
Ratan Gupta1dc91782018-04-19 16:47:12 +053016 parent(parent)
17{
18 this->address(address);
19 this->port(port);
20
21 // Emit deferred signal.
22 emit_object_added();
23}
24
Ratan Gupta9d18e562018-11-16 17:19:34 +053025std::string Client::address(std::string value)
26{
27 if (value == Ifaces::address())
28 {
29 return value;
30 }
31
32 parent.checkClientConfigured(value, port());
33
34 auto addr = Ifaces::address(value);
35 serialize(id, *this, parent.dbusPersistentLocation);
36 return addr;
37}
38
39uint16_t Client::port(uint16_t value)
40{
41 if (value == Ifaces::port())
42 {
43 return value;
44 }
45
46 parent.checkClientConfigured(address(), value);
47
48 auto port = Ifaces::port(value);
49 serialize(id, *this, parent.dbusPersistentLocation);
50 return port;
51}
52
Ratan Gupta1dc91782018-04-19 16:47:12 +053053void Client::delete_()
54{
Ratan Guptaa7ff3852018-11-16 14:05:57 +053055 parent.deleteSNMPClient(id);
Ratan Gupta1dc91782018-04-19 16:47:12 +053056}
57
58} // namespace snmp
59} // namespace network
60} // namespace phosphor