File: sip-connection-manager.c

package info (click to toggle)
telepathy-rakia 0.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 3,028 kB
  • ctags: 1,720
  • sloc: sh: 11,552; ansic: 9,892; python: 4,532; makefile: 421; xml: 15
file content (139 lines) | stat: -rw-r--r-- 4,304 bytes parent folder | download | duplicates (4)
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
/*
 * sip-connection-manager.c - Source for RakiaConnectionManager
 * Copyright (C) 2005-2007 Collabora Ltd.
 * Copyright (C) 2005-2009 Nokia Corporation
 *   @author Kai Vehmanen <first.surname@nokia.com>
 *   @author Martti Mela <first.surname@nokia.com>
 *   @author Mikhail Zabaluev <mikhail.zabaluev@nokia.com>
 *
 * Based on telepathy-gabble implementation (gabble-connection-manager).
 *   @author See gabble-connection-manager.c
 *
 * This work 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 work 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 work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"

#include <stdlib.h>
#include <string.h>

#include <dbus/dbus-protocol.h>

#include <telepathy-glib/debug-sender.h>
#include <telepathy-glib/errors.h>
#include <telepathy-glib/svc-connection-manager.h>

#include <rakia/sofia-decls.h>
#include <sofia-sip/su_glib.h>
#include <sofia-sip/su_log.h>

#include "protocol.h"
#include "sip-connection-manager.h"
#include "sip-connection.h"

#define DEBUG_FLAG RAKIA_DEBUG_CONNECTION
#include "rakia/debug.h"


G_DEFINE_TYPE(RakiaConnectionManager, rakia_connection_manager,
    TP_TYPE_BASE_CONNECTION_MANAGER)

struct _RakiaConnectionManagerPrivate
{
  su_root_t *sofia_root;
  TpDebugSender *debug_sender;
};

#define RAKIA_CONNECTION_MANAGER_GET_PRIVATE(obj) ((obj)->priv)

static void
rakia_connection_manager_init (RakiaConnectionManager *obj)
{
  RakiaConnectionManagerPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
        RAKIA_TYPE_CONNECTION_MANAGER, RakiaConnectionManagerPrivate);
  GSource *source;

  obj->priv = priv;

  priv->debug_sender = tp_debug_sender_dup ();
  g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);

  su_log_redirect (NULL, rakia_sofia_log_handler, NULL);

  priv->sofia_root = su_glib_root_create(obj);
  su_root_threading(priv->sofia_root, 0);
  source = su_glib_root_gsource(priv->sofia_root);
  g_source_attach(source, NULL);

#ifdef HAVE_LIBIPHB
  su_root_set_max_defer (priv->sofia_root, RAKIA_DEFER_TIMEOUT * 1000L);
#endif
}

static void
rakia_connection_manager_constructed (GObject *object)
{
  RakiaConnectionManager *self = RAKIA_CONNECTION_MANAGER (object);
  TpBaseConnectionManager *base = (TpBaseConnectionManager *) self;
  void (*constructed) (GObject *) =
      ((GObjectClass *) rakia_connection_manager_parent_class)->constructed;
  TpBaseProtocol *protocol;

  if (constructed != NULL)
    constructed (object);

  protocol = rakia_protocol_new (self->priv->sofia_root);
  tp_base_connection_manager_add_protocol (base, protocol);
  g_object_unref (protocol);
}

static void rakia_connection_manager_finalize (GObject *object);

static void
rakia_connection_manager_class_init (RakiaConnectionManagerClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  TpBaseConnectionManagerClass *base_class = 
    (TpBaseConnectionManagerClass *)klass;

  g_type_class_add_private (klass, sizeof (RakiaConnectionManagerPrivate));

  object_class->constructed = rakia_connection_manager_constructed;
  object_class->finalize = rakia_connection_manager_finalize;

  base_class->cm_dbus_name = "sofiasip";
}

void
rakia_connection_manager_finalize (GObject *object)
{
  RakiaConnectionManager *self = RAKIA_CONNECTION_MANAGER (object);
  RakiaConnectionManagerPrivate *priv = RAKIA_CONNECTION_MANAGER_GET_PRIVATE (self);
  GSource *source;

  source = su_glib_root_gsource(priv->sofia_root);
  g_source_destroy(source);
  su_root_destroy(priv->sofia_root);

  rakia_debug_free ();

  if (priv->debug_sender != NULL)
    {
      g_object_unref (priv->debug_sender);
      priv->debug_sender = NULL;
    }

  G_OBJECT_CLASS (rakia_connection_manager_parent_class)->finalize (object);
}