summaryrefslogtreecommitdiff
path: root/include/modules/redis.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/modules/redis.h')
-rw-r--r--include/modules/redis.h59
1 files changed, 43 insertions, 16 deletions
diff --git a/include/modules/redis.h b/include/modules/redis.h
index 4bb62c7c6..874bff998 100644
--- a/include/modules/redis.h
+++ b/include/modules/redis.h
@@ -1,9 +1,20 @@
/*
+ * Anope IRC Services
*
- * (C) 2003-2017 Anope Team
- * Contact us at team@anope.org
+ * Copyright (C) 2013-2017 Anope Team <team@anope.org>
*
- * Please read COPYING and README for further details.
+ * This file is part of Anope. Anope 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 see <http://www.gnu.org/licenses/>.
*/
namespace Redis
@@ -23,7 +34,7 @@ namespace Redis
Reply() { Clear(); }
~Reply() { Clear(); }
-
+
void Clear()
{
type = NOT_PARSED;
@@ -43,30 +54,46 @@ namespace Redis
class Interface
{
- public:
Module *owner;
+ public:
Interface(Module *m) : owner(m) { }
- virtual ~Interface() { }
+ virtual ~Interface() = default;
+
+ Module *GetOwner() const { return owner; }
- virtual void OnResult(const Reply &r) = 0;
- virtual void OnError(const Anope::string &error) { Log(owner) << error; }
+ virtual void OnResult(const Reply &r) anope_abstract;
+ virtual void OnError(const Anope::string &error) { owner->logger.Log(error); }
+ };
+
+ class FInterface : public Interface
+ {
+ public:
+ using Func = std::function<void(const Reply &)>;
+ Func function;
+
+ FInterface(Module *m, Func f) : Interface(m), function(f) { }
+
+ void OnResult(const Reply &r) override { function(r); }
};
class Provider : public Service
{
public:
- Provider(Module *c, const Anope::string &n) : Service(c, "Redis::Provider", n) { }
+ static constexpr const char *NAME = "redis";
+
+ Provider(Module *c, const Anope::string &n) : Service(c, NAME, n) { }
- virtual void SendCommand(Interface *i, const std::vector<Anope::string> &cmds) = 0;
- virtual void SendCommand(Interface *i, const Anope::string &str) = 0;
+ virtual void SendCommand(Interface *i, const std::vector<Anope::string> &cmds) anope_abstract;
+ virtual void SendCommand(Interface *i, const Anope::string &str) anope_abstract;
- virtual bool BlockAndProcess() = 0;
+ virtual bool BlockAndProcess() anope_abstract;
- virtual void Subscribe(Interface *i, const Anope::string &pattern) = 0;
- virtual void Unsubscribe(const Anope::string &pattern) = 0;
+ virtual void Subscribe(Interface *i, const Anope::string &) anope_abstract;
+ virtual void Unsubscribe(const Anope::string &pattern) anope_abstract;
- virtual void StartTransaction() = 0;
- virtual void CommitTransaction() = 0;
+ virtual void StartTransaction() anope_abstract;
+ virtual void CommitTransaction() anope_abstract;
};
}
+