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.
30 // TODO Add in some more consistency checks, beyond having an interface name
31 // TODO More intelligence about interfaces, e.g. the libraries to
36 std::map<std::string, std::vector<std::string> > vals;
42 void add_property(const char *name, const char *att);
43 void add_property(const char *name, const char **atts);
44 void add_property(const char *name, std::vector<std::string> &val_vec);
46 std::vector<std::string> get_property(std::string p){
47 std::vector<std::string> ret;
49 /* convert property name to lcase */
50 std::transform(p.begin(), p.end(), p.begin(), (int(*)(int))std::tolower);
53 printf("get_property %s :\n",p.c_str());
54 std::map<std::string, std::vector<std::string> >::iterator msvsi;
55 for(msvsi=vals.begin(); msvsi!=vals.end();++msvsi){
56 printf("\t%s : ",(*msvsi).first.c_str());
57 std::vector<std::string> vs = (*msvsi).second;
59 for(i=0;i<vs.size();++i){
60 printf(" %s",vs[i].c_str());
65 if(vals.count(p)) return vals[p];
69 std::vector<std::string> get_properties(){
70 std::vector<std::string> ret;
72 std::map<std::string, std::vector<std::string> >::iterator iter;
73 for (iter = vals.begin(); iter != vals.end(); iter++) {
74 ret.push_back((*iter).first);
79 // Add in more consistency checks
80 int finalize(std::string &errs);
82 std::string to_string();
83 std::string get_name();
84 std::string get_host();
85 bool has_multiple_schemas(); // depends on InterfaceType
88 bool eval_Contains(std::string prop, std::string val);
89 bool eval_Equals(std::string prop, std::string val);
90 bool eval_Exists(std::string prop);
93 // Represent an interface.
97 std::map<std::string, std::vector<std::string> > vals;
103 void add_property(const char *name, const char *att);
104 void add_property(const char *name, std::vector<std::string> &val_vec);
105 std::vector<std::string> get_property(std::string p){
106 std::vector<std::string> ret;
107 if(vals.count(p)) return vals[p];
110 int finalize(std::string &errs);
112 void add_interface(iface_t* it) {ifaces.push_back(it);}
114 void propagate_name() {
115 for(int i=0;i<ifaces.size();i++)
116 ifaces[i]->add_property("host", vals["name"]);
119 std::string to_string();
120 std::string get_name();
122 std::vector<iface_t *> ifaces;
127 // A collection of resources (interfaces)
131 std::vector<std::string> level;
132 bool in_Resources, in_Iface, in_Host;
134 gs_host_t *curr_host;
136 std::vector<iface_t *> ifaces;
137 std::vector<gs_host_t *> hosts;
138 bool use_live_hosts_file;
139 std::set<std::string> *live_hosts;
140 bool distributed_mode;
142 // XML_Parser parser;
144 // resparse_data(XML_Parser p){
146 resparse_data(bool use_live_hosts_file, std::set<std::string> *live_hosts, bool distributed_mode){
147 in_Resources = false;
151 this->use_live_hosts_file = use_live_hosts_file;
152 this->live_hosts = live_hosts;
153 this->distributed_mode = distributed_mode;
156 void new_iface(int l){
157 curr_iface = new iface_t(l);
159 iface_t *get_interface(int l){
164 void new_host(int l){
165 curr_host = new gs_host_t(l);
167 void add_property(const char *name, const char *att){
168 curr_iface->add_property(name, att);
170 void add_property(const char *name, const char **atts){
171 curr_iface->add_property(name, atts);
173 void add_property(const char *name, std::vector<std::string> &val_vec){
174 curr_iface->add_property(name, val_vec);
178 std::vector<std::string> get_property(int i, std::string property){
179 return ifaces[i]->get_property(property);
181 std::vector<std::string> get_properties(int i){
182 return ifaces[i]->get_properties();
185 int finalize_iface(std::string &errs);
186 int finalize_host(std::string &errs);
187 bool failed(){return failure;};
188 std::string to_string();
189 std::vector<std::pair<std::string,std::string> > find_ifaces(predicate_t *pr);
190 std::vector<int> get_ifaces_by_Name(std::string host_name, std::string if_name);
192 bool eval_pred(int i, predicate_t *pr);
199 std::map<std::string, predicate_t *> ifq_map;
201 ifq_t(){ rpd = NULL;};
203 int load_ifaces(std::string fname, bool use_live_hosts_file, bool distributed_mode, std::string &err);
204 int load_ifqs(std::string fname, std::string &err);
206 std::vector<std::pair<std::string,std::string> > eval(std::string qname, int &errnbr);
207 std::vector<std::string> get_iface_vals(std::string host_name, std::string if_name, std::string property, int &errnbr, std::string &err_str);
208 std::vector<std::string> get_iface_properties(std::string host_name, std::string basic_if_name, int &err_no, std::string &err_str);
209 iface_t *get_interface(std::string host_name, std::string basic_if_name, int &err_no, std::string &err_str);
213 /////////////////////////
214 // for resource parser
216 void startElement(void *userData, const char *name, std::vector<std::string> &attr_vec, std::vector<std::string> &val_vec);
217 void endElement(void *userData, const char *name) ;