/
mms_connection.c
146 lines (128 loc) · 3.08 KB
1
/*
2
* Copyright (C) 2013-2016 Jolla Ltd.
3
* Contact: Slava Monich <slava.monich@jolla.com>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
*/
#include "mms_connection.h"
/* Logging */
#define MMS_LOG_MODULE_NAME mms_connection_log
#include "mms_lib_log.h"
22
G_DEFINE_ABSTRACT_TYPE(MMSConnection, mms_connection, G_TYPE_OBJECT)
23
24
#define MMS_CONNECTION_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), MMS_TYPE_CONNECTION, MMSConnectionClass))
25
26
27
28
29
30
31
32
33
enum mms_connection_signal {
SIGNAL_STATE_CHANGED,
SIGNAL_COUNT
};
#define SIGNAL_STATE_CHANGED_NAME "state-changed"
static guint mms_connection_signals[SIGNAL_COUNT] = { 0 };
34
35
36
MMSConnection*
mms_connection_ref(
37
MMSConnection* self)
38
{
39
40
if (self) g_object_ref(MMS_CONNECTION(self));
return self;
41
42
43
44
}
void
mms_connection_unref(
45
MMSConnection* self)
46
{
47
if (self) g_object_unref(MMS_CONNECTION(self));
48
49
50
51
}
const char*
mms_connection_state_name(
52
MMSConnection* self)
53
54
{
static const char* names[] = {"????","OPENING","FAILED","OPEN","CLOSED"};
55
return names[mms_connection_state(self)];
56
57
58
59
}
MMS_CONNECTION_STATE
mms_connection_state(
60
61
62
63
64
65
66
67
68
69
MMSConnection* self)
{
return self ? self->state : MMS_CONNECTION_STATE_INVALID;
}
gulong
mms_connection_add_state_change_handler(
MMSConnection* self,
MMSConnectionStateChangeFunc fn,
void* data)
70
{
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
return (self && fn) ? g_signal_connect(self,SIGNAL_STATE_CHANGED_NAME,
G_CALLBACK(fn), data) : 0;
}
void
mms_connection_signal_state_change(
MMSConnection* self)
{
if (self) {
mms_connection_ref(self);
g_signal_emit(self, mms_connection_signals[SIGNAL_STATE_CHANGED], 0);
mms_connection_unref(self);
}
}
void
mms_connection_remove_handler(
MMSConnection* self,
gulong id)
{
if (self && id) {
g_signal_handler_disconnect(self, id);
}
94
95
96
97
98
99
100
101
102
103
}
void
mms_connection_close(
MMSConnection* conn)
{
if (conn) MMS_CONNECTION_GET_CLASS(conn)->fn_close(conn);
}
/**
104
* Per instance initializer
105
106
107
*/
static
void
108
109
mms_connection_init(
MMSConnection* self)
110
{
111
MMS_VERBOSE_("%p", self);
112
113
114
}
/**
115
* Final stage of deinitialization
116
117
118
*/
static
void
119
120
mms_connection_finalize(
GObject* object)
121
{
122
123
MMS_VERBOSE_("%p", object);
G_OBJECT_CLASS(mms_connection_parent_class)->finalize(object);
124
125
126
}
/**
127
* Per class initializer
128
129
130
*/
static
void
131
132
mms_connection_class_init(
MMSConnectionClass* klass)
133
{
134
135
136
137
G_OBJECT_CLASS(klass)->finalize = mms_connection_finalize;
mms_connection_signals[SIGNAL_STATE_CHANGED] =
g_signal_new(SIGNAL_STATE_CHANGED_NAME, G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
138
139
140
141
142
143
144
145
146
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/