1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ------------------------------------------- */
15 #ifndef __IFACE_Q_DEFINED_
16 #define __IFACE_Q_DEFINED_
19 //#include "xmlparse.h"
29 // Represent an interface.
33 std::map<std::string, std::vector<std::string> > vals;
39 void add_property(const char *name, const char *att);
40 void add_property(const char *name, const char **atts);
41 void add_property(const char *name, std::vector<std::string> &val_vec);
43 std::vector<std::string> get_property(std::string p){
44 std::vector<std::string> ret;
46 /* convert property name to lcase */
47 std::transform(p.begin(), p.end(), p.begin(), (int(*)(int))std::tolower);
50 printf("get_property %s :\n",p.c_str());
51 std::map<std::string, std::vector<std::string> >::iterator msvsi;
52 for(msvsi=vals.begin(); msvsi!=vals.end();++msvsi){
53 printf("\t%s : ",(*msvsi).first.c_str());
54 std::vector<std::string> vs = (*msvsi).second;
56 for(i=0;i<vs.size();++i){
57 printf(" %s",vs[i].c_str());
62 if(vals.count(p)) return vals[p];
66 std::vector<std::string> get_properties(){
67 std::vector<std::string> ret;
69 std::map<std::string, std::vector<std::string> >::iterator iter;
70 for (iter = vals.begin(); iter != vals.end(); iter++) {
71 ret.push_back((*iter).first);
76 int finalize(std::string &errs);
77 std::string to_string();
78 std::string get_name();
79 std::string get_host();
80 bool eval_Contains(std::string prop, std::string val);
81 bool eval_Equals(std::string prop, std::string val);
82 bool eval_Exists(std::string prop);
85 // Represent an interface.
89 std::map<std::string, std::vector<std::string> > vals;
95 void add_property(const char *name, const char *att);
96 void add_property(const char *name, std::vector<std::string> &val_vec);
97 std::vector<std::string> get_property(std::string p){
98 std::vector<std::string> ret;
99 if(vals.count(p)) return vals[p];
102 int finalize(std::string &errs);
104 void add_interface(iface_t* it) {ifaces.push_back(it);}
106 void propagate_name() {
107 for(int i=0;i<ifaces.size();i++)
108 ifaces[i]->add_property("host", vals["name"]);
111 std::string to_string();
112 std::string get_name();
114 std::vector<iface_t *> ifaces;
119 // A collection of resources (interfaces)
123 std::vector<std::string> level;
124 bool in_Resources, in_Iface, in_Host;
126 gs_host_t *curr_host;
128 std::vector<iface_t *> ifaces;
129 std::vector<gs_host_t *> hosts;
130 bool use_live_hosts_file;
131 std::set<std::string> *live_hosts;
132 bool distributed_mode;
134 // XML_Parser parser;
136 // resparse_data(XML_Parser p){
138 resparse_data(bool use_live_hosts_file, std::set<std::string> *live_hosts, bool distributed_mode){
139 in_Resources = false;
143 this->use_live_hosts_file = use_live_hosts_file;
144 this->live_hosts = live_hosts;
145 this->distributed_mode = distributed_mode;
148 void new_iface(int l){
149 curr_iface = new iface_t(l);
151 void new_host(int l){
152 curr_host = new gs_host_t(l);
154 void add_property(const char *name, const char *att){
155 curr_iface->add_property(name, att);
157 void add_property(const char *name, const char **atts){
158 curr_iface->add_property(name, atts);
160 void add_property(const char *name, std::vector<std::string> &val_vec){
161 curr_iface->add_property(name, val_vec);
165 std::vector<std::string> get_property(int i, std::string property){
166 return ifaces[i]->get_property(property);
168 std::vector<std::string> get_properties(int i){
169 return ifaces[i]->get_properties();
172 int finalize_iface(std::string &errs);
173 int finalize_host(std::string &errs);
174 bool failed(){return failure;};
175 std::string to_string();
176 std::vector<std::pair<std::string,std::string> > find_ifaces(predicate_t *pr);
177 std::vector<int> get_ifaces_by_Name(std::string host_name, std::string if_name);
179 bool eval_pred(int i, predicate_t *pr);
186 std::map<std::string, predicate_t *> ifq_map;
188 ifq_t(){ rpd = NULL;};
190 int load_ifaces(std::string fname, bool use_live_hosts_file, bool distributed_mode, std::string &err);
191 int load_ifqs(std::string fname, std::string &err);
193 std::vector<std::pair<std::string,std::string> > eval(std::string qname, int &errnbr);
194 std::vector<std::string> get_iface_vals(std::string host_name, std::string if_name, std::string property, int &errnbr, std::string &err_str);
195 std::vector<std::string> get_iface_properties(std::string host_name, std::string basic_if_name, int &err_no, std::string &err_str);
199 /////////////////////////
200 // for resource parser
202 void startElement(void *userData, const char *name, std::vector<std::string> &attr_vec, std::vector<std::string> &val_vec);
203 void endElement(void *userData, const char *name) ;