diff options
author | Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 2011-03-21 16:25:59 -0400 |
---|---|---|
committer | Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 2011-03-25 14:03:03 -0400 |
commit | 8d2e6cecb2c07bfecb40095519192d65cbc89707 (patch) | |
tree | a3f978b99d77df43de15474d2aed568a27049818 | |
parent | f69caf20f673750c5a5e6b38a7af18e10c99d4e9 (diff) |
Add TplCallEvent class
-rw-r--r-- | telepathy-logger/Makefile.am | 3 | ||||
-rw-r--r-- | telepathy-logger/call-event-internal.h | 48 | ||||
-rw-r--r-- | telepathy-logger/call-event.c | 274 | ||||
-rw-r--r-- | telepathy-logger/call-event.h | 57 |
4 files changed, 382 insertions, 0 deletions
diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am index 9941f7b..9382acb 100644 --- a/telepathy-logger/Makefile.am +++ b/telepathy-logger/Makefile.am @@ -23,6 +23,7 @@ lib_LTLIBRARIES = libtelepathy-logger.la LIBTPLdir = $(includedir)/telepathy-logger-0.2/telepathy-logger LIBTPL_HEADERS = \ + call-event.h \ entity.h \ event.h \ log-manager.h \ @@ -44,6 +45,8 @@ BUILT_SOURCES = \ libtelepathy_logger_la_SOURCES = \ action-chain.c \ action-chain-internal.h \ + call-event.c \ + call-event-internal.h \ channel-internal.h \ channel.c \ channel-factory.c \ diff --git a/telepathy-logger/call-event-internal.h b/telepathy-logger/call-event-internal.h new file mode 100644 index 0000000..e3a0a51 --- /dev/null +++ b/telepathy-logger/call-event-internal.h @@ -0,0 +1,48 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * 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 + * + * Authors: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> + */ + +#ifndef __TPL_CALL_EVENT_INTERNAL_H__ +#define __TPL_CALL_EVENT_INTERNAL_H__ + +#include <telepathy-logger/call-event.h> +#include <telepathy-logger/event-internal.h> + +G_BEGIN_DECLS + +struct _TplCallEvent +{ + TplEvent parent; + + /* Private */ + TplCallEventPriv *priv; +}; + +struct _TplCallEventClass +{ + TplEventClass parent_class; +}; + +const gchar * _tpl_call_event_end_reason_to_str (TplCallEndReason reason); +TplCallEndReason _tpl_call_event_str_to_end_reason (const gchar *str); + + +G_END_DECLS +#endif // __TPL_CALL_EVENT_INTERNAL_H__ diff --git a/telepathy-logger/call-event.c b/telepathy-logger/call-event.c new file mode 100644 index 0000000..6223d63 --- /dev/null +++ b/telepathy-logger/call-event.c @@ -0,0 +1,274 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * 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 + * + * Authors: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> + */ + +#include "config.h" +#include "call-event.h" +#include "call-event-internal.h" + +#include <glib-object.h> +#include <telepathy-glib/util.h> + +#include "entity.h" +#include "event.h" +#include "event-internal.h" +#include "util-internal.h" + +#define DEBUG_FLAG TPL_DEBUG_LOG_EVENT +#include "debug-internal.h" + +/** + * SECTION:call-event + * @title: TplCallEvent + * @short_description: Representation of a call log event + * + * A subclass of #TplEvent representing a call log event. + */ + +/** + * TplCallEvent: + * + * An object representing a call log event. + */ + +G_DEFINE_TYPE (TplCallEvent, tpl_call_event, TPL_TYPE_EVENT) + +struct _TplCallEventPriv +{ + GTimeSpan duration; + TplEntity *end_actor; + TplCallEndReason end_reason; + gchar *detailed_end_reason; +}; + +enum +{ + PROP_DURATION = 1, + PROP_END_ACTOR, + PROP_END_REASON, + PROP_DETAILED_END_REASON +}; + +static const gchar* end_reasons[] = { + "unknown", + "user-requested", + "no-answer" +}; + + +static void +tpl_call_event_dispose (GObject *object) +{ + TplCallEventPriv *priv = TPL_CALL_EVENT (object)->priv; + + tp_clear_object (&priv->end_actor); + tp_clear_pointer (&priv->detailed_end_reason, g_free); + + G_OBJECT_CLASS (tpl_call_event_parent_class)->dispose (object); +} + + +static void +tpl_call_event_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + TplCallEventPriv *priv = TPL_CALL_EVENT (object)->priv; + + switch (param_id) + { + case PROP_DURATION: + g_value_set_int64 (value, priv->duration); + break; + case PROP_END_ACTOR: + g_value_set_object (value, priv->end_actor); + break; + case PROP_END_REASON: + g_value_set_int (value, priv->end_reason); + break; + case PROP_DETAILED_END_REASON: + g_value_set_string (value, priv->detailed_end_reason); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + + +static void +tpl_call_event_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + TplCallEventPriv *priv = TPL_CALL_EVENT (object)->priv; + + switch (param_id) + { + case PROP_DURATION: + priv->duration = g_value_get_int64 (value); + break; + case PROP_END_ACTOR: + priv->end_actor = g_value_dup_object (value); + break; + case PROP_END_REASON: + priv->end_reason = g_value_get_int (value); + break; + case PROP_DETAILED_END_REASON: + priv->detailed_end_reason = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + +static void tpl_call_event_class_init (TplCallEventClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + object_class->dispose = tpl_call_event_dispose; + object_class->get_property = tpl_call_event_get_property; + object_class->set_property = tpl_call_event_set_property; + + param_spec = g_param_spec_int64 ("duration", + "Duration", + "The call duration in seconds", + -1, G_MAXINT64, 0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_DURATION, param_spec); + + param_spec = g_param_spec_object ("end-actor", + "End Actor", + "Actor (a #TplEntity) that caused the call to end", + TPL_TYPE_ENTITY, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_END_ACTOR, param_spec); + + param_spec = g_param_spec_int ("end-reason", + "End Reason", + "Reason for wich this call was ended", + 0, G_MAXINT, TPL_CALL_END_REASON_UNKNOWN, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_END_REASON, param_spec); + + param_spec = g_param_spec_string ("detailed-end-reason", + "Detailed End Reason", + "A string representing a D-Bus error that gives more details about the end reason", + "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_DETAILED_END_REASON, param_spec); + + g_type_class_add_private (object_class, sizeof (TplCallEventPriv)); +} + + +static void +tpl_call_event_init (TplCallEvent *self) +{ + TplCallEventPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + TPL_TYPE_CALL_EVENT, TplCallEventPriv); + self->priv = priv; +} + + +/** + * tpl_call_event_get_duration: + * @self: a #TplCallEvent + * + * Returns: the same duration as the #TplCallEvent:duration property + */ +GTimeSpan +tpl_call_event_get_duration (TplCallEvent *self) +{ + g_return_val_if_fail (TPL_IS_CALL_EVENT (self), 0); + + return self->priv->duration; +} + +/** + * tpl_call_event_get_end_actor: + * @self: a #TplCallEvent + * + * Returns: (transfer none): the same #TplEntity + * as #TplCallEvent:end-actor property + */ +TplEntity * +tpl_call_event_get_end_actor (TplCallEvent *self) +{ + g_return_val_if_fail (TPL_IS_CALL_EVENT (self), NULL); + + return self->priv->end_actor; +} + + +/** + * tpl_call_event_get_end_reason: + * @self: a #TplCallEvent + * + * Returns: the same #TplCallEndReason as #TplCallEvent:end-actor property + */ +TplCallEndReason +tpl_call_event_get_end_reason (TplCallEvent *self) +{ + g_return_val_if_fail (TPL_IS_CALL_EVENT (self), + TPL_CALL_END_REASON_UNKNOWN); + + return self->priv->end_reason; +} + + +/** + * tpl_call_event_get_detailed_end_reason: + * @self: a #TplCallEvent + * + * Returns: (transfer none): the same string as the + * #TplCallEvent:detailed-end-reason property + */ +const gchar * +tpl_call_event_get_detailed_end_reason (TplCallEvent *self) +{ + g_return_val_if_fail (TPL_IS_CALL_EVENT (self), ""); + + return self->priv->detailed_end_reason; +} + + +const gchar * +_tpl_call_event_end_reason_to_str (TplCallEndReason reason) +{ + g_return_val_if_fail (reason < G_N_ELEMENTS (end_reasons), end_reasons[0]); + return end_reasons[reason]; +} + + +TplCallEndReason +_tpl_call_event_str_to_end_reason (const gchar *str) +{ + guint i; + for (i = 0; i < G_N_ELEMENTS (end_reasons); i++) + if (g_strcmp0 (str, end_reasons[i]) == 0) + return i; + + return TPL_CALL_END_REASON_UNKNOWN; +} diff --git a/telepathy-logger/call-event.h b/telepathy-logger/call-event.h new file mode 100644 index 0000000..99b82d3 --- /dev/null +++ b/telepathy-logger/call-event.h @@ -0,0 +1,57 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * 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 + * + * Authors: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> + */ + +#ifndef __TPL_CALL_EVENT_H__ +#define __TPL_CALL_EVENT_H__ + +#include <glib-object.h> + +#include <telepathy-logger/event.h> + +G_BEGIN_DECLS +#define TPL_TYPE_CALL_EVENT (tpl_call_event_get_type ()) +#define TPL_CALL_EVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CALL_EVENT, TplCallEvent)) +#define TPL_CALL_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CALL_EVENT, TplCallEventClass)) +#define TPL_IS_CALL_EVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CALL_EVENT)) +#define TPL_IS_CALL_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CALL_EVENT)) +#define TPL_CALL_EVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CALL_EVENT, TplCallEventClass)) + +typedef struct _TplCallEvent TplCallEvent; +typedef struct _TplCallEventClass TplCallEventClass; +typedef struct _TplCallEventPriv TplCallEventPriv; + +typedef enum +{ + TPL_CALL_END_REASON_UNKNOWN = 0, + TPL_CALL_END_REASON_USER_REQUESTED, + TPL_CALL_END_REASON_NO_ANSWER, +} TplCallEndReason; + +GType tpl_call_event_get_type (void); + +GTimeSpan tpl_call_event_get_duration (TplCallEvent *self); +TplEntity * tpl_call_event_get_end_actor (TplCallEvent *self); +TplCallEndReason tpl_call_event_get_end_reason (TplCallEvent *self); +const gchar * tpl_call_event_get_detailed_end_reason (TplCallEvent *self); + + +G_END_DECLS +#endif // __TPL_CALL_EVENT_H__ |