diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/modules.h | 119 | ||||
| -rw-r--r-- | include/services.h | 1 | ||||
| -rw-r--r-- | include/sockets.h | 24 |
3 files changed, 141 insertions, 3 deletions
diff --git a/include/modules.h b/include/modules.h index 627e04383..307c83d87 100644 --- a/include/modules.h +++ b/include/modules.h @@ -160,9 +160,6 @@ extern CoreExport message_map MessageMap; class Module; extern CoreExport std::list<Module *> Modules; -/*************************************************************************/ -/* Structure for information about a *Serv command. */ - class Version { private: @@ -1109,11 +1106,16 @@ enum Implementation I_END }; +class Service; /** Used to manage modules. */ class CoreExport ModuleManager { + private: + /** A map of service providers + */ + static std::map<Anope::string, Service *> ServiceProviders; public: /** Event handler hooks. * This needs to be public to be used by FOREACH_MOD and friends. @@ -1202,6 +1204,24 @@ class CoreExport ModuleManager */ static void UnloadAll(bool unload_proto); + /** Register a service + * @param s The service + * @return true if it was successfully registeed, else false (service name colision) + */ + static bool RegisterService(Service *s); + + /** Unregister a service + * @param s The service + * @return true if it was unregistered successfully + */ + static bool UnregisterService(Service *s); + + /** Get a service + * @param name The service name + * @return The services, or NULL + */ + static Service *GetService(const Anope::string &name); + private: /** Call the module_delete function to safely delete the module * @param m the module to delete @@ -1229,6 +1249,99 @@ class CallBack : public Timer } }; +class Service +{ + public: + Module *owner; + Anope::string name; + + Service(Module *o, const Anope::string &n); + + virtual ~Service(); +}; + +class dynamic_reference_base +{ + public: + dynamic_reference_base(); + + virtual ~dynamic_reference_base(); +}; + +extern std::list<dynamic_reference_base *> dyn_references; + +template<typename T> +class dynamic_reference : public dynamic_reference_base +{ + protected: + T *ref; + public: + dynamic_reference() : dynamic_reference_base(), ref(NULL) { } + + dynamic_reference(T *obj) : dynamic_reference_base(), ref(obj) { } + + virtual ~dynamic_reference() { } + + virtual operator bool() + { + return this->ref; + } + + virtual inline T *operator->() + { + return this->ref; + } + + void Invalidate() + { + this->ref = NULL; + } + + static void Invalidate(T *obj) + { + for (std::list<dynamic_reference_base *>::iterator it = dyn_references.begin(), it_end = dyn_references.end(); it != it_end;) + { + dynamic_reference<void *> *d = static_cast<dynamic_reference<void *> *>(*it); + ++it; + + if (d && d->ref == obj) + { + d->Invalidate(); + } + } + } +}; + +template<typename T> +class service_reference : public dynamic_reference<T> +{ + Module *owner; + Anope::string name; + + public: + service_reference(Module *o, const Anope::string &n) : dynamic_reference<T>(), owner(o), name(n) + { + } + + ~service_reference() + { + } + + operator bool() + { + if (!this->ref) + this->ref = static_cast<T *>(ModuleManager::GetService(this->name)); + return this->ref; + } + + inline T *operator->() + { + if (!this->ref) + this->ref = static_cast<T *>(ModuleManager::GetService(this->name)); + return this->ref; + } +}; + struct Message { Anope::string name; diff --git a/include/services.h b/include/services.h index 1a81d6e96..15670c8ac 100644 --- a/include/services.h +++ b/include/services.h @@ -30,6 +30,7 @@ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <stdexcept> #include <string.h> #include <signal.h> diff --git a/include/sockets.h b/include/sockets.h index 78ed5f4af..6eeb3bf3d 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -81,6 +81,10 @@ class CoreExport Socket : public Flags<SocketFlag, 1> /* Type this socket is */ SocketType Type; + /** Empty constructor, used for things such as the pipe socket + */ + Socket(); + /** Default constructor * @param nsock The socket to use, 0 if we need to create our own * @param nIPv6 true if using ipv6 @@ -149,6 +153,26 @@ class CoreExport Socket : public Flags<SocketFlag, 1> void Write(const Anope::string &message); }; +class CoreExport Pipe : public Socket +{ + private: + int WritePipe; + + int RecvInternal(char *buf, size_t sz) const; + + int SendInternal(const Anope::string &buf) const; + public: + Pipe(); + + bool ProcessRead(); + + bool Read(const Anope::string &); + + void Notify(); + + virtual void OnNotify(); +}; + class CoreExport ClientSocket : public Socket { protected: |
