From a950ed8cabfeca55c909f02412b1788bd386dcff Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 15 Aug 2010 01:45:38 -0400 Subject: Rewrote the MySQL API to use threads. This acts similar to before, but is faster. Removed db_mysql_execute for now. --- include/modules.h | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++-- include/services.h | 1 + include/sockets.h | 24 +++++++++++ 3 files changed, 141 insertions(+), 3 deletions(-) (limited to 'include') 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 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 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 dyn_references; + +template +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::iterator it = dyn_references.begin(), it_end = dyn_references.end(); it != it_end;) + { + dynamic_reference *d = static_cast *>(*it); + ++it; + + if (d && d->ref == obj) + { + d->Invalidate(); + } + } + } +}; + +template +class service_reference : public dynamic_reference +{ + Module *owner; + Anope::string name; + + public: + service_reference(Module *o, const Anope::string &n) : dynamic_reference(), owner(o), name(n) + { + } + + ~service_reference() + { + } + + operator bool() + { + if (!this->ref) + this->ref = static_cast(ModuleManager::GetService(this->name)); + return this->ref; + } + + inline T *operator->() + { + if (!this->ref) + this->ref = static_cast(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 #include #include +#include #include #include 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 /* 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 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: -- cgit