summaryrefslogtreecommitdiff
path: root/src/service.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-07-28 21:29:35 -0400
committerAdam <Adam@anope.org>2016-07-28 21:29:35 -0400
commit0e758a2ac23dc4a001e8e126cec14588da9a9769 (patch)
tree45df813323e023c5c89db7279426c4ad0943b4a9 /src/service.cpp
parenta3c8afae00c54d5b95c620248b51f90679d7d53f (diff)
Allow serializable fields to use storage in the respective objects.
Split service management code nito a proper servicemanager. Make service references managed instead of lazy lookup. Also made events and serializable use service manager instead of their respective systems for management
Diffstat (limited to 'src/service.cpp')
-rw-r--r--src/service.cpp106
1 files changed, 25 insertions, 81 deletions
diff --git a/src/service.cpp b/src/service.cpp
index cfa9a17c7..c2270b734 100644
--- a/src/service.cpp
+++ b/src/service.cpp
@@ -1,6 +1,8 @@
/*
*
- * (C) 2014 Anope Team
+ * (C) 2014-2016 Anope Team
+ * (C) 2016 Adam <Adam@anope.org>
+ *
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -10,117 +12,59 @@
#include "services.h"
#include "service.h"
+#include "modules/nickserv.h"
+#include "modules/chanserv.h"
+#include "modules/memoserv.h"
-void Service::check()
-{
- if (Services || Aliases)
- return;
-
- Services = new std::map<Anope::string, std::map<Anope::string, Service *> >();
- Aliases = new std::map<Anope::string, std::map<Anope::string, Anope::string> >;
-}
+NickServ::NickServService *NickServ::service = nullptr;
+ChanServ::ChanServService *ChanServ::service = nullptr;
+MemoServ::MemoServService *MemoServ::service = nullptr;
-Service *Service::FindService(const std::map<Anope::string, Service *> &services, const std::map<Anope::string, Anope::string> *aliases, const Anope::string &n)
+ServiceReferenceBase::ServiceReferenceBase(const Anope::string &_type, const Anope::string &_name) : type(_type), name(_name)
{
- std::map<Anope::string, Service *>::const_iterator it = services.find(n);
- if (it != services.end())
- return it->second;
-
- if (aliases != NULL)
- {
- std::map<Anope::string, Anope::string>::const_iterator it2 = aliases->find(n);
- if (it2 != aliases->end())
- return FindService(services, aliases, it2->second);
- }
-
- return NULL;
+ ServiceManager::Get()->RegisterReference(this);
}
-Service *Service::FindService(const Anope::string &t, const Anope::string &n)
+ServiceReferenceBase::ServiceReferenceBase(const Anope::string &_type) : ServiceReferenceBase(_type, "")
{
- check();
-
- std::map<Anope::string, std::map<Anope::string, Service *> >::const_iterator it = (*Services).find(t);
- if (it == (*Services).end())
- return NULL;
-
- std::map<Anope::string, std::map<Anope::string, Anope::string> >::const_iterator it2 = (*Aliases).find(t);
- if (it2 != (*Aliases).end())
- return FindService(it->second, &it2->second, n);
-
- return FindService(it->second, NULL, n);
}
-std::vector<Anope::string> Service::GetServiceKeys(const Anope::string &t)
+ServiceReferenceBase::~ServiceReferenceBase()
{
- check();
-
- std::vector<Anope::string> keys;
- std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = (*Services).find(t);
- if (it != (*Services).end())
- for (std::map<Anope::string, Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
- keys.push_back(it2->first);
- return keys;
+ ServiceManager::Get()->UnregisterReference(this);
}
-void Service::AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v)
+void ServiceReferenceBase::SetService(Service *service)
{
- check();
-
- std::map<Anope::string, Anope::string> &smap = (*Aliases)[t];
- smap[n] = v;
+ if (service == nullptr)
+ this->services.clear();
+ else
+ this->services = { service };
}
-void Service::DelAlias(const Anope::string &t, const Anope::string &n)
+void ServiceReferenceBase::SetServices(const std::vector<Service *> &s)
{
- check();
-
- std::map<Anope::string, Anope::string> &smap = (*Aliases)[t];
- smap.erase(n);
- if (smap.empty())
- (*Aliases).erase(t);
+ this->services = s;
}
Service::Service(Module *o, const Anope::string &t, const Anope::string &n) : owner(o), type(t), name(n)
{
- this->Register();
+ ServiceManager::Get()->Register(this);
}
Service::~Service()
{
- this->Unregister();
-}
-
-void Service::Register()
-{
- check();
-
- std::map<Anope::string, Service *> &smap = (*Services)[this->type];
- if (smap.find(this->name) != smap.end())
- throw ModuleException("Service " + this->type + " with name " + this->name + " already exists");
- smap[this->name] = this;
-
- ReferenceBase::ResetAll();
-}
-
-void Service::Unregister()
-{
- check();
-
- std::map<Anope::string, Service *> &smap = (*Services)[this->type];
- smap.erase(this->name);
- if (smap.empty())
- (*Services).erase(this->type);
+ ServiceManager::Get()->Unregister(this);
}
ServiceAlias::ServiceAlias(const Anope::string &type, const Anope::string &from, const Anope::string &to) : t(type), f(from)
{
- Service::AddAlias(type, from, to);
+ ServiceManager::Get()->AddAlias(type, from, to);
}
ServiceAlias::~ServiceAlias()
{
- Service::DelAlias(t, f);
+ ServiceManager::Get()->DelAlias(t, f);
}