summaryrefslogtreecommitdiff
path: root/src/ring-emergency-service.c
blob: 2b5db20a4caf069c5ab88f0d23b440f729626c7f (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
/*
 * ring-emergency-service.c - RingEmergencyService and RingEmergencyServiceList
 *
 * Copyright (C) 2008 Nokia Corporation
 *   @author Pekka Pessi <first.surname@nokia.com>
 *
 * 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
 */

#define DEBUG_FLAG RING_DEBUG_CONNECTION
#include "ring-debug.h"

#include "ring-emergency-service.h"
#include "ring-util.h"
#include "modem/call.h"

#include <dbus/dbus-glib.h>
#include <telepathy-glib/gtypes.h>

#include <string.h>

RingEmergencyService *
ring_emergency_service_new(char const *service)
{
  GValue value[1] = {{ 0 }};
  GType gtype = TP_STRUCT_TYPE_SERVICE_POINT;
  TpServicePointType service_type;

  if (service == NULL)
    service = "";

  if (service[0] == '\0')
    service_type = TP_SERVICE_POINT_TYPE_NONE;
  else
    service_type = TP_SERVICE_POINT_TYPE_EMERGENCY;

  g_value_init(value, gtype);
  g_value_take_boxed(value, dbus_g_type_specialized_construct(gtype));
  dbus_g_type_struct_set(value,
    0, service_type,
    1, service,
    G_MAXUINT);

  return (RingEmergencyService *)g_value_get_boxed(value);
}

void
ring_emergency_service_free(RingEmergencyService *service)
{
  g_boxed_free(TP_STRUCT_TYPE_SERVICE_POINT, (gpointer)service);
}

/* Return a pointer to a boxed service struct */
RingEmergencyServiceInfo *
ring_emergency_service_info_new(char const *service,
  char * const *aliases)
{
  RingEmergencyService *es;
  GValue value[1] = {{ 0 }};
  GType gtype = TP_STRUCT_TYPE_SERVICE_POINT_INFO;

  g_value_init(value, gtype);
  g_value_take_boxed(value, dbus_g_type_specialized_construct(gtype));

  es = ring_emergency_service_new(service);

  dbus_g_type_struct_set(value,
    0, es,
    1, aliases,
    G_MAXUINT);

  ring_emergency_service_free(es);

  return (RingEmergencyServiceInfo *)g_value_get_boxed(value);
}

void
ring_emergency_service_info_free(RingEmergencyServiceInfo *info)
{
  g_boxed_free(TP_STRUCT_TYPE_SERVICE_POINT_INFO, info);
}

RingEmergencyServiceInfoList *
ring_emergency_service_info_list_new(RingEmergencyServiceInfo *info,
  ...)
{
  RingEmergencyServiceInfoList *self = g_ptr_array_sized_new(1);
  va_list ap;

  for (va_start(ap, info); info; info = va_arg(ap, gpointer)) {
    g_ptr_array_add(self, info);
  }
  va_end(ap);

  return self;
}

void
ring_emergency_service_info_list_free(RingEmergencyServiceInfoList *list)
{
  guint i;
  for (i = 0; i < list->len; i++)
    ring_emergency_service_free(g_ptr_array_index(list, i));
  g_ptr_array_free(list, TRUE);
}

RingEmergencyServiceInfoList *
ring_emergency_service_info_list_default (char * const *numbers)
{
  RingEmergencyServiceInfo *base;

  base = ring_emergency_service_info_new(RING_EMERGENCY_SERVICE_URN, numbers);

  return ring_emergency_service_info_list_new(base, NULL);
}