1
0
mirror of https://github.com/anope/anope.git synced 2026-07-09 02:03:14 +02:00

Fixed service_reference to work correctly with external classes

This commit is contained in:
Adam
2011-09-02 15:28:16 -04:00
parent feaef7cc4a
commit 17ea4ed8f5
26 changed files with 47 additions and 108 deletions
+2 -2
View File
@@ -1219,7 +1219,7 @@ class CallBack : public Timer
}
};
template<typename T>
template<typename T, typename U = T>
class service_reference : public dynamic_reference<T>
{
Anope::string name;
@@ -1238,7 +1238,7 @@ class service_reference : public dynamic_reference<T>
}
if (!this->ref)
{
this->ref = Service<T>::FindService(this->name);
this->ref = static_cast<T *>(Service<U>::FindService(this->name));
if (this->ref)
this->ref->AddReference(this);
}
+2
View File
@@ -396,6 +396,8 @@ template<typename T> class CoreExport Service : public Base
};
template<typename T> Anope::map<T *> Service<T>::services;
template class Service<Base>;
#include "sockets.h"
#include "socketengine.h"
#include "extensible.h"
+1 -1
View File
@@ -243,7 +243,7 @@ class CommandOSDefcon : public Command
class OSDefcon : public Module
{
service_reference<SessionService> session_service;
service_reference<SessionService, Base> session_service;
service_reference<XLineManager> akills;
CommandOSDefcon commandosdefcon;
+1 -1
View File
@@ -75,7 +75,7 @@ class MyForbidService : public ForbidService
class CommandOSForbid : public Command
{
service_reference<ForbidService> fs;
service_reference<ForbidService, Base> fs;
public:
CommandOSForbid(Module *creator) : Command(creator, "operserv/forbid", 1, 5), fs("forbid")
{
+2 -2
View File
@@ -19,10 +19,10 @@ struct ForbidData
ForbidType type;
};
class ForbidService : public Service<ForbidService>
class ForbidService : public Service<Base>
{
public:
ForbidService(Module *m) : Service<ForbidService>(m, "forbid") { }
ForbidService(Module *m) : Service<Base>(m, "forbid") { }
virtual void AddForbid(ForbidData *d) = 0;
+5 -5
View File
@@ -146,7 +146,7 @@ class CommandOSIgnore : public Command
private:
void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
{
service_reference<IgnoreService> ignore_service("ignore");
service_reference<IgnoreService, Base> ignore_service("ignore");
if (!ignore_service)
return;
@@ -181,7 +181,7 @@ class CommandOSIgnore : public Command
void DoList(CommandSource &source)
{
service_reference<IgnoreService> ignore_service("ignore");
service_reference<IgnoreService, Base> ignore_service("ignore");
if (!ignore_service)
return;
@@ -205,7 +205,7 @@ class CommandOSIgnore : public Command
void DoDel(CommandSource &source, const std::vector<Anope::string> &params)
{
service_reference<IgnoreService> ignore_service("ignore");
service_reference<IgnoreService, Base> ignore_service("ignore");
if (!ignore_service)
return;
@@ -222,7 +222,7 @@ class CommandOSIgnore : public Command
void DoClear(CommandSource &source)
{
service_reference<IgnoreService> ignore_service("ignore");
service_reference<IgnoreService, Base> ignore_service("ignore");
if (!ignore_service)
return;
@@ -301,7 +301,7 @@ class OSIgnore : public Module
{
if (params.size() >= 4 && params[0].equals_ci("OS") && params[1].equals_ci("IGNORE"))
{
service_reference<IgnoreService> ignore_service("ignore");
service_reference<IgnoreService, Base> ignore_service("ignore");
if (ignore_service)
{
const Anope::string &mask = params[2];
+2 -2
View File
@@ -18,12 +18,12 @@ struct IgnoreData
time_t time; /* When do we stop ignoring them? */
};
class IgnoreService : public Service<IgnoreService>
class IgnoreService : public Service<Base>
{
protected:
std::list<IgnoreData> ignores;
IgnoreService(Module *c, const Anope::string &n) : Service<IgnoreService>(c, n) { }
IgnoreService(Module *c, const Anope::string &n) : Service<Base>(c, n) { }
public:
virtual void AddIgnore(const Anope::string &mask, const Anope::string &creator, const Anope::string &reason, time_t delta = Anope::CurTime) = 0;
+1 -1
View File
@@ -106,7 +106,7 @@ static const char **findmsgs(NewsType type)
class NewsBase : public Command
{
service_reference<NewsService> ns;
service_reference<NewsService, Base> ns;
protected:
void DoList(CommandSource &source, NewsType type, const char **msgs)
+2 -2
View File
@@ -23,10 +23,10 @@ struct NewsItem
time_t time;
};
class NewsService : public Service<NewsService>
class NewsService : public Service<Base>
{
public:
NewsService(Module *m) : Service<NewsService>(m, "news") { }
NewsService(Module *m) : Service<Base>(m, "news") { }
virtual void AddNewsItem(NewsItem *n) = 0;
+2 -2
View File
@@ -14,7 +14,7 @@
#include "module.h"
#include "os_session.h"
static service_reference<SessionService> sessionservice("session");
static service_reference<SessionService, Base> sessionservice("session");
class MySessionService : public SessionService
{
@@ -634,7 +634,7 @@ class OSSession : public Module
ExpireTimer expiretimer;
CommandOSSession commandossession;
CommandOSException commandosexception;
service_reference<XLineManager> akills;
service_reference<XLineManager, Base> akills;
void AddSession(User *u, bool exempt)
{
+2 -2
View File
@@ -1,13 +1,13 @@
#ifndef OS_SESSION_H
#define OS_SESSION_H
class SessionService : public Service<SessionService>
class SessionService : public Service<Base>
{
public:
typedef Anope::map<Session *> SessionMap;
typedef std::vector<Exception *> ExceptionVector;
SessionService(Module *m) : Service<SessionService>(m, "session") { }
SessionService(Module *m) : Service<Base>(m, "session") { }
virtual void AddException(Exception *e) = 0;
+2 -2
View File
@@ -88,10 +88,10 @@ class DBMySQL : public Module
private:
CommandSQLSync commandsqlsync;
MySQLInterface sqlinterface;
service_reference<SQLProvider> SQL;
service_reference<SQLProvider, Base> SQL;
public:
service_reference<SessionService> SessionInterface;
service_reference<SessionService, Base> SessionInterface;
time_t lastwarn;
bool ro;
+1 -1
View File
@@ -134,7 +134,7 @@ static void NickCoreUpdate(const SQLResult &res)
class MySQLLiveModule : public Module
{
service_reference<SQLProvider> SQL;
service_reference<SQLProvider, Base> SQL;
SQLCache chan_cache, nick_cache, core_cache;
+1 -1
View File
@@ -15,7 +15,7 @@
Anope::string DatabaseFile;
std::stringstream db_buffer;
service_reference<SessionService> SessionInterface("session");
service_reference<SessionService, Base> SessionInterface("session");
/** Enum used for what METADATA type we are reading
*/
+2 -2
View File
@@ -111,10 +111,10 @@ class LDAPInterface
virtual void OnError(const LDAPResult &err) { }
};
class LDAPProvider : public Service<LDAPProvider>
class LDAPProvider : public Service<Base>
{
public:
LDAPProvider(Module *c, const Anope::string &n) : Service<LDAPProvider>(c, n) { }
LDAPProvider(Module *c, const Anope::string &n) : Service<Base>(c, n) { }
/** Attempt to bind to the LDAP server as an admin
* @param i The LDAPInterface the result is sent to
+1 -1
View File
@@ -165,7 +165,7 @@ class OnRegisterInterface : public LDAPInterface
class NSIdentifyLDAP : public Module
{
service_reference<LDAPProvider> ldap;
service_reference<LDAPProvider, Base> ldap;
IdentifyInterface iinterface;
OnIdentifyInterface oninterface;
OnRegisterInterface orinterface;
+1 -1
View File
@@ -76,7 +76,7 @@ class IdentifyInterface : public LDAPInterface
class LDAPOper : public Module
{
service_reference<LDAPProvider> ldap;
service_reference<LDAPProvider, Base> ldap;
IdentifyInterface iinterface;
Anope::string binddn;
+1 -1
View File
@@ -220,7 +220,7 @@ class ModuleXMLRPC;
static ModuleXMLRPC *me;
class ModuleXMLRPC : public Module
{
service_reference<SSLService> sslref;
service_reference<SSLService, Base> sslref;
public:
MyXMLRPCServiceInterface xmlrpcinterface;
+1 -1
View File
@@ -255,7 +255,7 @@ class MyXMLRPCEvent : public XMLRPCEvent
class ModuleXMLRPCMain : public Module
{
service_reference<XMLRPCServiceInterface> xmlrpc;
service_reference<XMLRPCServiceInterface, Base> xmlrpc;
MyXMLRPCEvent stats;
+2 -2
View File
@@ -108,10 +108,10 @@ class SQLInterface
/** Class providing the SQL service, modules call this to execute queries
*/
class SQLProvider : public Service<SQLProvider>
class SQLProvider : public Service<Base>
{
public:
SQLProvider(Module *c, const Anope::string &n) : Service<SQLProvider>(c, n) { }
SQLProvider(Module *c, const Anope::string &n) : Service<Base>(c, n) { }
virtual void Run(SQLInterface *i, const SQLQuery &query) = 0;
+2 -2
View File
@@ -1,8 +1,8 @@
class SSLService : public Service<SSLService>
class SSLService : public Service<Base>
{
public:
SSLService(Module *o, const Anope::string &n) : Service<SSLService>(o, n) { }
SSLService(Module *o, const Anope::string &n) : Service<Base>(o, n) { }
virtual void Init(Socket *s) = 0;
};
+2 -2
View File
@@ -55,10 +55,10 @@ class XMLRPCEvent
virtual void Run(XMLRPCServiceInterface *iface, XMLRPCClientSocket *source, XMLRPCRequest *request) = 0;
};
class XMLRPCServiceInterface : public Service<XMLRPCServiceInterface>
class XMLRPCServiceInterface : public Service<Base>
{
public:
XMLRPCServiceInterface(Module *creator, const Anope::string &sname) : Service<XMLRPCServiceInterface>(creator, sname) { }
XMLRPCServiceInterface(Module *creator, const Anope::string &sname) : Service<Base>(creator, sname) { }
virtual void Register(XMLRPCEvent *event) = 0;
-63
View File
@@ -1,63 +0,0 @@
#ifndef BOTSERV_H
#define BOTSERV_H
struct UserData
{
UserData()
{
this->Clear();
}
void Clear()
{
last_use = last_start = Anope::CurTime;
lines = times = 0;
lastline.clear();
}
/* Data validity */
time_t last_use;
/* for flood kicker */
int16 lines;
time_t last_start;
/* for repeat kicker */
Anope::string lastline;
Anope::string lasttarget;
int16 times;
};
struct BanData
{
Anope::string mask;
time_t last_use;
int16 ttb[TTB_SIZE];
BanData()
{
this->Clear();
}
void Clear()
{
last_use = 0;
for (int i = 0; i < TTB_SIZE; ++i)
this->ttb[i] = 0;
}
};
class BotServService : public Service
{
public:
BotServService(Module *m) : Service(m, "BotServ") { }
virtual UserData *GetUserData(User *u, Channel *c) = 0;
virtual BanData *GetBanData(User *u, Channel *c) = 0;
};
static service_reference<BotServService> botserv("BotServ");
#endif // BOTSERV_H
+3 -3
View File
@@ -1,10 +1,10 @@
#ifndef GLOBAL_H
#define GLOBAL_H
class GlobalService : public Service<GlobalService>
class GlobalService : public Service<Base>
{
public:
GlobalService(Module *m) : Service<GlobalService>(m, "Global") { }
GlobalService(Module *m) : Service<Base>(m, "Global") { }
/** Send out a global message to all users
* @param sender Our client which should send the global
@@ -14,7 +14,7 @@ class GlobalService : public Service<GlobalService>
virtual void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) = 0;
};
static service_reference<GlobalService> global("Global");
static service_reference<GlobalService, Base> global("Global");
#endif // GLOBAL_H
+3 -3
View File
@@ -1,7 +1,7 @@
#ifndef MEMOSERV_H
#define MEMOSERV_H
class MemoServService : public Service<MemoServService>
class MemoServService : public Service<Base>
{
public:
enum MemoResult
@@ -12,7 +12,7 @@ class MemoServService : public Service<MemoServService>
MEMO_TARGET_FULL
};
MemoServService(Module *m) : Service<MemoServService>(m, "MemoServ") { }
MemoServService(Module *m) : Service<Base>(m, "MemoServ") { }
/** Retrieve the memo info for a nick or channel
* @param target Target
@@ -35,7 +35,7 @@ class MemoServService : public Service<MemoServService>
virtual void Check(User *u) = 0;
};
static service_reference<MemoServService> memoserv("MemoServ");
static service_reference<MemoServService, Base> memoserv("MemoServ");
#endif // MEMOSERV_H
+3 -3
View File
@@ -1,15 +1,15 @@
#ifndef NICKSERV_H
#define NICKSERV_H
class NickServService : public Service<NickServService>
class NickServService : public Service<Base>
{
public:
NickServService(Module *m) : Service<NickServService>(m, "NickServ") { }
NickServService(Module *m) : Service<Base>(m, "NickServ") { }
virtual void Validate(User *u) = 0;
};
static service_reference<NickServService> nickserv("NickServ");
static service_reference<NickServService, Base> nickserv("NickServ");
#endif // NICKSERV_H