summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2003-04-26 20:59:04 +0000
committerimp <imp@FreeBSD.org>2003-04-26 20:59:04 +0000
commit9f864f962e6456a803eda5de9c2a5c451f36edc9 (patch)
tree2343cb82f7d1f2b8bbd96a837ca592ec27d7630f /sbin
parent0c6d9d6137c9e68207e641fb4b21724c795fdf17 (diff)
downloadFreeBSD-src-9f864f962e6456a803eda5de9c2a5c451f36edc9.zip
FreeBSD-src-9f864f962e6456a803eda5de9c2a5c451f36edc9.tar.gz
Create a new C++ header file called devd.hh which has all the class
definitions in it. Begin to document the classes that we use, and how they interrelate (using comments that I can use with doxygen to automatically generate docs with).
Diffstat (limited to 'sbin')
-rw-r--r--sbin/devd/devd.cc103
-rw-r--r--sbin/devd/devd.h7
-rw-r--r--sbin/devd/devd.hh163
3 files changed, 172 insertions, 101 deletions
diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc
index df9ba7f..2265604 100644
--- a/sbin/devd/devd.cc
+++ b/sbin/devd/devd.cc
@@ -56,7 +56,8 @@ __FBSDID("$FreeBSD$");
#include <string>
#include <vector>
-#include "devd.h"
+#include "devd.h" /* C compatible definitions */
+#include "devd.hh" /* C++ class definitions */
#define CF "/etc/devd.conf"
#define SYSCTL "hw.bus.devctl_disable"
@@ -88,106 +89,6 @@ delete_and_clear(vector<T *> &v)
v.clear();
}
-class config;
-
-class var_list
-{
-public:
- var_list() {}
- virtual ~var_list() {}
- void set_variable(const string &var, const string &val);
- const string &get_variable(const string &var) const;
- bool is_set(const string &var) const;
- static const string bogus;
- static const string nothing;
-private:
- map<string, string> _vars;
-};
-
-class eps
-{
-public:
- eps() {}
- 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:
- string _var;
- string _re;
- regex_t _regex;
-};
-
-class action : public eps
-{
-public:
- action(const char *cmd);
- virtual ~action();
- virtual bool do_match(config &) { return true; }
- virtual bool do_action(config &);
-private:
- string _cmd;
-};
-
-class 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 &);
- bool run(config &);
-private:
- int _prio;
- vector<eps *> _epsvec;
-};
-
-class config
-{
-public:
- config() : _pidfile("") { 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 set_pidfile(const char *);
- void reset();
- void parse();
- void drop_pidfile();
- void push_var_table();
- void pop_var_table();
- void set_variable(const char *var, const char *val);
- const string &get_variable(const string &var);
- const string expand_string(const string &var);
- char *set_vars(char *);
- void find_and_execute(char);
-protected:
- void sort_vector(vector<event_proc *> &);
- void parse_one_file(const char *fn);
- void parse_files_in_dir(const char *dirname);
- void expand_one(const char *&src, string &dst);
- bool is_id_char(char);
- bool chop_var(char *&buffer, char *&lhs, char *&rhs);
-private:
- vector<string> _dir_list;
- string _pidfile;
- vector<var_list *> _var_list_table;
- vector<event_proc *> _attach_list;
- vector<event_proc *> _detach_list;
- vector<event_proc *> _nomatch_list;
-};
-
config cfg;
event_proc::event_proc() : _prio(-1)
diff --git a/sbin/devd/devd.h b/sbin/devd/devd.h
index 1319664..c2f54a6 100644
--- a/sbin/devd/devd.h
+++ b/sbin/devd/devd.h
@@ -28,6 +28,11 @@
* $FreeBSD$
*/
+#ifndef DEVD_H
+#define DEVD_H
+
+/** @warning This file needs to be purely 'C' compatible.
+ */
struct event_proc;
struct eps;
__BEGIN_DECLS
@@ -47,3 +52,5 @@ __END_DECLS
#define PATH_DEVCTL "/dev/devctl"
#define DEVCTL_MAXBUF 1025
+
+#endif /* DEVD_H */
diff --git a/sbin/devd/devd.hh b/sbin/devd/devd.hh
new file mode 100644
index 0000000..15dba5d
--- /dev/null
+++ b/sbin/devd/devd.hh
@@ -0,0 +1,163 @@
+/*-
+ * Copyright (c) 2002-2003 M. Warner Losh.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef DEVD_HH
+#define DEVD_HH
+
+class config;
+
+/**
+ * var_list is a collection of variables. These collections of variables
+ * are stacked up and popped down for each event that we have to process.
+ * We have multiple levels so that we can push variables that are unique
+ * to the event in question, in addition to having global variables. This
+ * allows for future flexibility.
+ */
+class var_list
+{
+public:
+ var_list() {}
+ virtual ~var_list() {}
+ /** Set a variable in this var list.
+ */
+ void set_variable(const std::string &var, const std::string &val);
+ /** Get the variable out of this, and no other, var_list. If
+ * no variable of %var is set, then %bogus will be returned.
+ */
+ const std::string &get_variable(const std::string &var) const;
+ /** Is there a variable of %var set in thi stable?
+ */
+ bool is_set(const std::string &var) const;
+ /** A completely bogus string.
+ */
+ static const std::string bogus;
+ static const std::string nothing;
+private:
+ std::map<std::string, std::string> _vars;
+};
+
+/**
+ * eps is short for event_proc_single. It is a single entry in an
+ * event_proc. Each keyword needs its own subclass from eps.
+ */
+class eps
+{
+public:
+ eps() {}
+ virtual ~eps() {}
+ /** Does this eps match the current config?
+ */
+ virtual bool do_match(config &) = 0;
+ /** Perform some action for this eps.
+ */
+ virtual bool do_action(config &) = 0;
+};
+
+/**
+ * match is the subclass used to match an individual variable. Its
+ * actions are nops.
+ */
+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:
+ std::string _var;
+ std::string _re;
+ regex_t _regex;
+};
+
+/**
+ * action is used to fork a process. It matches everything.
+ */
+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;
+};
+
+class 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 &);
+ bool run(config &);
+private:
+ int _prio;
+ std::vector<eps *> _epsvec;
+};
+
+class config
+{
+public:
+ config() : _pidfile("") { 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 set_pidfile(const char *);
+ void reset();
+ void parse();
+ void drop_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 std::string &var);
+ 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_id_char(char);
+ bool chop_var(char *&buffer, char *&lhs, char *&rhs);
+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;
+};
+
+#endif /* DEVD_HH */
OpenPOWER on IntegriCloud