Skip to content

Latest commit

 

History

History
146 lines (128 loc) · 3.08 KB

mms_connection.c

File metadata and controls

146 lines (128 loc) · 3.08 KB
 
Feb 17, 2014
Feb 17, 2014
1
/*
May 1, 2016
May 1, 2016
2
* Copyright (C) 2013-2016 Jolla Ltd.
Oct 27, 2015
Oct 27, 2015
3
* Contact: Slava Monich <slava.monich@jolla.com>
Feb 17, 2014
Feb 17, 2014
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"
May 1, 2016
May 1, 2016
22
G_DEFINE_ABSTRACT_TYPE(MMSConnection, mms_connection, G_TYPE_OBJECT)
Feb 17, 2014
Feb 17, 2014
23
24
#define MMS_CONNECTION_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), MMS_TYPE_CONNECTION, MMSConnectionClass))
Oct 27, 2015
Oct 27, 2015
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 };
Feb 17, 2014
Feb 17, 2014
34
35
36
MMSConnection*
mms_connection_ref(
Oct 27, 2015
Oct 27, 2015
37
MMSConnection* self)
Feb 17, 2014
Feb 17, 2014
38
{
Oct 27, 2015
Oct 27, 2015
39
40
if (self) g_object_ref(MMS_CONNECTION(self));
return self;
Feb 17, 2014
Feb 17, 2014
41
42
43
44
}
void
mms_connection_unref(
Oct 27, 2015
Oct 27, 2015
45
MMSConnection* self)
Feb 17, 2014
Feb 17, 2014
46
{
Oct 27, 2015
Oct 27, 2015
47
if (self) g_object_unref(MMS_CONNECTION(self));
Feb 17, 2014
Feb 17, 2014
48
49
50
51
}
const char*
mms_connection_state_name(
Oct 27, 2015
Oct 27, 2015
52
MMSConnection* self)
Feb 17, 2014
Feb 17, 2014
53
54
{
static const char* names[] = {"????","OPENING","FAILED","OPEN","CLOSED"};
Oct 27, 2015
Oct 27, 2015
55
return names[mms_connection_state(self)];
Feb 17, 2014
Feb 17, 2014
56
57
58
59
}
MMS_CONNECTION_STATE
mms_connection_state(
Oct 27, 2015
Oct 27, 2015
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)
Feb 17, 2014
Feb 17, 2014
70
{
Oct 27, 2015
Oct 27, 2015
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);
}
Feb 17, 2014
Feb 17, 2014
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);
}
/**
Oct 27, 2015
Oct 27, 2015
104
* Per instance initializer
Feb 17, 2014
Feb 17, 2014
105
106
107
*/
static
void
Oct 27, 2015
Oct 27, 2015
108
109
mms_connection_init(
MMSConnection* self)
Feb 17, 2014
Feb 17, 2014
110
{
Oct 27, 2015
Oct 27, 2015
111
MMS_VERBOSE_("%p", self);
Feb 17, 2014
Feb 17, 2014
112
113
114
}
/**
Oct 27, 2015
Oct 27, 2015
115
* Final stage of deinitialization
Feb 17, 2014
Feb 17, 2014
116
117
118
*/
static
void
Oct 27, 2015
Oct 27, 2015
119
120
mms_connection_finalize(
GObject* object)
Feb 17, 2014
Feb 17, 2014
121
{
Oct 27, 2015
Oct 27, 2015
122
123
MMS_VERBOSE_("%p", object);
G_OBJECT_CLASS(mms_connection_parent_class)->finalize(object);
Feb 17, 2014
Feb 17, 2014
124
125
126
}
/**
Oct 27, 2015
Oct 27, 2015
127
* Per class initializer
Feb 17, 2014
Feb 17, 2014
128
129
130
*/
static
void
Oct 27, 2015
Oct 27, 2015
131
132
mms_connection_class_init(
MMSConnectionClass* klass)
Feb 17, 2014
Feb 17, 2014
133
{
Oct 27, 2015
Oct 27, 2015
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);
Feb 17, 2014
Feb 17, 2014
138
139
140
141
142
143
144
145
146
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/