/* * ip_table.h * * Created on: 2022年3月10日 * Author: pengzc */ #ifndef JNI_CORE_IP_TABLE_H_ #define JNI_CORE_IP_TABLE_H_ #include #include namespace i { struct NetworkProfile { std::string name; std::string code; std::string ipv4; std::string gateway; std::string sub_network_mask; int building; int unit; int number; int extension; public: NetworkProfile() { building = 0; unit = 0; number = 0; extension = 0; } std::string ToString() const { return base::format("%s %s %s %s %s", name.c_str(), code.c_str(), ipv4.c_str(), gateway.c_str(), sub_network_mask.c_str()); } std::string ToAddressString() const { return base::format("%d栋%d单元%04d室%d分机", building, unit, number, extension); } bool ParseAddressString(const std::string& str) { return 4 == sscanf(str.c_str(), "%d栋%d单元%d室%d分机", &building, &unit, &number, &extension); } }; class IpTable { public: virtual ~IpTable(); /** * 更新IP表 * @param map_xml * @return */ static int Update(const std::string& map_xml); /** * 加载IP表 * @param map_xml * @return */ static int Load(std::string* map_xml); /** * 从IP表中查找指定分机的网络配置 * * @param building 栋 * @param unit 单元 * @param number 室 * @param extension 分机号 * @param profile 对应的网络配置 * @return success 0 */ static int GetExtension(int building, int unit, int number, int extension, NetworkProfile* profile); /** * 从IP表中查找指定门口机的网络配置 * @param building 栋 * @param unit 单元 * @return success 0 */ static int GetGate(int building, int unit, NetworkProfile* profile); static std::string GetVersion(); private: IpTable(); }; } /* namespace i */ #endif /* JNI_CORE_IP_TABLE_H_ */