author | Frank Zschockelt <lm@freakysoft.de> |
Thu, 04 Feb 2016 19:18:03 +0100 | |
changeset 690 | 7ccf2113ec5f |
parent 607 | e2bd14357c9a |
permissions | -rw-r--r-- |
516
4dd3aa6b83e5
Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents:
515
diff
changeset
|
1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
2 |
/* |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
3 |
* Copyright (C) 2006 Imendio AB |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
4 |
* |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
6 |
* modify it under the terms of the GNU Lesser General Public License as |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; either version 2 of the |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
8 |
* License, or (at your option) any later version. |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
9 |
* |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
13 |
* Lesser General Public License for more details. |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
14 |
* |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU Lesser General Public |
690
7ccf2113ec5f
Update the postal address of the FSF
Frank Zschockelt <lm@freakysoft.de>
parents:
607
diff
changeset
|
16 |
* License along with this program; if not, see <https://www.gnu.org/licenses> |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
17 |
*/ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
18 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
19 |
#include <config.h> |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
20 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
21 |
#include "lm-message-queue.h" |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
22 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
23 |
struct _LmMessageQueue { |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
24 |
GQueue *messages; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
25 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
26 |
GMainContext *context; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
27 |
GSource *source; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
28 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
29 |
LmMessageQueueCallback callback; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
30 |
gpointer user_data; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
31 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
32 |
gint ref_count; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
33 |
}; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
34 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
35 |
typedef struct { |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
36 |
GSource source; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
37 |
LmMessageQueue *queue; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
38 |
} MessageQueueSource; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
39 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
40 |
static void message_queue_free (LmMessageQueue *queue); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
41 |
static gboolean message_queue_prepare_func (GSource *source, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
42 |
gint *timeout); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
43 |
static gboolean message_queue_check_func (GSource *source); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
44 |
static gboolean message_queue_dispatch_func (GSource *source, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
45 |
GSourceFunc callback, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
46 |
gpointer user_data); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
47 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
48 |
static GSourceFuncs source_funcs = { |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
49 |
message_queue_prepare_func, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
50 |
message_queue_check_func, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
51 |
message_queue_dispatch_func, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
52 |
NULL |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
53 |
}; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
54 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
55 |
static void |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
56 |
foreach_free_message (LmMessage *m, gpointer user_data) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
57 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
58 |
lm_message_unref (m); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
59 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
60 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
61 |
static void |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
62 |
message_queue_free (LmMessageQueue *queue) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
63 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
64 |
lm_message_queue_detach (queue); |
607 | 65 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
66 |
g_queue_foreach (queue->messages, (GFunc) foreach_free_message, NULL); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
67 |
g_queue_free (queue->messages); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
68 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
69 |
g_free (queue); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
70 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
71 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
72 |
static gboolean |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
73 |
message_queue_prepare_func (GSource *source, gint *timeout) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
74 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
75 |
LmMessageQueue *queue; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
76 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
77 |
queue = ((MessageQueueSource *)source)->queue; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
78 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
79 |
return !g_queue_is_empty (queue->messages); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
80 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
81 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
82 |
static gboolean |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
83 |
message_queue_check_func (GSource *source) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
84 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
85 |
return FALSE; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
86 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
87 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
88 |
static gboolean |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
89 |
message_queue_dispatch_func (GSource *source, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
90 |
GSourceFunc callback, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
91 |
gpointer user_data) |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
92 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
93 |
LmMessageQueue *queue; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
94 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
95 |
queue = ((MessageQueueSource *)source)->queue; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
96 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
97 |
if (queue->callback) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
98 |
(queue->callback) (queue, queue->user_data); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
99 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
100 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
101 |
return TRUE; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
102 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
103 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
104 |
LmMessageQueue * |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
105 |
lm_message_queue_new (LmMessageQueueCallback callback, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
106 |
gpointer user_data) |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
107 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
108 |
LmMessageQueue *queue; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
109 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
110 |
queue = g_new0 (LmMessageQueue, 1); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
111 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
112 |
queue->messages = g_queue_new (); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
113 |
queue->context = NULL; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
114 |
queue->source = NULL; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
115 |
queue->ref_count = 1; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
116 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
117 |
queue->callback = callback; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
118 |
queue->user_data = user_data; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
119 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
120 |
return queue; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
121 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
122 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
123 |
void |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
124 |
lm_message_queue_attach (LmMessageQueue *queue, GMainContext *context) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
125 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
126 |
GSource *source; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
127 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
128 |
if (queue->source) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
129 |
if (queue->context == context) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
130 |
/* Already attached */ |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
131 |
return; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
132 |
} |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
133 |
lm_message_queue_detach (queue); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
134 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
135 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
136 |
if (context) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
137 |
queue->context = g_main_context_ref (context); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
138 |
} |
607 | 139 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
140 |
source = g_source_new (&source_funcs, sizeof (MessageQueueSource)); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
141 |
((MessageQueueSource *)source)->queue = queue; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
142 |
queue->source = source; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
143 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
144 |
g_source_attach (source, queue->context); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
145 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
146 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
147 |
void |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
148 |
lm_message_queue_detach (LmMessageQueue *queue) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
149 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
150 |
if (queue->source) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
151 |
g_source_destroy (queue->source); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
152 |
g_source_unref (queue->source); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
153 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
154 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
155 |
if (queue->context) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
156 |
g_main_context_unref (queue->context); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
157 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
158 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
159 |
queue->source = NULL; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
160 |
queue->context = NULL; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
161 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
162 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
163 |
void |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
164 |
lm_message_queue_push_tail (LmMessageQueue *queue, LmMessage *m) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
165 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
166 |
g_return_if_fail (queue != NULL); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
167 |
g_return_if_fail (m != NULL); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
168 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
169 |
g_queue_push_tail (queue->messages, m); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
170 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
171 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
172 |
LmMessage * |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
173 |
lm_message_queue_peek_nth (LmMessageQueue *queue, guint n) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
174 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
175 |
g_return_val_if_fail (queue != NULL, NULL); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
176 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
177 |
return (LmMessage *) g_queue_peek_nth (queue->messages, n); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
178 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
179 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
180 |
LmMessage * |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
181 |
lm_message_queue_pop_nth (LmMessageQueue *queue, guint n) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
182 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
183 |
g_return_val_if_fail (queue != NULL, NULL); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
184 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
185 |
return (LmMessage *) g_queue_pop_nth (queue->messages, n); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
186 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
187 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
188 |
guint |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
189 |
lm_message_queue_get_length (LmMessageQueue *queue) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
190 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
191 |
g_return_val_if_fail (queue != NULL, 0); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
192 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
193 |
return g_queue_get_length (queue->messages); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
194 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
195 |
|
607 | 196 |
gboolean |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
197 |
lm_message_queue_is_empty (LmMessageQueue *queue) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
198 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
199 |
g_return_val_if_fail (queue != NULL, TRUE); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
200 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
201 |
return g_queue_is_empty (queue->messages); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
202 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
203 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
204 |
LmMessageQueue * |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
205 |
lm_message_queue_ref (LmMessageQueue *queue) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
206 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
207 |
g_return_val_if_fail (queue != NULL, NULL); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
208 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
209 |
queue->ref_count++; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
210 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
211 |
return queue; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
212 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
213 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
214 |
void |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
215 |
lm_message_queue_unref (LmMessageQueue *queue) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
216 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
217 |
g_return_if_fail (queue != NULL); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
218 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
219 |
queue->ref_count--; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
220 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
221 |
if (queue->ref_count <= 0) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
222 |
message_queue_free (queue); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
223 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
224 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
225 |