blob: 3f6a405289bb052c1600889d451f985dfe69cd15 [file] [log] [blame]
Ratan Gupta1dc91782018-04-19 16:47:12 +05301#include "snmp_client.hpp"
Patrick Williams1334b7b2021-02-22 17:15:12 -06002
Ratan Gupta1dc91782018-04-19 16:47:12 +05303#include "snmp_conf_manager.hpp"
Ratan Gupta9d18e562018-11-16 17:19:34 +05304#include "snmp_serialize.hpp"
Ratan Gupta1dc91782018-04-19 16:47:12 +05305
6namespace phosphor
7{
8namespace network
9{
10namespace snmp
11{
12
13Client::Client(sdbusplus::bus::bus& bus, const char* objPath,
14 ConfManager& parent, const std::string& address, uint16_t port) :
15 Ifaces(bus, objPath, true),
Ratan Guptaa7ff3852018-11-16 14:05:57 +053016 id(std::stol(std::experimental::filesystem::path(objPath).filename())),
Ratan Gupta1dc91782018-04-19 16:47:12 +053017 parent(parent)
18{
19 this->address(address);
20 this->port(port);
21
22 // Emit deferred signal.
23 emit_object_added();
24}
25
Ratan Gupta9d18e562018-11-16 17:19:34 +053026std::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
40uint16_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
Ratan Gupta1dc91782018-04-19 16:47:12 +053054void Client::delete_()
55{
Ratan Guptaa7ff3852018-11-16 14:05:57 +053056 parent.deleteSNMPClient(id);
Ratan Gupta1dc91782018-04-19 16:47:12 +053057}
58
59} // namespace snmp
60} // namespace network
61} // namespace phosphor