summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEitan Isaacson <eitan@monotonous.org>2010-12-08 19:31:38 (GMT)
committerEitan Isaacson <eitan@monotonous.org>2010-12-10 21:11:40 (GMT)
commit1274d465b78a69de499719e3567a9754eb8532dc (patch)
tree93587f5dfb7f54a28f2a5b6a9678f0c2ea5bcfbf
parent3ef08d23bfe44bb9ace99729c5641102db2a8979 (diff)
downloadtelepathy-gabble-1274d465b78a69de499719e3567a9754eb8532dc.tar.gz
telepathy-gabble-1274d465b78a69de499719e3567a9754eb8532dc.tar.xz
Use GEnum fro jingle reasons.
-rw-r--r--src/Makefile.am12
-rw-r--r--src/jingle-factory.h14
-rw-r--r--src/jingle-session.c98
3 files changed, 25 insertions, 99 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7217a0b..b8bdf00 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -190,6 +190,10 @@ libgabble_convenience_la_SOURCES = \
vcard-manager.h \
vcard-manager.c
+enumtype_sources = \
+ jingle-factory.h \
+ presence.h
+
libgabble_convenience_la_LIBADD = \
$(top_builddir)/extensions/libgabble-extensions.la \
$(top_builddir)/lib/gibber/libgibber.la \
@@ -257,19 +261,19 @@ gabble-signals-marshal.list: $(libgabble_convenience_la_SOURCES) Makefile.am
} > $@
# rules for making the glib enum objects
-gabble-enumtypes.h: presence.h Makefile.in
+gabble-enumtypes.h: $(enumtype_sources) Makefile.in
$(AM_V_GEN)glib-mkenums \
--fhead "#ifndef __GABBLE_ENUM_TYPES_H__\n#define __GABBLE_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \
--fprod "/* enumerations from \"@filename@\" */\n" \
--vhead "GType @enum_name@_get_type (void);\n#define GABBLE_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \
--ftail "G_END_DECLS\n\n#endif /* __GABBLE_ENUM_TYPES_H__ */" \
- $< > $@
+ $(enumtype_sources) > $@
-gabble-enumtypes.c: presence.h Makefile.in
+gabble-enumtypes.c: $(enumtype_sources) Makefile.in
$(AM_V_GEN)glib-mkenums \
--fhead "#include <$*.h>" \
--fprod "\n/* enumerations from \"@filename@\" */\n#include \"@filename@\"" \
--vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \
--vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
--vtail " { 0, NULL, NULL }\n };\n etype = g_@type@_register_static (\"@EnumName@\", values);\n }\n return etype;\n}\n" \
- $< > $@
+ $(enumtype_sources) > $@
diff --git a/src/jingle-factory.h b/src/jingle-factory.h
index 687b3dc..6256305 100644
--- a/src/jingle-factory.h
+++ b/src/jingle-factory.h
@@ -26,7 +26,7 @@
G_BEGIN_DECLS
-typedef enum {
+typedef enum { /*< skip >*/
/* not a jingle message */
JINGLE_DIALECT_ERROR,
/* old libjingle3 gtalk variant */
@@ -42,7 +42,7 @@ typedef enum {
#define JINGLE_IS_GOOGLE_DIALECT(d)\
((d == JINGLE_DIALECT_GTALK3) || (d == JINGLE_DIALECT_GTALK4))
-typedef enum {
+typedef enum { /*< skip >*/
JINGLE_STATE_INVALID = -1,
JINGLE_STATE_PENDING_CREATED = 0,
JINGLE_STATE_PENDING_INITIATE_SENT,
@@ -53,7 +53,7 @@ typedef enum {
MAX_JINGLE_STATES
} JingleState;
-typedef enum {
+typedef enum { /*< skip >*/
JINGLE_ACTION_UNKNOWN,
JINGLE_ACTION_CONTENT_ACCEPT,
JINGLE_ACTION_CONTENT_ADD,
@@ -71,26 +71,26 @@ typedef enum {
JINGLE_ACTION_INFO
} JingleAction;
-typedef enum {
+typedef enum { /*< skip >*/
JINGLE_CONTENT_SENDERS_NONE,
JINGLE_CONTENT_SENDERS_INITIATOR,
JINGLE_CONTENT_SENDERS_RESPONDER,
JINGLE_CONTENT_SENDERS_BOTH
} JingleContentSenders;
-typedef enum {
+typedef enum { /*< skip >*/
JINGLE_TRANSPORT_UNKNOWN,
JINGLE_TRANSPORT_GOOGLE_P2P,
JINGLE_TRANSPORT_RAW_UDP,
JINGLE_TRANSPORT_ICE_UDP,
} JingleTransportType;
-typedef enum {
+typedef enum { /*< skip >*/
JINGLE_TRANSPORT_PROTOCOL_UDP,
JINGLE_TRANSPORT_PROTOCOL_TCP
} JingleTransportProtocol;
-typedef enum {
+typedef enum { /*< skip >*/
JINGLE_CANDIDATE_TYPE_LOCAL,
JINGLE_CANDIDATE_TYPE_STUN,
JINGLE_CANDIDATE_TYPE_RELAY
diff --git a/src/jingle-session.c b/src/jingle-session.c
index 9b508ae..b4701fc 100644
--- a/src/jingle-session.c
+++ b/src/jingle-session.c
@@ -26,6 +26,7 @@
#include <loudmouth/loudmouth.h>
#include <telepathy-glib/handle-repo-dynamic.h>
+#include <wocky/wocky-utils.h>
#define DEBUG_FLAG GABBLE_DEBUG_MEDIA
@@ -34,6 +35,7 @@
#include "conn-presence.h"
#include "debug.h"
#include "gabble-signals-marshal.h"
+#include "gabble-enumtypes.h"
#include "jingle-content.h"
#include "jingle-factory.h"
/* FIXME: the RTP-specific bits of this file should be separated from the
@@ -492,50 +494,6 @@ typedef void (*ContentHandlerFunc)(GabbleJingleSession *sess,
GabbleJingleContent *c, LmMessageNode *content_node, gpointer user_data,
GError **error);
-static JingleReason
-parse_reason (const gchar *txt)
-{
- if (txt == NULL)
- return JINGLE_REASON_UNKNOWN;
-
- if (!tp_strdiff (txt, "alternative-session"))
- return JINGLE_REASON_ALTERNATIVE_SESSION;
- if (!tp_strdiff (txt, "busy"))
- return JINGLE_REASON_BUSY;
- if (!tp_strdiff (txt, "cancel"))
- return JINGLE_REASON_CANCEL;
- if (!tp_strdiff (txt, "connectivity-error"))
- return JINGLE_REASON_CONNECTIVITY_ERROR;
- if (!tp_strdiff (txt, "decline"))
- return JINGLE_REASON_DECLINE;
- if (!tp_strdiff (txt, "expired"))
- return JINGLE_REASON_EXPIRED;
- if (!tp_strdiff (txt, "failed-application"))
- return JINGLE_REASON_FAILED_APPLICATION;
- if (!tp_strdiff (txt, "failed-transport"))
- return JINGLE_REASON_FAILED_TRANSPORT;
- if (!tp_strdiff (txt, "general-error"))
- return JINGLE_REASON_GENERAL_ERROR;
- if (!tp_strdiff (txt, "gone"))
- return JINGLE_REASON_GONE;
- if (!tp_strdiff (txt, "incompatible-parameters"))
- return JINGLE_REASON_INCOMPATIBLE_PARAMETERS;
- if (!tp_strdiff (txt, "media-error"))
- return JINGLE_REASON_MEDIA_ERROR;
- if (!tp_strdiff (txt, "security-error"))
- return JINGLE_REASON_SECURITY_ERROR;
- if (!tp_strdiff (txt, "success"))
- return JINGLE_REASON_SUCCESS;
- if (!tp_strdiff (txt, "timeout"))
- return JINGLE_REASON_TIMEOUT;
- if (!tp_strdiff (txt, "unsupported-applications"))
- return JINGLE_REASON_UNSUPPORTED_APPLICATIONS;
- if (!tp_strdiff (txt, "unsupported-transports"))
- return JINGLE_REASON_UNSUPPORTED_TRANSPORTS;
-
- return JINGLE_REASON_UNKNOWN;
-}
-
static gboolean
extract_reason (WockyNode *node, JingleReason *reason, gchar **message)
{
@@ -552,9 +510,8 @@ extract_reason (WockyNode *node, JingleReason *reason, gchar **message)
while (wocky_node_iter_next (&iter, &child))
{
- _reason = parse_reason (child->name);
-
- if (_reason != JINGLE_REASON_UNKNOWN)
+ if (wocky_enum_from_nick (
+ jingle_reason_get_type (), child->name, (gint *) &_reason))
{
if (reason != NULL)
*reason = _reason;
@@ -2063,47 +2020,12 @@ gabble_jingle_session_accept (GabbleJingleSession *sess)
const gchar *
gabble_jingle_session_get_reason_name (JingleReason reason)
{
- switch (reason)
- {
- case JINGLE_REASON_UNKNOWN:
- return "unknown";
- case JINGLE_REASON_ALTERNATIVE_SESSION:
- return "alternative-session";
- case JINGLE_REASON_BUSY:
- return "busy";
- case JINGLE_REASON_CANCEL:
- return "cancel";
- case JINGLE_REASON_CONNECTIVITY_ERROR:
- return "connectivity-error";
- case JINGLE_REASON_DECLINE:
- return "decline";
- case JINGLE_REASON_EXPIRED:
- return "expired";
- case JINGLE_REASON_FAILED_APPLICATION:
- return "failed-application";
- case JINGLE_REASON_FAILED_TRANSPORT:
- return "failed-transport";
- case JINGLE_REASON_GENERAL_ERROR:
- return "general-error";
- case JINGLE_REASON_GONE:
- return "gone";
- case JINGLE_REASON_INCOMPATIBLE_PARAMETERS:
- return "incompatible-parameters";
- case JINGLE_REASON_MEDIA_ERROR:
- return "media-error";
- case JINGLE_REASON_SECURITY_ERROR:
- return "security-error";
- case JINGLE_REASON_SUCCESS:
- return "success";
- case JINGLE_REASON_TIMEOUT:
- return "timeout";
- case JINGLE_REASON_UNSUPPORTED_APPLICATIONS:
- return "unsupported-applications";
- case JINGLE_REASON_UNSUPPORTED_TRANSPORTS:
- return "unsupported-transports";
- default:
- g_assert_not_reached ();
- }
+ GEnumClass *klass = g_type_class_ref (jingle_reason_get_type ());
+ GEnumValue *enum_value = g_enum_get_value (klass, (gint) reason);
+
+ g_return_val_if_fail (enum_value != NULL, NULL);
+
+ return enum_value->value_nick;
}
gboolean