blob: fc16a343fa9fc43511dfa8488098e0611fbb7a55 [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
Patrick Williams87d3edd2022-07-22 19:26:53 -050013Client::Client(sdbusplus::bus_t& bus, const char* objPath, ConfManager& parent,
14 const std::string& address, uint16_t port) :
Patrick Williamsb9b4c7d2022-04-05 16:20:37 -050015 Ifaces(bus, objPath, Ifaces::action::defer_emit),
Ratan Gupta34d129a2021-12-04 21:04:51 +053016 id(std::stol(std::filesystem::path(objPath).filename())), parent(parent)
Ratan Gupta1dc91782018-04-19 16:47:12 +053017{
18 this->address(address);
19 this->port(port);
Ivan Mikhaylov40f769b2023-06-20 19:18:56 +030020 this->transportProtocol(sdbusplus::server::xyz::openbmc_project::network::
21 Client::TransportProtocol::UDP);
Ratan Gupta1dc91782018-04-19 16:47:12 +053022
23 // Emit deferred signal.
24 emit_object_added();
25}
26
Ratan Gupta9d18e562018-11-16 17:19:34 +053027std::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
41uint16_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
Ratan Gupta1dc91782018-04-19 16:47:12 +053055void Client::delete_()
56{
Ratan Guptaa7ff3852018-11-16 14:05:57 +053057 parent.deleteSNMPClient(id);
Ratan Gupta1dc91782018-04-19 16:47:12 +053058}
59
60} // namespace snmp
61} // namespace network
62} // namespace phosphor