#ifndef __SITECING_COMPONENT_SO_H #define __SITECING_COMPONENT_SO_H #include #include #include #include #include #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 used_chickens_t; /** * The type for storing the list of unused instances. */ typedef list 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 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) { } /** * typed dereference operator * @return the pointer to the most derived component instance * @see acomponent::__the_most_derived_this() */ CT* operator->() { return static_cast(ac->__the_most_derived_this()); } }; } #endif /* __SITECING_COMPONENT_SO_H */