/
mms_connection.c
146 lines (128 loc) · 3.07 KB
/
mms_connection.c
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
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* 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"
G_DEFINE_TYPE(MMSConnection, mms_connection, G_TYPE_OBJECT);
#define MMS_CONNECTION_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), MMS_TYPE_CONNECTION, MMSConnectionClass))
enum mms_connection_signal {
SIGNAL_STATE_CHANGED,
SIGNAL_COUNT
};
#define SIGNAL_STATE_CHANGED_NAME "state-changed"
static guint mms_connection_signals[SIGNAL_COUNT] = { 0 };
MMSConnection*
mms_connection_ref(
MMSConnection* self)
{
if (self) g_object_ref(MMS_CONNECTION(self));
return self;
}
void
mms_connection_unref(
MMSConnection* self)
{
if (self) g_object_unref(MMS_CONNECTION(self));
}
const char*
mms_connection_state_name(
MMSConnection* self)
{
static const char* names[] = {"????","OPENING","FAILED","OPEN","CLOSED"};
return names[mms_connection_state(self)];
}
MMS_CONNECTION_STATE
mms_connection_state(
MMSConnection* self)
{
return self ? self->state : MMS_CONNECTION_STATE_INVALID;
}
gulong
mms_connection_add_state_change_handler(
MMSConnection* self,
MMSConnectionStateChangeFunc fn,
void* data)
{
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);
}
}
void
mms_connection_close(
MMSConnection* conn)
{
if (conn) MMS_CONNECTION_GET_CLASS(conn)->fn_close(conn);
}
/**
* Per instance initializer
*/
static
void
mms_connection_init(
MMSConnection* self)
{
MMS_VERBOSE_("%p", self);
}
/**
* Final stage of deinitialization
*/
static
void
mms_connection_finalize(
GObject* object)
{
MMS_VERBOSE_("%p", object);
G_OBJECT_CLASS(mms_connection_parent_class)->finalize(object);
}
/**
* Per class initializer
*/
static
void
mms_connection_class_init(
MMSConnectionClass* klass)
{
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);
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/