diff options
-rw-r--r-- | docs/reference/telepathy-glib-docs.sgml | 1 | ||||
-rw-r--r-- | docs/reference/telepathy-glib-sections.txt | 25 | ||||
-rw-r--r-- | telepathy-glib/Makefile.am | 3 | ||||
-rw-r--r-- | telepathy-glib/debug-message-internal.h | 31 | ||||
-rw-r--r-- | telepathy-glib/debug-message.c | 295 | ||||
-rw-r--r-- | telepathy-glib/debug-message.h | 75 |
6 files changed, 430 insertions, 0 deletions
diff --git a/docs/reference/telepathy-glib-docs.sgml b/docs/reference/telepathy-glib-docs.sgml index e6c2c6b0c..e3aa13b9d 100644 --- a/docs/reference/telepathy-glib-docs.sgml +++ b/docs/reference/telepathy-glib-docs.sgml @@ -99,6 +99,7 @@ <xi:include href="xml/call-stream.xml"/> <xi:include href="xml/call-misc.xml"/> <xi:include href="xml/debug-client.xml"/> + <xi:include href="xml/debug-message.xml"/> </chapter> <chapter id="ch-service-dbus"> diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 6b7c09270..1cac5adec 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -7205,3 +7205,28 @@ tp_debug_client_get_feature_quark_core <SUBSECTION Private> TpDebugClientPrivate </SECTION> + +<SECTION> +<INCLUDE>telepathy-glib/telepathy-glib.h</INCLUDE> +<FILE>debug-message</FILE> +<TITLE>TpDebugMessage</TITLE> +<SUBSECTION> +TpDebugMessage +TpDebugMessageClass +tp_debug_client_get_messages_async +tp_debug_client_get_messages_finish +tp_debug_message_get_domain +tp_debug_message_get_level +tp_debug_message_get_message +tp_debug_message_get_time +<SUBSECTION Standard> +TP_DEBUG_MESSAGE +TP_DEBUG_MESSAGE_CLASS +TP_DEBUG_MESSAGE_GET_CLASS +TP_IS_DEBUG_MESSAGE +TP_IS_DEBUG_MESSAGE_CLASS +TP_TYPE_DEBUG_MESSAGE +tp_debug_message_get_type +<SUBSECTION Private> +TpDebugMessagePriv +</SECTION> diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am index 41a13813a..ea0d651f1 100644 --- a/telepathy-glib/Makefile.am +++ b/telepathy-glib/Makefile.am @@ -79,6 +79,7 @@ our_headers = \ debug-sender.h \ debug-client.h \ debug-ansi.h \ + debug-message.h \ dtmf.h \ enums.h \ errors.h \ @@ -238,6 +239,8 @@ libtelepathy_glib_internal_la_SOURCES = \ debug.c \ debug-client.c \ debug-sender.c \ + debug-message.c \ + debug-message-internal.h \ deprecated-internal.h \ dtmf.c \ interfaces.c \ diff --git a/telepathy-glib/debug-message-internal.h b/telepathy-glib/debug-message-internal.h new file mode 100644 index 000000000..56039d7f7 --- /dev/null +++ b/telepathy-glib/debug-message-internal.h @@ -0,0 +1,31 @@ +/* + * debug-message-internal.h + * + * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __TP_DEBUG_MESSAGE_INTERNAL_H__ +#define __TP_DEBUG_MESSAGE_INTERNAL_H__ + +#include <telepathy-glib/telepathy-glib.h> + +TpDebugMessage * _tp_debug_message_new (gdouble timestamp, + const gchar *domain, + TpDebugLevel level, + const gchar *message); + +#endif diff --git a/telepathy-glib/debug-message.c b/telepathy-glib/debug-message.c new file mode 100644 index 000000000..463df392e --- /dev/null +++ b/telepathy-glib/debug-message.c @@ -0,0 +1,295 @@ +/* + * debug-message.c + * + * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include "config.h" + +#include "debug-message.h" +#include "debug-message-internal.h" + +#include <telepathy-glib/telepathy-glib.h> + +/** + * SECTION: debug-message + * @title: TpDebugMessage + * @short_description: a debug message + * + * #TpDebugMessage is a small object used to represent a debug message receive + * from a Telepathy component using #TpDebugClient. + * + * See also: #TpDebugClient + */ + +/** + * TpDebugMessage: + * + * Data structure representing a #TpDebugMessage. + * + * Since: UNRELEASED + */ + +/** + * TpDebugMessageClass: + * + * The class of a #TpDebugMessage. + * + * Since: UNRELEASED + */ + +G_DEFINE_TYPE (TpDebugMessage, tp_debug_message, G_TYPE_OBJECT) + +enum { + PROP_TIME = 1, + PROP_DOMAIN, + PROP_LEVEL, + PROP_MESSAGE, + LAST_PROPERTY, +}; + +struct _TpDebugMessagePriv { + GDateTime *time; + gchar *domain; + GLogLevelFlags level; + gchar *message; +}; + +static void +tp_debug_message_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + TpDebugMessage *self = TP_DEBUG_MESSAGE (object); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + case PROP_TIME: + g_value_set_boxed (value, self->priv->time); + break; + case PROP_DOMAIN: + g_value_set_string (value, self->priv->domain); + break; + case PROP_LEVEL: + g_value_set_uint (value, self->priv->level); + break; + case PROP_MESSAGE: + g_value_set_string (value, self->priv->message); + break; + } +} + +static void +tp_debug_message_finalize (GObject *object) +{ + TpDebugMessage *self = TP_DEBUG_MESSAGE (object); + void (*chain_up) (GObject *) = + ((GObjectClass *) tp_debug_message_parent_class)->finalize; + + g_free (self->priv->domain); + g_free (self->priv->message); + + if (chain_up != NULL) + chain_up (object); +} + +static void +tp_debug_message_class_init ( + TpDebugMessageClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + GParamSpec *spec; + + oclass->get_property = tp_debug_message_get_property; + oclass->finalize = tp_debug_message_finalize; + + /** + * TpDebugMessage:time: + * + * Timestamp of the debug message. + * + * Since: UNRELEASED + */ + spec = g_param_spec_boxed ("time", "time", + "Time", + G_TYPE_DATE_TIME, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (oclass, PROP_TIME, spec); + + /** + * TpDebugMessage:domain: + * + * Domain of the debug message. + * + * Since: UNRELEASED + */ + spec = g_param_spec_string ("domain", "domain", + "Domain", + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (oclass, PROP_DOMAIN, spec); + + /** + * TpDebugMessage:level: + * + * A #GLogLevelFlags representing the level of the debug message. + * + * Since: UNRELEASED + */ + spec = g_param_spec_uint ("level", "level", + "Level", + 0, G_LOG_LEVEL_MASK, 0, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (oclass, PROP_LEVEL, spec); + + /** + * TpDebugMessage:message: + * + * Text of the debug message + * + * Since: UNRELEASED + */ + spec = g_param_spec_string ("message", "message", + "Message", + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (oclass, PROP_MESSAGE, spec); + + g_type_class_add_private (klass, sizeof (TpDebugMessagePriv)); +} + +static void +tp_debug_message_init (TpDebugMessage *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + TP_TYPE_DEBUG_MESSAGE, TpDebugMessagePriv); +} + +static GLogLevelFlags +debug_level_to_log_level_flags (TpDebugLevel level) +{ + if (level == TP_DEBUG_LEVEL_ERROR) + return G_LOG_LEVEL_ERROR; + else if (level == TP_DEBUG_LEVEL_CRITICAL) + return G_LOG_LEVEL_CRITICAL; + else if (level == TP_DEBUG_LEVEL_WARNING) + return G_LOG_LEVEL_WARNING; + else if (level == TP_DEBUG_LEVEL_MESSAGE) + return G_LOG_LEVEL_MESSAGE; + else if (level == TP_DEBUG_LEVEL_INFO) + return G_LOG_LEVEL_INFO; + else if (level == TP_DEBUG_LEVEL_DEBUG) + return G_LOG_LEVEL_DEBUG; + + /* Fall back to DEBUG if all else fails */ + return TP_DEBUG_LEVEL_DEBUG; +} + +TpDebugMessage * +_tp_debug_message_new (gdouble timestamp, + const gchar *domain, + TpDebugLevel level, + const gchar *message) +{ + TpDebugMessage *self; + GTimeVal tv; + + g_return_val_if_fail (domain != NULL, NULL); + g_return_val_if_fail (message != NULL, NULL); + + self = g_object_new (TP_TYPE_DEBUG_MESSAGE, + NULL); + + tv.tv_sec = (glong) timestamp; + tv.tv_usec = ((timestamp - (int) timestamp) * 1e6); + + self->priv->time = g_date_time_new_from_timeval_utc (&tv); + self->priv->domain = g_strdup (domain); + self->priv->level = debug_level_to_log_level_flags (level); + self->priv->message = g_strdup (message); + + return self; +} + +/** + * tp_debug_message_get_time: + * @self: a #TpDebugMessage + * + * Return the #TpDebugMessage:time property + * + * Returns: (transfer none): the value of #TpDebugMessage:time property + * + * Since: UNRELEASED + */ +GDateTime * +tp_debug_message_get_time (TpDebugMessage *self) +{ + return self->priv->time; +} + +/** + * tp_debug_message_get_domain: + * @self: a #TpDebugMessage + * + * Return the #TpDebugMessage:domain property + * + * Returns: the value of #TpDebugMessage:domain property + * + * Since: UNRELEASED + */ +const gchar * +tp_debug_message_get_domain (TpDebugMessage *self) +{ + return self->priv->domain; +} + +/** + * tp_debug_message_get_level: + * @self: a #TpDebugMessage + * + * Return the #TpDebugMessage:level property + * + * Returns: the value of #TpDebugMessage:level property + * + * Since: UNRELEASED + */ +GLogLevelFlags +tp_debug_message_get_level (TpDebugMessage *self) +{ + return self->priv->level; +} + +/** + * tp_debug_message_get_message: + * @self: a #TpDebugMessage + * + * Return the #TpDebugMessage:message property + * + * Returns: the value of #TpDebugMessage:message property + * + * Since: UNRELEASED + */ +const gchar * +tp_debug_message_get_message (TpDebugMessage *self) +{ + return self->priv->message; +} diff --git a/telepathy-glib/debug-message.h b/telepathy-glib/debug-message.h new file mode 100644 index 000000000..8d6d0b6fb --- /dev/null +++ b/telepathy-glib/debug-message.h @@ -0,0 +1,75 @@ +/* + * debug-message.h + * + * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef __TP_DEBUG_MESSAGE_H__ +#define __TP_DEBUG_MESSAGE_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +typedef struct _TpDebugMessage TpDebugMessage; +typedef struct _TpDebugMessageClass TpDebugMessageClass; +typedef struct _TpDebugMessagePriv TpDebugMessagePriv; + +struct _TpDebugMessageClass { + /*<private>*/ + GObjectClass parent_class; +}; + +struct _TpDebugMessage { + /*<private>*/ + GObject parent; + TpDebugMessagePriv *priv; +}; + +GType tp_debug_message_get_type (void); + +/* TYPE MACROS */ +#define TP_TYPE_DEBUG_MESSAGE \ + (tp_debug_message_get_type ()) +#define TP_DEBUG_MESSAGE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + TP_TYPE_DEBUG_MESSAGE, \ + TpDebugMessage)) +#define TP_DEBUG_MESSAGE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + TP_TYPE_DEBUG_MESSAGE, \ + TpDebugMessageClass)) +#define TP_IS_DEBUG_MESSAGE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + TP_TYPE_DEBUG_MESSAGE)) +#define TP_IS_DEBUG_MESSAGE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + TP_TYPE_DEBUG_MESSAGE)) +#define TP_DEBUG_MESSAGE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + TP_TYPE_DEBUG_MESSAGE, \ + TpDebugMessageClass)) + +GDateTime * tp_debug_message_get_time (TpDebugMessage *self); +const gchar * tp_debug_message_get_domain (TpDebugMessage *self); +GLogLevelFlags tp_debug_message_get_level (TpDebugMessage *self); +const gchar * tp_debug_message_get_message (TpDebugMessage *self); + +G_END_DECLS + +#endif /* #ifndef __TP_DEBUG_MESSAGE_H__*/ |