summaryrefslogtreecommitdiff
path: root/telepathy-glib/logger.c
blob: 070a2148b8f8ba3513d438166c7abc4214017d2c (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * TpLogger - a TpProxy for the logger
 *
 * Copyright (C) 2014 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, see <http://www.gnu.org/licenses/>.
 */


#include "config.h"

#include "logger.h"

#include <telepathy-glib/telepathy-glib-dbus.h>
#include <telepathy-glib/cli-misc.h>
#include <telepathy-glib/proxy-subclass.h>

#define DEBUG_FLAG TP_DEBUG_PROXY
#include "telepathy-glib/debug-internal.h"
#include "telepathy-glib/dbus-internal.h"

/**
 * SECTION: logger
 * @title: TpLogger
 * @short_description: proxy object on the logger
 *
 * #TpLogger is a #TpProxy subclass on the telepathy logger.
 */

/**
 * TpLogger:
 *
 * Data structure representing a #TpLogger.
 *
 * Since: 0.99.8
 */

/**
 * TpLoggerClass:
 *
 * The class of a #TpLogger.
 *
 * Since: 0.99.8
 */

G_DEFINE_TYPE (TpLogger, tp_logger, TP_TYPE_PROXY)

struct _TpLoggerPriv
{
  gpointer unused;
};

static void
tp_logger_init_known_interfaces (void)
{
  static gsize once = 0;

  if (g_once_init_enter (&once))
    {
      GType tp_type = TP_TYPE_ACCOUNT_MANAGER;

      tp_proxy_init_known_interfaces ();
      tp_proxy_or_subclass_hook_on_interface_add (tp_type,
          tp_cli_logger_add_signals);
      tp_proxy_subclass_add_error_mapping (tp_type,
          TP_ERROR_PREFIX, TP_ERROR, TP_TYPE_ERROR);

      g_once_init_leave (&once, 1);
    }
}

static void
tp_logger_class_init (
    TpLoggerClass *klass)
{
  TpProxyClass *proxy_class = (TpProxyClass *) klass;

  proxy_class->interface = TP_IFACE_QUARK_LOGGER;
  tp_logger_init_known_interfaces ();

  g_type_class_add_private (klass, sizeof (TpLoggerPriv));
}

static void
tp_logger_init (TpLogger *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
      TP_TYPE_LOGGER, TpLoggerPriv);
}

static gpointer logger_singleton = NULL;

/**
 * tp_logger_dup:
 *
 * Returns an logger proxy on the D-Bus daemon on which this
 * process was activated (if it was launched by D-Bus service activation), or
 * the session bus (otherwise). This logger proxy will always have
 * the result of tp_dbus_daemon_dup() as its #TpProxy:dbus-daemon.
 *
 * The returned #TpLogger is cached; the same #TpLogger object
 * will be returned by this function repeatedly, as long as at least one
 * reference exists.
 *
 * Returns: (transfer full): an logger proxy on the starter or session
 *          bus, or %NULL if it wasn't possible to get a dbus daemon proxy for
 *          the appropriate bus

 * Since: 0.99.8
 */
TpLogger *
tp_logger_dup (void)
{
  TpDBusDaemon *dbus;
  GError *error = NULL;

  if (logger_singleton != NULL)
    g_object_ref (logger_singleton);

  dbus = tp_dbus_daemon_dup (&error);
  if (dbus == NULL)
    {
      WARNING ("Error getting default TpDBusDaemon: %s", error->message);
      g_clear_error (&error);
      return NULL;
    }

  logger_singleton = g_object_new (TP_TYPE_LOGGER,
      "dbus-daemon", dbus,
      "bus-name", TP_LOGGER_BUS_NAME,
      "object-path", TP_LOGGER_OBJECT_PATH,
      NULL);

  g_assert (logger_singleton != NULL);
  g_object_add_weak_pointer (logger_singleton, &logger_singleton);

  g_object_unref (dbus);
  return logger_singleton;
}