changeset 6562:c53a3f0649eb

[gaim-migrate @ 7084] New GaimValue structure. We'll be using this for signals and stuff shortly. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Thu, 21 Aug 2003 20:29:33 +0000
parents 33ceba0dfd9b
children 122cb375be2d
files src/Makefile.am src/signals.h src/value.c src/value.h
diffstat 4 files changed, 839 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Thu Aug 21 18:29:48 2003 +0000
+++ b/src/Makefile.am	Thu Aug 21 20:29:33 2003 +0000
@@ -89,7 +89,9 @@
 	sound.c \
 	sound.h \
 	util.c \
-	util.h
+	util.h \
+	value.c \
+	value.h
 
 bin_PROGRAMS = gaim gaim-remote
 gaim_SOURCES = \
--- a/src/signals.h	Thu Aug 21 18:29:48 2003 +0000
+++ b/src/signals.h	Thu Aug 21 20:29:33 2003 +0000
@@ -25,53 +25,6 @@
 
 #include <glib.h>
 
-#if 0
-/**
- * Event types
- */
-typedef enum gaim_event
-{
-	event_signon = 0,
-	event_signoff,
-	event_away,
-	event_back,
-	event_im_recv,
-	event_im_send,
-	event_buddy_signon,
-	event_buddy_signoff,
-	event_buddy_away,
-	event_buddy_back,
-	event_buddy_idle,
-	event_buddy_unidle,
-	event_blist_update,
-	event_chat_invited,
-	event_chat_join,
-	event_chat_leave,
-	event_chat_buddy_join,
-	event_chat_buddy_leave,
-	event_chat_recv,
-	event_chat_send,
-	event_warned,
-	event_error,
-	event_quit,
-	event_new_conversation,
-	event_set_info,
-	event_draw_menu,
-	event_im_displayed_sent,
-	event_im_displayed_rcvd,
-	event_chat_send_invite,
-	event_got_typing,
-	event_del_conversation,
-	event_connecting,
-	event_conversation_switch
-	/* any others? it's easy to add... */
-
-} GaimEvent;
-
-typedef int (*GaimSignalBroadcastFunc)(GaimEvent event, void *data,
-									   va_list args);
-#endif
-
 #define GAIM_CALLBACK(func) ((GaimCallback)func)
 
 typedef void (*GaimCallback)(void);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/value.c	Thu Aug 21 20:29:33 2003 +0000
