From 4e488cb54d72fb4a1caa580f6756a6f4687beaf6 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 2 Mar 2021 05:39:12 +0000 Subject: Refactor classbase/CullResult into Cullable/Cullable::Result. --- include/base.h | 27 ++------------- include/cull.h | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/cull_list.h | 69 ------------------------------------- include/dynamic.h | 2 +- include/extensible.h | 4 +-- include/inspircd.h | 4 +-- include/inspsocket.h | 2 +- include/iohook.h | 2 +- include/logger.h | 2 +- include/mode.h | 4 +-- include/modules.h | 4 +-- include/modules/sql.h | 8 ++--- include/server.h | 2 +- include/socketengine.h | 2 +- include/stdalgo.h | 2 +- include/users.h | 8 ++--- include/xline.h | 2 +- 17 files changed, 119 insertions(+), 118 deletions(-) create mode 100644 include/cull.h delete mode 100644 include/cull_list.h (limited to 'include') diff --git a/include/base.h b/include/base.h index 83693dc3f..7e541d6b3 100644 --- a/include/base.h +++ b/include/base.h @@ -34,30 +34,7 @@ #include #include "utility/uncopiable.h" - -/** Dummy class to help enforce culls being parent-called up to classbase */ -class CullResult -{ - CullResult() = default; - friend class classbase; -}; - -/** The base class for all inspircd classes with a well-defined lifetime. - * Classes that inherit from this may be destroyed through GlobalCulls, - * and may rely on cull() being called prior to their deletion. - */ -class CoreExport classbase - : private insp::uncopiable -{ - public: - classbase(); - - /** - * Called just prior to destruction via cull list. - */ - virtual CullResult cull(); - virtual ~classbase(); -}; +#include "cull.h" /** The base class for inspircd classes that provide a wrapping interface, and * should only exist while being used. Prevents heap allocation. @@ -239,7 +216,7 @@ enum ServiceType { }; /** A structure defining something that a module can provide */ -class CoreExport ServiceProvider : public classbase +class CoreExport ServiceProvider : public Cullable { public: /** Module that is providing this service */ diff --git a/include/cull.h b/include/cull.h new file mode 100644 index 000000000..7660f2109 --- /dev/null +++ b/include/cull.h @@ -0,0 +1,93 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2013, 2017 Sadie Powell + * Copyright (C) 2012 Robby + * Copyright (C) 2011 jackmcbarn + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2005, 2010 Craig Edwards + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#pragma once + +/* Allows deleting instances of an inheriting type at the end of the current main loop iteration. */ +class CoreExport Cullable + : private insp::uncopiable +{ + protected: + /** Default constructor for the Cullable class. */ + Cullable(); + + public: + /** Dummy class to help ensure all superclasses get culled. */ + class Result final + { + public: + /** Default constructor for the Cullable::Result class. */ + Result() = default; + }; + + /** Destroys this instance of the Cullable class. */ + virtual ~Cullable(); + + /** Called just before the instance is deleted to allow culling members. */ + virtual Result Cull(); +}; + +/** + * The CullList class is used to delete objects at the end of the main loop to + * avoid problems with references to deleted pointers if an object were deleted + * during execution. + */ +class CoreExport CullList +{ + std::vector list; + std::vector SQlist; + + public: + /** Adds an item to the cull list + */ + void AddItem(Cullable* item) { list.push_back(item); } + void AddSQItem(LocalUser* item) { SQlist.push_back(item); } + + /** Applies the cull list (deletes the contents) + */ + void Apply(); +}; + +/** Represents an action which is executable by an action list */ +class CoreExport ActionBase : public Cullable +{ + public: + /** Executes this action. */ + virtual void Call() = 0; +}; + +class CoreExport ActionList +{ + std::vector list; + + public: + /** Adds an item to the list + */ + void AddAction(ActionBase* item) { list.push_back(item); } + + /** Runs the items + */ + void Run(); + +}; diff --git a/include/cull_list.h b/include/cull_list.h deleted file mode 100644 index d29b7b267..000000000 --- a/include/cull_list.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2013, 2017 Sadie Powell - * Copyright (C) 2012 Robby - * Copyright (C) 2011 jackmcbarn - * Copyright (C) 2009 Daniel De Graaf - * Copyright (C) 2007 Dennis Friis - * Copyright (C) 2005, 2010 Craig Edwards - * - * This file is part of InspIRCd. InspIRCd is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#pragma once - -/** - * The CullList class is used to delete objects at the end of the main loop to - * avoid problems with references to deleted pointers if an object were deleted - * during execution. - */ -class CoreExport CullList -{ - std::vector list; - std::vector SQlist; - - public: - /** Adds an item to the cull list - */ - void AddItem(classbase* item) { list.push_back(item); } - void AddSQItem(LocalUser* item) { SQlist.push_back(item); } - - /** Applies the cull list (deletes the contents) - */ - void Apply(); -}; - -/** Represents an action which is executable by an action list */ -class CoreExport ActionBase : public classbase -{ - public: - /** Executes this action. */ - virtual void Call() = 0; -}; - -class CoreExport ActionList -{ - std::vector list; - - public: - /** Adds an item to the list - */ - void AddAction(ActionBase* item) { list.push_back(item); } - - /** Runs the items - */ - void Run(); - -}; diff --git a/include/dynamic.h b/include/dynamic.h index bf19ff6b2..2e1665667 100644 --- a/include/dynamic.h +++ b/include/dynamic.h @@ -38,7 +38,7 @@ /** The DLLManager class is able to load a module file by filename, * and locate its init_module symbol. */ -class CoreExport DLLManager : public classbase +class CoreExport DLLManager : public Cullable { private: /** The last error string. */ diff --git a/include/extensible.h b/include/extensible.h index 94f3e7c28..50ffad3c3 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -125,7 +125,7 @@ class CoreExport ExtensionItem * supports arbitrary data storage). */ class CoreExport Extensible - : public classbase + : public Cullable , public Serializable { public: @@ -150,7 +150,7 @@ class CoreExport Extensible inline const ExtensibleStore& GetExtList() const { return extensions; } Extensible(); - CullResult cull() override; + Cullable::Result Cull() override; virtual ~Extensible(); void UnhookExtensions(const std::vector>& toRemove); diff --git a/include/inspircd.h b/include/inspircd.h index 2b6fdd98c..12ca681b8 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -72,7 +72,7 @@ CoreExport extern InspIRCd* ServerInstance; #include "config.h" #include "dynref.h" #include "consolecolors.h" -#include "cull_list.h" +#include "cull.h" #include "serialize.h" #include "extensible.h" #include "fileutils.h" @@ -565,7 +565,7 @@ class CoreExport InspIRCd ENTRYPOINT; -inline void stdalgo::cull_delete::operator()(classbase* item) +inline void stdalgo::cull_delete::operator()(Cullable* item) { if (item) ServerInstance->GlobalCulls.AddItem(item); diff --git a/include/inspsocket.h b/include/inspsocket.h index d5cdb9b57..d5a139888 100644 --- a/include/inspsocket.h +++ b/include/inspsocket.h @@ -353,7 +353,7 @@ class CoreExport StreamSocket : public EventHandler void Close(bool writeblock); /** This ensures that close is called prior to destructor */ - CullResult cull() override; + Cullable::Result Cull() override; /** Get the IOHook of a module attached to this socket * @param mod Module whose IOHook to return diff --git a/include/iohook.h b/include/iohook.h index b35d68dbf..986a5ba1f 100644 --- a/include/iohook.h +++ b/include/iohook.h @@ -64,7 +64,7 @@ class IOHookProvider : public refcountbase, public ServiceProvider virtual void OnConnect(StreamSocket* sock) = 0; }; -class IOHook : public classbase +class IOHook : public Cullable { public: /** The IOHookProvider for this hook, contains information about the hook, diff --git a/include/logger.h b/include/logger.h index 520f94040..17b694c43 100644 --- a/include/logger.h +++ b/include/logger.h @@ -93,7 +93,7 @@ class CoreExport FileWriter /** LogStream base class. Modules (and other stuff) inherit from this to decide what logging they are interested in, and what to do with it. */ -class CoreExport LogStream : public classbase +class CoreExport LogStream : public Cullable { protected: LogLevel loglvl; diff --git a/include/mode.h b/include/mode.h index df789c5a7..694ece305 100644 --- a/include/mode.h +++ b/include/mode.h @@ -174,7 +174,7 @@ class CoreExport ModeHandler : public ServiceProvider * @param mclass The object type of this mode handler, one of ModeHandler::Class */ ModeHandler(Module* me, const std::string& name, char modeletter, ParamSpec params, ModeType type, Class mclass = MC_OTHER); - CullResult cull() override; + Cullable::Result Cull() override; virtual ~ModeHandler() = default; /** Register this object in the ModeParser @@ -498,7 +498,7 @@ class CoreExport SimpleChannelModeHandler : public ModeHandler * and attach it to the mode using Server::AddModeWatcher and Server::DelModeWatcher. * A ModeWatcher will be called both before and after the mode change. */ -class CoreExport ModeWatcher : public classbase +class CoreExport ModeWatcher : public Cullable { private: /** diff --git a/include/modules.h b/include/modules.h index 290aa9ee6..5177c1585 100644 --- a/include/modules.h +++ b/include/modules.h @@ -283,7 +283,7 @@ enum Implementation * its methods will be called when irc server events occur. class inherited from module must be * instantiated by the ModuleFactory class (see relevant section) for the module to be initialised. */ -class CoreExport Module : public classbase, public usecountbase +class CoreExport Module : public Cullable, public usecountbase { protected: /** Initializes a new instance of the Module class. @@ -328,7 +328,7 @@ class CoreExport Module : public classbase, public usecountbase /** Clean up prior to destruction * If you override, you must call this AFTER your module's cleanup */ - CullResult cull() override; + Cullable::Result Cull() override; /** Default destructor. * destroys a module class diff --git a/include/modules/sql.h b/include/modules/sql.h index ae84e8171..985b273dd 100644 --- a/include/modules/sql.h +++ b/include/modules/sql.h @@ -101,7 +101,7 @@ class SQL::Field }; /** Represents the result of an SQL query. */ -class SQL::Result : public classbase +class SQL::Result : public Cullable { public: /** @@ -198,7 +198,7 @@ class SQL::Error * You should store whatever information is needed to have the callbacks work in * this object (UID of user, channel name, etc). */ -class SQL::Query : public classbase +class SQL::Query : public Cullable { protected: /** Creates a new SQL query. */ @@ -216,12 +216,12 @@ class SQL::Query : public classbase /** Called when an SQL error happens. * @param error The error that occurred. */ - virtual void OnError(Error& error) = 0; + virtual void OnError(SQL::Error& error) = 0; /** Called when a SQL result is received. * @param result The result of the SQL query. */ - virtual void OnResult(Result& result) = 0; + virtual void OnResult(SQL::Result& result) = 0; }; /** diff --git a/include/server.h b/include/server.h index cf9637765..5e28ff9b9 100644 --- a/include/server.h +++ b/include/server.h @@ -21,7 +21,7 @@ #pragma once -class CoreExport Server : public classbase +class CoreExport Server : public Cullable { protected: /** The unique identifier for this server. */ diff --git a/include/socketengine.h b/include/socketengine.h index bb04dfc64..2073f2724 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -154,7 +154,7 @@ enum EventMask * must have a file descriptor. What this file descriptor * is actually attached to is completely up to you. */ -class CoreExport EventHandler : public classbase +class CoreExport EventHandler : public Cullable { private: /** Private state maintained by socket engine */ diff --git a/include/stdalgo.h b/include/stdalgo.h index cf267798b..6b0d27390 100644 --- a/include/stdalgo.h +++ b/include/stdalgo.h @@ -157,7 +157,7 @@ namespace stdalgo */ struct cull_delete { - void operator()(classbase* item); + void operator()(Cullable* item); }; /** diff --git a/include/users.h b/include/users.h index cf4d9d395..97cae5bce 100644 --- a/include/users.h +++ b/include/users.h @@ -306,7 +306,7 @@ class CoreExport User : public Extensible time_t age; /** Time the connection was created, set in the constructor. This - * may be different from the time the user's classbase object was + * may be different from the time the user's Cullable object was * created. */ time_t signon = 0; @@ -619,7 +619,7 @@ class CoreExport User : public Extensible /** Default destructor */ virtual ~User() = default; - CullResult cull() override; + Cullable::Result Cull() override; /** @copydoc Serializable::Deserialize */ bool Deserialize(Data& data) override; @@ -685,7 +685,7 @@ class CoreExport LocalUser : public User, public insp::intrusive_list_node