Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef __DB_IFMAP_AGENT_PARSER_H__ 6 : #define __DB_IFMAP_AGENT_PARSER_H__ 7 : 8 : #include <list> 9 : #include <map> 10 : #include <boost/function.hpp> 11 : #include "db/db.h" 12 : #include "ifmap/ifmap_object.h" 13 : #include "ifmap/ifmap_table.h" 14 : 15 : namespace pugi { 16 : class xml_document; 17 : class xml_node; 18 : } // namespace pugi 19 : 20 : class IFMapAgentParser { 21 : public: 22 : 23 : enum ConfigMsgType { 24 : UPDATE, 25 : DEL, 26 : MAX 27 : }; 28 : 29 17 : IFMapAgentParser(DB *db) : db_(db) { reset_statistics(); } ; 30 : 31 : typedef boost::function< IFMapObject *(const pugi::xml_node, DB *, 32 : std::string *id_name) > NodeParseFn; 33 : typedef std::map<std::string, NodeParseFn> NodeParseMap; 34 : void NodeRegister(const std::string &node, NodeParseFn parser); 35 : void NodeClear(); 36 : void ConfigParse(const pugi::xml_node config, uint64_t seq); 37 0 : uint64_t node_updates() { return nodes_processed_[UPDATE]; } 38 0 : uint64_t node_deletes() { return nodes_processed_[DEL]; } 39 0 : uint64_t link_updates() { return links_processed_[UPDATE]; } 40 0 : uint64_t link_deletes() { return links_processed_[DEL]; } 41 0 : uint64_t node_update_parse_errors() { return node_parse_errors_[UPDATE]; } 42 0 : uint64_t node_delete_parse_errors() { return node_parse_errors_[DEL]; } 43 0 : uint64_t link_update_parse_errors() { return link_parse_errors_[UPDATE]; } 44 0 : uint64_t link_delete_parse_errors() { return link_parse_errors_[DEL]; } 45 18 : void reset_statistics() { 46 18 : nodes_processed_[UPDATE] = 0; 47 18 : nodes_processed_[DEL] = 0; 48 18 : links_processed_[UPDATE] = 0; 49 18 : links_processed_[DEL] = 0; 50 18 : node_parse_errors_[UPDATE] = 0; 51 18 : node_parse_errors_[DEL] = 0; 52 18 : link_parse_errors_[UPDATE] = 0; 53 18 : link_parse_errors_[DEL] = 0; 54 18 : } 55 : private: 56 : DB *db_; 57 : NodeParseMap node_map_; 58 : uint64_t nodes_processed_[MAX]; 59 : uint64_t links_processed_[MAX]; 60 : uint64_t node_parse_errors_[MAX]; 61 : uint64_t link_parse_errors_[MAX]; 62 : void NodeParse(pugi::xml_node &node, DBRequest::DBOperation oper, uint64_t seq); 63 : void LinkParse(pugi::xml_node &node, DBRequest::DBOperation oper, uint64_t seq); 64 : }; 65 : 66 : #endif