summaryrefslogtreecommitdiffabout
path: root/include/sitecing/component_so.h
Side-by-side diff
Diffstat (limited to 'include/sitecing/component_so.h') (more/less context) (ignore whitespace changes)
-rw-r--r--include/sitecing/component_so.h159
1 files changed, 159 insertions, 0 deletions
diff --git a/include/sitecing/component_so.h b/include/sitecing/component_so.h
new file mode 100644
index 0000000..3239d4a
--- a/dev/null
+++ b/include/sitecing/component_so.h
@@ -0,0 +1,159 @@
+#ifndef __SITECING_COMPONENT_SO_H
+#define __SITECING_COMPONENT_SO_H
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string>
+#include <map>
+#include <list>
+#include "sitecing/acomponent.h"
+
+/**
+ * @file
+ * @brief Classes related to the .so components handling.
+ */
+
+namespace sitecing {
+ using namespace std;
+
+ /**
+ * The 'class' component object.
+ */
+ class component_so {
+ public:
+ /**
+ * The type of the component instantiating function.
+ */
+ typedef acomponent *(*egg_t)();
+ /**
+ * Type for storing the list of instances and the reference counts.
+ */
+ typedef map<acomponent*,int> used_chickens_t;
+ /**
+ * The type for storing the list of unused instances.
+ */
+ typedef list<acomponent*> free_chickens_t;
+
+ /**
+ * The .so file name.
+ */
+ string sofile;
+ /**
+ * The stat structure for the .so loaded.
+ */
+ struct stat stso;
+ /**
+ * The dloaded .so handle.
+ */
+ void *dl;
+ /**
+ * Pointer to the instatiator function.
+ */
+ egg_t egg;
+ /**
+ * The list of instances in use.
+ */
+ used_chickens_t chickens_used;
+ /**
+ * The list of unused instances.
+ */
+ free_chickens_t chickens_free;
+
+ /**
+ * @param soname the .so file name
+ */
+ component_so(const string& soname);
+ ~component_so();
+ /**
+ * Check whether the loaded .so is in sync with the disk file.
+ */
+ bool is_uptodate() const;
+
+ /**
+ * @todo TODO: wish I could remember -- document me.
+ */
+ acomponent* allocate_chicken();
+ /**
+ * @todo TODO: wish I could remember -- document me.
+ */
+ void allocate_chicken(acomponent *ac);
+ /**
+ * @todo TODO: wish I could remember -- document me.
+ */
+ void deallocate_chicken(acomponent *ac);
+ };
+
+ /**
+ * The component instance container.
+ */
+ class so_component {
+ public:
+ /**
+ * Pointer to the component 'class'.
+ */
+ component_so *hen;
+ /**
+ * The instance in question.
+ */
+ acomponent* ac;
+
+ so_component()
+ : hen(0), ac(0) { }
+ /**
+ * @param h the 'class' object.
+ * @param scif pointer to the interface to the site-C-ing core.
+ */
+ so_component(component_so *h,sitecing_interface *scif);
+ /**
+ * Copy constructor
+ * @param s source instance.
+ */
+ so_component(const so_component& s)
+ : hen(0), ac(0) { attach(s); }
+ ~so_component() { detach(); }
+
+ /**
+ * Assignment operator.
+ * @param s source instance.
+ */
+ so_component& operator=(const so_component& s) {
+ attach(s); return *this;
+ }
+
+ /**
+ * @todo TODO: wish I could remember the details -- document me.
+ * @param h the 'class' object.
+ * @param a the instance to be attached.
+ */
+ void attach(component_so *h,acomponent *a);
+ /**
+ * @todo TODO: wish I could remember the details -- document me.
+ * @param s the source instance.
+ */
+ void attach(const so_component& s) { attach(s.hen,s.ac); }
+ /**
+ * @todo TODO: wish I could remember the details -- document me.
+ */
+ void detach();
+ };
+
+ /**
+ * The typed component instance container template.
+ * @param CT the component class.
+ */
+ template<typename CT>
+ class so_component_t : public sitecing::so_component {
+ public:
+ /**
+ * @param s The untyped instance container.
+ */
+ so_component_t(const so_component& s)
+ : so_component(s) { }
+ CT* operator->() {
+ return static_cast<CT*>(ac->__the_most_derived_this());
+ }
+ };
+
+}
+
+#endif /* __SITECING_COMPONENT_SO_H */