#ifndef DEVD_HH
#define DEVD_HH
class config;
class var_list
{
public:
void set_variable(const std::string &var, const std::string &val);
const std::string &get_variable(const std::string &var) const;
bool is_set(const std::string &var) const;
static const std::string bogus;
static const std::string nothing;
private:
std::string fix_value(const std::string &val) const;
std::map<std::string, std::string> _vars;
};
struct eps
{
public:
virtual ~eps() {}
virtual bool do_match(config &) = 0;
virtual bool do_action(config &) = 0;
};
class match : public eps
{
public:
match(config &, const char *var, const char *re);
virtual ~match();
virtual bool do_match(config &);
virtual bool do_action(config &) { return true; }
private:
bool _inv;
std::string _var;
std::string _re;
regex_t _regex;
};
class media : public eps
{
public:
media(config &, const char *var, const char *type);
virtual ~media();
virtual bool do_match(config &);
virtual bool do_action(config &) { return true; }
private:
std::string _var;
int _type;
};
class action : public eps
{
public:
action(const char *cmd);
virtual ~action();
virtual bool do_match(config &) { return true; }
virtual bool do_action(config &);
private:
std::string _cmd;
};
struct event_proc
{
public:
event_proc();
virtual ~event_proc();
int get_priority() const { return (_prio); }
void set_priority(int prio) { _prio = prio; }
void add(eps *);
bool matches(config &) const;
bool run(config &) const;
private:
int _prio;
std::vector<eps *> _epsvec;
};
class config
{
public:
config() { push_var_table(); }
virtual ~config() { reset(); }
void add_attach(int, event_proc *);
void add_detach(int, event_proc *);
void add_directory(const char *);
void add_nomatch(int, event_proc *);
void add_notify(int, event_proc *);
void set_pidfile(const char *);
void reset();
void parse();
void close_pidfile();
void open_pidfile();
void write_pidfile();
void remove_pidfile();
void push_var_table();
void pop_var_table();
void set_variable(const char *var, const char *val);
const std::string &get_variable(const std::string &var);
const std::string expand_string(const char * var,
const char * prepend = NULL, const char * append = NULL);
char *set_vars(char *);
void find_and_execute(char);
protected:
void sort_vector(std::vector<event_proc *> &);
void parse_one_file(const char *fn);
void parse_files_in_dir(const char *dirname);
void expand_one(const char *&src, std::string &dst, bool is_shell);
std::string shell_quote(const std::string &s);
bool is_id_char(char) const;
bool chop_var(char *&buffer, char *&lhs, char *&rhs) const;
private:
std::vector<std::string> _dir_list;
std::string _pidfile;
std::vector<var_list *> _var_list_table;
std::vector<event_proc *> _attach_list;
std::vector<event_proc *> _detach_list;
std::vector<event_proc *> _nomatch_list;
std::vector<event_proc *> _notify_list;
};
#endif