author | Mikael Berthe <mikael@lilotux.net> |
Mon, 25 Jan 2016 18:35:10 +0100 | |
changeset 685 | dfa02c1c7fda |
parent 643 | e7ef923056d7 |
child 690 | 7ccf2113ec5f |
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 -*- */ |
1 | 2 |
/* |
99
81e9d035de02
2004-10-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
84
diff
changeset
|
3 |
* Copyright (C) 2003 Imendio AB |
1 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU Lesser General Public License as |
|
7 |
* published by the Free Software Foundation; either version 2 of the |
|
8 |
* License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
* Lesser General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU Lesser General Public |
|
16 |
* License along with this program; if not, write to the |
|
17 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
18 |
* Boston, MA 02111-1307, USA. |
|
19 |
*/ |
|
20 |
||
417
364c17252e5f
Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents:
168
diff
changeset
|
21 |
/** |
420
f40434cca022
Fixed the SECTION parts of the inlined docs so that gtk-doc finds them.
Mikael Hallendal <micke@imendio.com>
parents:
417
diff
changeset
|
22 |
* SECTION:lm-message-handler |
421
2a91651d22de
Added Title to the inlined documentation
Mikael Hallendal <micke@imendio.com>
parents:
420
diff
changeset
|
23 |
* @Title: LmMessageHandler |
417
364c17252e5f
Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents:
168
diff
changeset
|
24 |
* @Short_description: A handler for incoming messages. |
607 | 25 |
* |
417
364c17252e5f
Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents:
168
diff
changeset
|
26 |
* A handler can be registered to listen to incoming messages with lm_connection_register_message_handler(). When a message is recieved the handlers of the correct type will be called. |
364c17252e5f
Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents:
168
diff
changeset
|
27 |
*/ |
364c17252e5f
Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents:
168
diff
changeset
|
28 |
|
66
577d5059b718
2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
57
diff
changeset
|
29 |
#include <config.h> |
577d5059b718
2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
57
diff
changeset
|
30 |
|
1 | 31 |
#include "lm-internals.h" |
32 |
#include "lm-message-handler.h" |
|
33 |
||
34 |
struct LmMessageHandler { |
|
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
|
35 |
gboolean valid; |
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 |
gint ref_count; |
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 |
LmHandleMessageFunction function; |
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
|
38 |
gpointer 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
|
39 |
GDestroyNotify notify; |
1 | 40 |
}; |
41 |
||
607 | 42 |
LmHandlerResult |
1 | 43 |
_lm_message_handler_handle_message (LmMessageHandler *handler, |
44 |
LmConnection *connection, |
|
45 |
LmMessage *message) |
|
46 |
{ |
|
607 | 47 |
g_return_val_if_fail (handler != NULL, |
1 | 48 |
LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS); |
19
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
49 |
|
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
|
50 |
if (!handler->valid) { |
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 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
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 |
} |
607 | 53 |
|
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
|
54 |
if (handler->function) { |
607 | 55 |
return (* handler->function) (handler, connection, |
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
|
56 |
message, handler->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
|
57 |
} |
607 | 58 |
|
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
|
59 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
1 | 60 |
} |
61 |
||
62 |
/** |
|
63 |
* lm_message_handler_new: |
|
64 |
* @function: a callback |
|
65 |
* @user_data: user data passed to function |
|
66 |
* @notify: function called when the message handler is freed |
|
607 | 67 |
* |
1 | 68 |
* Creates a new message handler. This can be set to handle incoming messages |
69 |
* and when a message of the type the handler is registered to handle is |
|
70 |
* received @function will be called and @user_data will be passed to it. |
|
71 |
* @notify is called when the message handler is freed, that way any memory |
|
72 |
* allocated by @user_data can be freed. |
|
607 | 73 |
* |
1 | 74 |
* Return value: a newly created message handler |
75 |
**/ |
|
76 |
LmMessageHandler * |
|
77 |
lm_message_handler_new (LmHandleMessageFunction function, |
|
78 |
gpointer user_data, |
|
79 |
GDestroyNotify notify) |
|
80 |
{ |
|
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
|
81 |
LmMessageHandler *handler; |
168
ac1affcd5d22
2006-09-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
99
diff
changeset
|
82 |
|
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
|
83 |
g_return_val_if_fail (function != NULL, NULL); |
607 | 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 |
handler = g_new0 (LmMessageHandler, 1); |
607 | 86 |
|
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
|
87 |
if (handler == 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
|
88 |
return 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
|
89 |
} |
607 | 90 |
|
91 |
handler->valid = TRUE; |
|
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
|
92 |
handler->ref_count = 1; |
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 |
handler->function = function; |
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
|
94 |
handler->user_data = 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
|
95 |
handler->notify = notify; |
607 | 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 |
return handler; |
1 | 98 |
} |
99 |
||
100 |
/** |
|
19
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
101 |
* lm_message_handler_invalidate |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
102 |
* @handler: an #LmMessageHandler |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
103 |
* |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
104 |
* Invalidates the handler. Useful if you need to cancel a reply |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
105 |
**/ |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
106 |
void |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
107 |
lm_message_handler_invalidate (LmMessageHandler *handler) |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
108 |
{ |
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
|
109 |
handler->valid = FALSE; |
19
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
110 |
} |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
111 |
|
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
112 |
/** |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
113 |
* lm_message_handler_is_valid |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
114 |
* @handler: an #LmMessageHandler |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
115 |
* |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
116 |
* Fetches whether the handler is valid or not. |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
117 |
* |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
118 |
* Return value: #TRUE if @handler is valid, otherwise #FALSE |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
119 |
**/ |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
120 |
gboolean |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
121 |
lm_message_handler_is_valid (LmMessageHandler *handler) |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
122 |
{ |
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
|
123 |
g_return_val_if_fail (handler != NULL, FALSE); |
168
ac1affcd5d22
2006-09-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
99
diff
changeset
|
124 |
|
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
|
125 |
return handler->valid; |
19
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
126 |
} |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
127 |
|
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
128 |
/** |
1 | 129 |
* lm_message_handler_ref: |
130 |
* @handler: an #LmMessageHandler |
|
607 | 131 |
* |
66
577d5059b718
2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
57
diff
changeset
|
132 |
* Adds a reference to @handler. |
607 | 133 |
* |
1 | 134 |
* Return value: the message handler |
135 |
**/ |
|
136 |
LmMessageHandler * |
|
137 |
lm_message_handler_ref (LmMessageHandler *handler) |
|
138 |
{ |
|
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
|
139 |
g_return_val_if_fail (handler != NULL, NULL); |
607 | 140 |
|
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
|
141 |
handler->ref_count++; |
1 | 142 |
|
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
|
143 |
return handler; |
1 | 144 |
} |
145 |
||
146 |
/** |
|
147 |
* lm_message_handler_unref: |
|
643
e7ef923056d7
Minor documentation fixes
Myhailo Danylenko <isbear@ukrpost.net>
parents:
607
diff
changeset
|
148 |
* @handler: an #LmMessageHandler |
607 | 149 |
* |
150 |
* Removes a reference from @handler. When no more references are present the |
|
1 | 151 |
* handler is freed. |
152 |
**/ |
|
153 |
void |
|
154 |
lm_message_handler_unref (LmMessageHandler *handler) |
|
155 |
{ |
|
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
|
156 |
g_return_if_fail (handler != NULL); |
607 | 157 |
|
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
|
158 |
handler->ref_count --; |
607 | 159 |
|
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
|
160 |
if (handler->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
|
161 |
if (handler->notify) { |
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
|
162 |
(* handler->notify) (handler->user_data); |
1 | 163 |
} |
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
|
164 |
g_free (handler); |
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
|
165 |
} |
1 | 166 |
} |
167 |