summaryrefslogtreecommitdiff
path: root/src/test-api.c
blob: 61afe662105efa086a6a90f4ee296dfa7d431179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
 */


#include <glib.h>

#include <telepathy-glib/dbus.h>

#include <telepathy-logger/dbus-service.h>
#include <extensions/extensions.h>

#define ACCOUNT_PATH "/org/freedesktop/Telepathy/Account/gabble/jabber/cosimo_2ealfarano_40collabora_2eco_2euk0"
#define ID "echo@test.collabora.co.uk"

//static GMainLoop *loop = NULL;

static void
last_chats_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_body = g_value_get_string (g_value_array_get_nth
          (message_struct, 0));
      message_sender = g_value_get_string (g_value_array_get_nth
          (message_struct, 1));
      message_timestamp = g_value_get_uint (g_value_array_get_nth
          (message_struct, 2));

      g_debug ("%d: [%d] from=%s - %s", i, message_timestamp, message_sender,
          message_body);
    }
}

int
main (int argc, char *argv[])
{
  TpDBusDaemon *bus;
  TpProxy *proxy;
  GError *error = NULL;

  g_type_init ();

  bus = tp_dbus_daemon_dup (&error);
  g_assert_no_error (error);

  proxy = g_object_new (TP_TYPE_PROXY,
      "bus-name", TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME,
      "object-path", TPL_DBUS_SRV_OBJECT_PATH,
      "dbus-daemon", bus,
      NULL);

  g_object_unref (bus);

  tpl_cli_logger_call_get_recent_messages (proxy, -1,
      ACCOUNT_PATH, ID, FALSE, 5,
      last_chats_cb, NULL, NULL, NULL);

  g_object_unref (proxy);

  return 0;
}