Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 1 | #include "snmp_client.hpp" |
Patrick Williams | 1334b7b | 2021-02-22 17:15:12 -0600 | [diff] [blame] | 2 | |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 3 | #include "snmp_conf_manager.hpp" |
Ratan Gupta | 9d18e56 | 2018-11-16 17:19:34 +0530 | [diff] [blame] | 4 | #include "snmp_serialize.hpp" |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace network |
| 9 | { |
| 10 | namespace snmp |
| 11 | { |
| 12 | |
Patrick Williams | 87d3edd | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 13 | Client::Client(sdbusplus::bus_t& bus, const char* objPath, ConfManager& parent, |
| 14 | const std::string& address, uint16_t port) : |
Patrick Williams | b9b4c7d | 2022-04-05 16:20:37 -0500 | [diff] [blame] | 15 | Ifaces(bus, objPath, Ifaces::action::defer_emit), |
Ratan Gupta | 34d129a | 2021-12-04 21:04:51 +0530 | [diff] [blame] | 16 | id(std::stol(std::filesystem::path(objPath).filename())), parent(parent) |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 17 | { |
| 18 | this->address(address); |
| 19 | this->port(port); |
| 20 | |
| 21 | // Emit deferred signal. |
| 22 | emit_object_added(); |
| 23 | } |
| 24 | |
Ratan Gupta | 9d18e56 | 2018-11-16 17:19:34 +0530 | [diff] [blame] | 25 | std::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 | |
| 39 | uint16_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 Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 53 | void Client::delete_() |
| 54 | { |
Ratan Gupta | a7ff385 | 2018-11-16 14:05:57 +0530 | [diff] [blame] | 55 | parent.deleteSNMPClient(id); |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | } // namespace snmp |
| 59 | } // namespace network |
| 60 | } // namespace phosphor |