summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-13 20:32:03 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-13 20:32:03 +0000
commit0ed3ef9dee2cb8f4b0c37da218a2fd1eee8c31f6 (patch)
tree933fa0ba26a0113b0404ca52796440bc297a614c /include
parentd9e3bb8d4343643504ab7ee6ab943a000065cc8a (diff)
Add SerializeFormat for easier metadata formatting
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11704 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'include')
-rw-r--r--include/extensible.h46
-rw-r--r--include/modules.h7
2 files changed, 36 insertions, 17 deletions
diff --git a/include/extensible.h b/include/extensible.h
index 0a33470b5..3f5998231 100644
--- a/include/extensible.h
+++ b/include/extensible.h
@@ -1,6 +1,18 @@
class Extensible;
class Module;
+enum SerializeFormat
+{
+ /** Shown to a human (does not need to be unserializable) */
+ FORMAT_USER,
+ /** Passed internally to this process (i.e. for /RELOADMODULE) */
+ FORMAT_INTERNAL,
+ /** Passed to other servers on the network (i.e. METADATA s2s command) */
+ FORMAT_NETWORK,
+ /** Stored on disk (i.e. permchannel database) */
+ FORMAT_PERSIST
+};
+
/** Class represnting an extension of some object
*/
class CoreExport ExtensionItem
@@ -9,10 +21,19 @@ class CoreExport ExtensionItem
const std::string key;
Module* const owner;
ExtensionItem(const std::string& key, Module* owner);
- /** Serialize this item into a string */
- virtual std::string serialize(Module* requestor, const Extensible* container, void* item) = 0;
- /** Convert the string form back into an item */
- virtual void unserialize(Module* requestor, Extensible* container, const std::string& value) = 0;
+ /** Serialize this item into a string
+ *
+ * @param format The format to serialize to
+ * @param container The object containing this item
+ * @param item The item itself
+ */
+ virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) = 0;
+ /** Convert the string form back into an item
+ * @param format The format to serialize from (not FORMAT_USER)
+ * @param container The object that this item applies to
+ * @param value The return from a serialize() call that was run elsewhere with this key
+ */
+ virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value) = 0;
/** Free the item */
virtual void free(void* item) = 0;
@@ -71,9 +92,8 @@ class CoreExport LocalExtItem : public ExtensionItem
{
public:
LocalExtItem(const std::string& key, Module* owner);
- // this is deliberately NOT virtual; don't subclass LocalExtItem if you want to sync data!
- std::string serialize(Module* requestor, const Extensible* container, void* item);
- void unserialize(Module* requestor, Extensible* container, const std::string& value);
+ virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item);
+ virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value);
virtual void free(void* item) = 0;
};
@@ -126,12 +146,18 @@ class CoreExport SimpleExtItem : public LocalExtItem
}
};
-typedef SimpleExtItem<std::string> LocalStringExt;
+class CoreExport LocalStringExt : public SimpleExtItem<std::string>
+{
+ public:
+ LocalStringExt(const std::string& key, Module* owner);
+ std::string serialize(SerializeFormat format, const Extensible* container, void* item);
+};
class CoreExport LocalIntExt : public LocalExtItem
{
public:
LocalIntExt(const std::string& key, Module* owner);
+ std::string serialize(SerializeFormat format, const Extensible* container, void* item);
intptr_t get(const Extensible* container);
intptr_t set(Extensible* container, intptr_t value);
void free(void* item);
@@ -142,8 +168,8 @@ class CoreExport StringExtItem : public ExtensionItem
public:
StringExtItem(const std::string& key, Module* owner);
std::string* get(const Extensible* container);
- std::string serialize(Module* requestor, const Extensible* container, void* item);
- void unserialize(Module* requestor, Extensible* container, const std::string& value);
+ std::string serialize(SerializeFormat format, const Extensible* container, void* item);
+ void unserialize(SerializeFormat format, Extensible* container, const std::string& value);
void set(Extensible* container, const std::string& value);
void unset(Extensible* container);
void free(void* item);
diff --git a/include/modules.h b/include/modules.h
index 4e960ec64..06c0f1dd5 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -857,13 +857,6 @@ class CoreExport Module : public Extensible
*/
virtual void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata);
- /**
- * Implemented by all modules that implement ProtoSendMetaData.
- * Translates the item into a string format suitable for sending to other servers.
- * Currently, this just translates nicks to their UID and channels to their name
- */
- virtual std::string ProtoTranslate(Extensible* item);
-
/** Called after every WALLOPS command.
* @param user The user sending the WALLOPS
* @param text The content of the WALLOPS message