diff options
author | Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 2011-02-08 16:56:34 +0000 |
---|---|---|
committer | Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 2011-02-08 16:56:34 +0000 |
commit | 74c45ca9b274ea2368fe210a6ce59d2de9bbabd9 (patch) | |
tree | 2610d28a8438f42cff1c79bd9d1501df055cd99b | |
parent | 9a7fa789f52da6c946a36ac2049016e2ac48f880 (diff) | |
download | telepathy-logger-74c45ca9b274ea2368fe210a6ce59d2de9bbabd9.tar.gz |
Strip off GetRecentsEvents from D-Bus API
-rw-r--r-- | extensions/Logger.xml | 71 | ||||
-rw-r--r-- | src/test-api.c | 43 | ||||
-rw-r--r-- | telepathy-logger/dbus-service.c | 188 |
3 files changed, 2 insertions, 300 deletions
diff --git a/extensions/Logger.xml b/extensions/Logger.xml index bb2a456..0dead83 100644 --- a/extensions/Logger.xml +++ b/extensions/Logger.xml @@ -19,82 +19,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</ </tp:license> <interface name="org.freedesktop.Telepathy.Logger.DRAFT" tp:causes-havoc="experimental"> - <tp:added version="0.2">(as a draft)</tp:added> + <tp:added version="0.3">(as a draft)</tp:added> <tp:docstring> An interface for requesting information from the Telepathy Logger service. </tp:docstring> - <tp:struct name="Chat_Message" array-name="Chat_Message_List"> - <tp:member type="s" name="Sender"> - <tp:docstring> - The identifier of the contact who originated this message. - </tp:docstring> - </tp:member> - - <tp:member type="s" name="Message"> - <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> - The body of the message sent to a 1-1 Chat or a Chat Room. - </tp:docstring> - </tp:member> - - <tp:member type="x" name="Timestamp" tp:type="Unix_Timestamp64"> - <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> - Unix timestamp for the log event - </tp:docstring> - </tp:member> - - <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> - <p>It represents a single message, received or sent.</p> - <p>The receiver is implicit in the request: if the sender is the user, - the receiver is the identifier in chat_id paramenter, if the sender is - not the user, the user is consequently the receiver of the message</p> - </tp:docstring> - </tp:struct> - - <method name="GetRecentEvents" - tp:name-for-bindings="Get_Recent_Events"> - <arg direction="in" name="Account" type="o" tp:type="Account"> - <tp:docstring> - The account path for the TpAccount to which the conversation is related - </tp:docstring> - </arg> - - <arg direction="in" name="Identifier" type="s"> - <tp:docstring> - The buddy's identifier for the conversation - </tp:docstring> - </arg> - - <arg direction="in" name="Type" type="u"> - <tp:docstring> - The type of the events to return. - </tp:docstring> - </arg> - - <arg direction="in" name="Lines" type="u"> - <tp:docstring> - how many entries will be returned. - - NOTE: to retreive information that would generate high traffic, use - the library API approach instead of DBus. - </tp:docstring> - </arg> - - <!-- FIXME: we're returning a list of events that can be - messages (chats), but also calls and any other event - type in the future, so make the return type a list of - TplLogSearchHit or something generic than a(ssx) ? --> - <arg direction="out" name="Messages" type="a(ssx)" - tp:type="Chat_Message[]" /> - - <tp:docstring> - Request the last Lines entries of logs for the specified couple - Account+Identifier. - </tp:docstring> - </method> - <method name="GetFavouriteContacts" tp:name-for-bindings="Get_Favourite_Contacts"> <arg direction="out" name="Favourite_Contacts" type="a(oas)"> diff --git a/src/test-api.c b/src/test-api.c index 558ce90..d538e65 100644 --- a/src/test-api.c +++ b/src/test-api.c @@ -30,45 +30,6 @@ static GMainLoop *mainloop = NULL; -static void -last_events_cb (TpProxy *logger, - const GPtrArray *result, - const GError *error, - gpointer userdata, - GObject *weak_obj) -{ - /* Just do demonstrate remote exceptions versus regular GError */ - if (error != NULL) - { - g_printerr ("Error: %s\n", error->message); - return; - } - - g_print ("Names on the message bus:\n"); - - for (guint i = 0; i < result->len; ++i) - { - GValueArray *message_struct; - const gchar *message_body; - const gchar *message_sender; - guint message_timestamp; - - message_struct = g_ptr_array_index (result, i); - - message_sender = g_value_get_string ( - g_value_array_get_nth (message_struct, 0)); - message_body = g_value_get_string ( - g_value_array_get_nth (message_struct, 1)); - message_timestamp = g_value_get_int64 (g_value_array_get_nth - (message_struct, 2)); - - g_print ("%d: [%d] from=%s: %s\n", i, message_timestamp, message_sender, - message_body); - } - - g_main_loop_quit (mainloop); -} - int main (int argc, char *argv[]) { @@ -102,9 +63,7 @@ main (int argc, char *argv[]) tp_proxy_add_interface_by_id (proxy, TPL_IFACE_QUARK_LOGGER); - tpl_cli_logger_call_get_recent_events (proxy, -1, - account, identifer, FALSE, 5, - last_events_cb, NULL, NULL, NULL); + // FIXME Test favorites g_free (account); diff --git a/telepathy-logger/dbus-service.c b/telepathy-logger/dbus-service.c index 9f853bc..7f39059 100644 --- a/telepathy-logger/dbus-service.c +++ b/telepathy-logger/dbus-service.c @@ -368,193 +368,6 @@ _tpl_dbus_service_new (void) } -typedef struct -{ - TplDBusService *self; - TpAccount *account; - char *identifier; - TplEventSearchType type; - guint lines; - DBusGMethodInvocation *context; - GPtrArray *packed; - GList *dates, *ptr; -} RecentEventsContext; - -static void _lookup_next_date (RecentEventsContext *ctx); - -static void -_get_events_return (GObject *manager, - GAsyncResult *res, - gpointer user_data) -{ - RecentEventsContext *ctx = user_data; - GList *events, *ptr; - GError *error = NULL; - - if (!tpl_log_manager_get_events_for_date_finish ( - TPL_LOG_MANAGER (manager), res, &events, &error)) - { - DEBUG ("Failed to get events: %s", error->message); - - g_clear_error (&error); - events = NULL; /* just to be sure */ - } - - /* from the most recent message, backward */ - for (ptr = g_list_last (events); - ptr != NULL && ctx->lines > 0; - ptr = g_list_previous (ptr)) - { - TplEvent *log = ptr->data; - const char *message = tpl_text_event_get_message ( - TPL_TEXT_EVENT (log)); - const char *sender = tpl_entity_get_identifier ( - tpl_event_get_sender (log)); - gint64 timestamp = tpl_event_get_timestamp (log); - - DEBUG ("Message: %" G_GINT64_FORMAT " <%s> %s", - timestamp, sender, message); - - g_ptr_array_add (ctx->packed, tp_value_array_build (3, - G_TYPE_STRING, sender, - G_TYPE_STRING, message, - G_TYPE_INT64, timestamp, - G_TYPE_INVALID)); - - ctx->lines--; - } - - g_list_foreach (events, (GFunc) g_object_unref, NULL); - g_list_free (events); - - _lookup_next_date (ctx); -} - - -static void -_lookup_next_date (RecentEventsContext *ctx) -{ - TplDBusServicePriv *priv = ctx->self->priv; - - if (ctx->ptr != NULL && ctx->lines > 0) - { - GDate *date = ctx->ptr->data; - - DEBUG ("Looking up date %04u-%02u-%02u", g_date_get_year (date), - g_date_get_month (date), g_date_get_day (date)); - - tpl_log_manager_get_events_for_date_async (priv->manager, - ctx->account, ctx->identifier, ctx->type, date, - _get_events_return, ctx); - - ctx->ptr = g_list_previous (ctx->ptr); - } - else - { - /* return and release */ - DEBUG ("complete, returning"); - - g_list_foreach (ctx->dates, (GFunc) g_date_free, NULL); - g_list_free (ctx->dates); - - tpl_svc_logger_return_from_get_recent_events (ctx->context, - ctx->packed); - - g_ptr_array_free (ctx->packed, TRUE); - g_free (ctx->identifier); - g_object_unref (ctx->account); - g_slice_free (RecentEventsContext, ctx); - } -} - - -static void -_get_dates_return (GObject *manager, - GAsyncResult *res, - gpointer user_data) -{ - RecentEventsContext *ctx = user_data; - GError *error = NULL; - - if (!tpl_log_manager_get_dates_finish (TPL_LOG_MANAGER (manager), res, - &ctx->dates, &error)) - { - DEBUG ("Failed to get dates: %s", error->message); - - dbus_g_method_return_error (ctx->context, error); - - g_clear_error (&error); - - g_free (ctx->identifier); - g_object_unref (ctx->account); - g_slice_free (RecentEventsContext, ctx); - - return; - } - - ctx->ptr = g_list_last (ctx->dates); - ctx->packed = g_ptr_array_new_with_free_func ( - (GDestroyNotify) g_value_array_free); - - _lookup_next_date (ctx); -} - - -static void -tpl_dbus_service_get_recent_events (TplSvcLogger *self, - const gchar *account_path, - const gchar *identifier, - TplEventSearchType type, - guint lines, - DBusGMethodInvocation *context) -{ - TplDBusServicePriv *priv = TPL_DBUS_SERVICE (self)->priv; - TpDBusDaemon *tp_dbus; - TpAccount *account; - RecentEventsContext *ctx; - GError *error = NULL; - - g_return_if_fail (TPL_IS_DBUS_SERVICE (self)); - g_return_if_fail (context != NULL); - - tp_dbus = tp_dbus_daemon_dup (&error); - if (tp_dbus == NULL) - { - DEBUG ("Unable to acquire the bus daemon: %s", error->message); - dbus_g_method_return_error (context, error); - goto out; - } - - account = tp_account_new (tp_dbus, account_path, &error); - if (account == NULL) - { - DEBUG ("Unable to acquire the account for %s: %s", account_path, - error->message); - dbus_g_method_return_error (context, error); - goto out; - } - - ctx = g_slice_new (RecentEventsContext); - ctx->self = TPL_DBUS_SERVICE (self); - ctx->account = account; - ctx->identifier = g_strdup (identifier); - ctx->type = type; - ctx->lines = lines; - ctx->context = context; - - tpl_log_manager_get_dates_async (priv->manager, - account, identifier, type, - _get_dates_return, ctx); - -out: - - if (tp_dbus != NULL) - g_object_unref (tp_dbus); - - g_clear_error (&error); -} - - static void append_favourite_contacts_account_and_contacts (const gchar *account, GHashTable *contacts, @@ -928,7 +741,6 @@ tpl_logger_iface_init (gpointer iface, TplSvcLoggerClass *klass = (TplSvcLoggerClass *) iface; #define IMPLEMENT(x) tpl_svc_logger_implement_##x (klass, tpl_dbus_service_##x) - IMPLEMENT (get_recent_events); IMPLEMENT (get_favourite_contacts); IMPLEMENT (add_favourite_contact); IMPLEMENT (remove_favourite_contact); |