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 | |
| 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), |
Ratan Gupta | a7ff385 | 2018-11-16 14:05:57 +0530 | [diff] [blame] | 16 | id(std::stol(std::experimental::filesystem::path(objPath).filename())), |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 17 | parent(parent) |
| 18 | { |
| 19 | this->address(address); |
| 20 | this->port(port); |
| 21 | |
| 22 | // Emit deferred signal. |
| 23 | emit_object_added(); |
| 24 | } |
| 25 | |
Ratan Gupta | 9d18e56 | 2018-11-16 17:19:34 +0530 | [diff] [blame] | 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 | |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 54 | void Client::delete_() |
| 55 | { |
Ratan Gupta | a7ff385 | 2018-11-16 14:05:57 +0530 | [diff] [blame] | 56 | parent.deleteSNMPClient(id); |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | } // namespace snmp |
| 60 | } // namespace network |
| 61 | } // namespace phosphor |