@@ -0,0 +1,390 @@
+/**
+ * @file value.c Value wrapper API
+ * @ingroup core
+ *
+ * gaim
+ *
+ * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include "internal.h"
+
+#include "value.h"
+
+#define OUTGOING_FLAG 0x01
+
+GaimValue *
+gaim_value_new(GaimType type, ...)
+{
+	GaimValue *value;
+	va_list args;
+
+	g_return_val_if_fail(type != GAIM_TYPE_UNKNOWN, NULL);
+
+	value = g_new0(GaimValue, 1);
+
+	value->type = type;
+
+	va_start(args, type);
+
+	if (type == GAIM_TYPE_SUBTYPE)
+		value->u.subtype = va_arg(args, int);
+	else if (type == GAIM_TYPE_BOXED)
+		value->u.specific_type = g_strdup(va_arg(args, char *));
+
+	va_end(args);
+
+	return value;
+}
+
+GaimValue *
+gaim_value_new_outgoing(GaimType type, ...)
+{
+	GaimValue *value;
+	va_list args;
+
+	g_return_val_if_fail(type != GAIM_TYPE_UNKNOWN, NULL);
+
+	value = g_new0(GaimValue, 1);
+
+	value->type = type;
+
+	va_start(args, type);
+
+	if (type == GAIM_TYPE_SUBTYPE)
+		value->u.subtype = va_arg(args, int);
+	else if (type == GAIM_TYPE_BOXED)
+		value->u.specific_type = g_strdup(va_arg(args, char *));
+
+	va_end(args);
+
+	value->flags |= OUTGOING_FLAG;
+
+	return value;
+}
+
+void
+gaim_value_destroy(GaimValue *value)
+{
+	g_return_if_fail(value != NULL);
+
+	if (gaim_value_get_type(value) == GAIM_TYPE_BOXED)
+	{
+		if (value->u.specific_type != NULL)
+			g_free(value->u.specific_type);
+	}
+	else if (gaim_value_get_type(value) == GAIM_TYPE_STRING)
+	{
+		if (value->data.string_data != NULL)
+			g_free(value->data.string_data);
+	}
+
+	g_free(value);
+}
+
+GaimType
+gaim_value_get_type(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, GAIM_TYPE_UNKNOWN);
+
+	return value->type;
+}
+
+unsigned int
+gaim_value_get_subtype(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+	g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_SUBTYPE, 0);
+
+	return value->u.subtype;
+}
+
+const char *
+gaim_value_get_specific_type(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, NULL);
+	g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_BOXED, NULL);
+
+	return value->u.specific_type;
+}
+
+gboolean
+gaim_value_is_outgoing(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, FALSE);
+
+	return (value->flags & OUTGOING_FLAG);
+}
+
+void
+gaim_value_set_char(GaimValue *value, char data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.char_data = data;
+}
+
+void
+gaim_value_set_uchar(GaimValue *value, unsigned char data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.uchar_data = data;
+}
+
+void
+gaim_value_set_boolean(GaimValue *value, gboolean data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.boolean_data = data;
+}
+
+void
+gaim_value_set_short(GaimValue *value, short data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.short_data = data;
+}
+
+void
+gaim_value_set_ushort(GaimValue *value, unsigned short data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.ushort_data = data;
+}
+
+void
+gaim_value_set_int(GaimValue *value, int data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.int_data = data;
+}
+
+void
+gaim_value_set_uint(GaimValue *value, unsigned int data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.int_data = data;
+}
+
+void
+gaim_value_set_long(GaimValue *value, long data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.long_data = data;
+}
+
+void
+gaim_value_set_ulong(GaimValue *value, unsigned long data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.long_data = data;
+}
+
+void
+gaim_value_set_int64(GaimValue *value, gint64 data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.int64_data = data;
+}
+
+void
+gaim_value_set_uint64(GaimValue *value, guint64 data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.uint64_data = data;
+}
+
+void
+gaim_value_set_string(GaimValue *value, const char *data)
+{
+	g_return_if_fail(value != NULL);
+
+	if (value->data.string_data != NULL)
+		g_free(value->data.string_data);
+
+	value->data.string_data = (data == NULL ? NULL : g_strdup(data));
+}
+
+void
+gaim_value_set_object(GaimValue *value, void *data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.object_data = data;
+}
+
+void
+gaim_value_set_pointer(GaimValue *value, void *data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.pointer_data = data;
+}
+
+void
+gaim_value_set_enum(GaimValue *value, int data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.enum_data = data;
+}
+
+void
+gaim_value_set_boxed(GaimValue *value, void *data)
+{
+	g_return_if_fail(value != NULL);
+
+	value->data.boxed_data = data;
+}
+
+char
+gaim_value_get_char(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+
+	return value->data.char_data;
+}
+
+unsigned char
+gaim_value_get_uchar(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+
+	return value->data.uchar_data;
+}
+
+gboolean
+gaim_value_get_boolean(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, FALSE);
+
+	return value->data.boolean_data;
+}
+
+short
+gaim_value_get_short(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+
+	return value->data.short_data;
+}
+
+unsigned short
+gaim_value_get_ushort(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+
+	return value->data.ushort_data;
+}
+
+int
+gaim_value_get_int(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+
+	return value->data.int_data;
+}
+
+unsigned int
+gaim_value_get_uint(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+
+	return value->data.int_data;
+}
+
+long
+gaim_value_get_long(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+
+	return value->data.long_data;
+}
+
+unsigned long
+gaim_value_get_ulong(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+
+	return value->data.long_data;
+}
+
+gint64
+gaim_value_get_int64(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+
+	return value->data.int64_data;
+}
+
+guint64
+gaim_value_get_uint64(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, 0);
+
+	return value->data.uint64_data;
+}
+
+const char *
+gaim_value_get_string(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, NULL);
+
+	return value->data.string_data;
+}
+
+void *
+gaim_value_get_object(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, NULL);
+
+	return value->data.object_data;
+}
+
+void *
+gaim_value_get_pointer(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, NULL);
+
+	return value->data.pointer_data;
+}
+
+int
+gaim_value_get_enum(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, -1);
+
+	return value->data.enum_data;
+}
+
+void *
+gaim_value_get_boxed(const GaimValue *value)
+{
+	g_return_val_if_fail(value != NULL, NULL);
+
+	return value->data.boxed_data;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/value.h	Thu Aug 21 20:29:33 2003 +0000
@@ -0,0 +1,446 @@
+/**
+ * @file value.h Value wrapper API
+ * @ingroup core
+ *
+ * gaim
+ *
+ * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#ifndef _GAIM_VALUE_H_
+#define _GAIM_VALUE_H_
+
+/**
+ * Specific value types.
+ */
+typedef enum
+{
+	GAIM_TYPE_UNKNOWN = 0,  /**< Unknown type.                     */
+	GAIM_TYPE_SUBTYPE,      /**< Subtype.                          */
+	GAIM_TYPE_CHAR,         /**< Character.                        */
+	GAIM_TYPE_UCHAR,        /**< Unsigned character.               */
+	GAIM_TYPE_BOOLEAN,      /**< Boolean.                          */
+	GAIM_TYPE_SHORT,        /**< Short integer.                    */
+	GAIM_TYPE_USHORT,       /**< Unsigned short integer.           */
+	GAIM_TYPE_INT,          /**< Integer.                          */
+	GAIM_TYPE_UINT,         /**< Unsigned integer.                 */
+	GAIM_TYPE_LONG,         /**< Long integer.                     */
+	GAIM_TYPE_ULONG,        /**< Unsigned long integer.            */
+	GAIM_TYPE_INT64,        /**< 64-bit integer.                   */
+	GAIM_TYPE_UINT64,       /**< 64-bit unsigned integer.          */
+	GAIM_TYPE_STRING,       /**< String.                           */
+	GAIM_TYPE_OBJECT,       /**< Object pointer.                   */
+	GAIM_TYPE_POINTER,      /**< Generic pointer.                  */
+	GAIM_TYPE_ENUM,         /**< Enum.                             */
+	GAIM_TYPE_BOXED         /**< Boxed pointer with specific type. */
+
+} GaimType;
+
+/**
+ * A wrapper for a type, subtype, and specific type of value.
+ */
+typedef struct
+{
+	GaimType type;
+	unsigned short flags;
+
+	union
+	{
+		char char_data;
+		unsigned char uchar_data;
+		gboolean boolean_data;
+		short short_data;
+		unsigned short ushort_data;
+		int int_data;
+		unsigned int uint_data;
+		long long_data;
+		unsigned long ulong_data;
+		gint64 int64_data;
+		guint64 uint64_data;
+		char *string_data;
+		void *object_data;
+		void *pointer_data;
+		int enum_data;
+		void *boxed_data;
+
+	} data;
+
+	union
+	{
+		unsigned int subtype;
+		char *specific_type;
+
+	} u;
+
+} GaimValue;
+
+/**
+ * Creates a new GaimValue.
+ *
+ * This function takes a type and, depending on that type, a sub-type
+ * or specific type.
+ *
+ * If @a type is GAIM_TYPE_POINTER, the next parameter must be a
+ * string representing the specific type.
+ *
+ * If @a type is GAIM_TYPE_SUBTYPE, the next parameter must be a
+ * integer or enum representing the sub-type.
+ *
+ * If the subtype or specific type is not set when required, random
+ * errors may occur. You have been warned.
+ *
+ * @param type The type.
+ *
+ * @return The new value.
+ */
+GaimValue *gaim_value_new(GaimType type, ...);
+
+/**
+ * Creates a new outgoing GaimValue.
+ *
+ * This function takes a type and, depending on that type, a sub-type
+ * or specific type.
+ *
+ * If @a type is GAIM_TYPE_POINTER, the next parameter must be a
+ * string representing the specific type.
+ *
+ * If @a type is GAIM_TYPE_SUBTYPE, the next parameter must be a
+ * integer or enum representing the sub-type.
+ *
+ * If the sub-type or specific type is not set when required, random
+ * errors may occur. You have been warned.
+ *
+ * @param type The type.
+ *
+ * @return The new value.
+ */
+GaimValue *gaim_value_new_outgoing(GaimType type, ...);
+
+/**
+ * Destroys a GaimValue.
+ *
+ * @param value The value to destroy.
+ */
+void gaim_value_destroy(GaimValue *value);
+
+/**
+ * Returns a value's type.
+ *
+ * @return The value's type.
+ */
+GaimType gaim_value_get_type(const GaimValue *value);
+
+/**
+ * Returns a value's subtype.
+ *
+ * If the value's type is not GAIM_TYPE_SUBTYPE, this will return 0.
+ * Subtypes should never have a subtype of 0.
+ *
+ * @return The value's subtype, or 0 if @a type is not GAIM_TYPE_SUBTYPE.
+ */
+unsigned int gaim_value_get_subtype(const GaimValue *value);
+
+/**
+ * Returns a value's specific type.
+ *
+ * If the value's type is not GAIM_TYPE_BOXED, this will return @c NULL.
+ *
+ * @return The value's specific type, or @a NULL if not GAIM_TYPE_BOXED.
+ */
+const char *gaim_value_get_specific_type(const GaimValue *value);
+
+/**
+ * Returns whether or not the value is an outgoing value.
+ *
+ * @param value The value.
+ *
+ * @return TRUE if the value is outgoing, or FALSE otherwise.
+ */
+gboolean gaim_value_is_outgoing(const GaimValue *value);
+
+/**
+ * Sets the value's character data.
+ *
+ * @param value The value.
+ * @param data The character data.
+ */
+void gaim_value_set_char(GaimValue *value, char data);
+
+/**
+ * Sets the value's unsigned character data.
+ *
+ * @param value The value.
+ * @param data The unsigned character data.
+ */
+void gaim_value_set_uchar(GaimValue *value, unsigned char data);
+
+/**
+ * Sets the value's boolean data.
+ *
+ * @param value The value.
+ * @param data The boolean data.
+ */
+void gaim_value_set_boolean(GaimValue *value, gboolean data);
+
+/**
+ * Sets the value's short integer data.
+ *
+ * @param value The value.
+ * @param data The short integer data.
+ */
+void gaim_value_set_short(GaimValue *value, short data);
+
+/**
+ * Sets the value's unsigned short integer data.
+ *
+ * @param value The value.
+ * @param data The unsigned short integer data.
+ */
+void gaim_value_set_ushort(GaimValue *value, unsigned short data);
+
+/**
+ * Sets the value's integer data.
+ *
+ * @param value The value.
+ * @param data The integer data.
+ */
+void gaim_value_set_int(GaimValue *value, int data);
+
+/**
+ * Sets the value's unsigned integer data.
+ *
+ * @param value The value.
+ * @param data The unsigned integer data.
+ */
+void gaim_value_set_uint(GaimValue *value, unsigned int data);
+
+/**
+ * Sets the value's long integer data.
+ *
+ * @param value The value.
+ * @param data The long integer data.
+ */
+void gaim_value_set_long(GaimValue *value, long data);
+
+/**
+ * Sets the value's unsigned long integer data.
+ *
+ * @param value The value.
+ * @param data The unsigned long integer data.
+ */
+void gaim_value_set_ulong(GaimValue *value, unsigned long data);
+
+/**
+ * Sets the value's 64-bit integer data.
+ *
+ * @param value The value.
+ * @param data The 64-bit integer data.
+ */
+void gaim_value_set_int64(GaimValue *value, gint64 data);
+
+/**
+ * Sets the value's unsigned 64-bit integer data.
+ *
+ * @param value The value.
+ * @param data The unsigned 64-bit integer data.
+ */
+void gaim_value_set_uint64(GaimValue *value, guint64 data);
+
+/**
+ * Sets the value's string data.
+ *
+ * @param value The value.
+ * @param data The string data.
+ */
+void gaim_value_set_string(GaimValue *value, const char *data);
+
+/**
+ * Sets the value's object data.
+ *
+ * @param value The value.
+ * @param data The object data.
+ */
+void gaim_value_set_object(GaimValue *value, void *data);
+
+/**
+ * Sets the value's pointer data.
+ *
+ * @param value The value.
+ * @param data The pointer data.
+ */
+void gaim_value_set_pointer(GaimValue *value, void *data);
+
+/**
+ * Sets the value's enum data.
+ *
+ * @param value The value.
+ * @param data The enum data.
+ */
+void gaim_value_set_enum(GaimValue *value, int data);
+
+/**
+ * Sets the value's boxed data.
+ *
+ * @param value The value.
+ * @param data The boxed data.
+ */
+void gaim_value_set_boxed(GaimValue *value, void *data);
+
+/**
+ * Returns the value's character data.
+ *
+ * @param value The value.
+ *
+ * @return The character data.
+ */
+char gaim_value_get_char(const GaimValue *value);
+
+/**
+ * Returns the value's unsigned character data.
+ *
+ * @param value The value.
+ *
+ * @return The unsigned character data.
+ */
+unsigned char gaim_value_get_uchar(const GaimValue *value);
+
+/**
+ * Returns the value's boolean data.
+ *
+ * @param value The value.
+ *
+ * @return The boolean data.
+ */
+gboolean gaim_value_get_boolean(const GaimValue *value);
+
+/**
+ * Returns the value's short integer data.
+ *
+ * @param value The value.
+ *
+ * @return The short integer data.
+ */
+short gaim_value_get_short(const GaimValue *value);
+
+/**
+ * Returns the value's unsigned short integer data.
+ *
+ * @param value The value.
+ *
+ * @return The unsigned short integer data.
+ */
+unsigned short gaim_value_get_ushort(const GaimValue *value);
+
+/**
+ * Returns the value's integer data.
+ *
+ * @param value The value.
+ *
+ * @return The integer data.
+ */
+int gaim_value_get_int(const GaimValue *value);
+
+/**
+ * Returns the value's unsigned integer data.
+ *
+ * @param value The value.
+ *
+ * @return The unsigned integer data.
+ */
+unsigned int gaim_value_get_uint(const GaimValue *value);
+
+/**
+ * Returns the value's long integer data.
+ *
+ * @param value The value.
+ *
+ * @return The long integer data.
+ */
+long gaim_value_get_long(const GaimValue *value);
+
+/**
+ * Returns the value's unsigned long integer data.
+ *
+ * @param value The value.
+ *
+ * @return The unsigned long integer data.
+ */
+unsigned long gaim_value_get_ulong(const GaimValue *value);
+
+/**
+ * Returns the value's 64-bit integer data.
+ *
+ * @param value The value.
+ *
+ * @return The 64-bit integer data.
+ */
+gint64 gaim_value_get_int64(const GaimValue *value);
+
+/**
+ * Returns the value's unsigned 64-bit integer data.
+ *
+ * @param value The value.
+ *
+ * @return The unsigned 64-bit integer data.
+ */
+guint64 gaim_value_get_uint64(const GaimValue *value);
+
+/**
+ * Returns the value's string data.
+ *
+ * @param value The value.
+ *
+ * @return The string data.
+ */
+const char *gaim_value_get_string(const GaimValue *value);
+
+/**
+ * Returns the value's object data.
+ *
+ * @param value The value.
+ *
+ * @return The object data.
+ */
+void *gaim_value_get_object(const GaimValue *value);
+
+/**
+ * Returns the value's pointer data.
+ *
+ * @param value The value.
+ *
+ * @return The pointer data.
+ */
+void *gaim_value_get_pointer(const GaimValue *value);
+
+/**
+ * Returns the value's enum data.
+ *
+ * @param value The value.
+ *
+ * @return The enum data.
+ */
+int gaim_value_get_enum(const GaimValue *value);
+
+/**
+ * Returns the value's boxed data.
+ *
+ * @param value The value.
+ *
+ * @return The boxed data.
+ */
+void *gaim_value_get_boxed(const GaimValue *value);
+
+#endif /* _GAIM_VALUE_H_ */