author | Mikael Berthe <mikael@lilotux.net> |
Sat, 17 Apr 2010 14:03:37 +0200 | |
changeset 1906 | 5d37cee8c6c6 |
parent 1892 | ea3f9b4f3558 |
child 1913 | 3cabdacf58df |
permissions | -rw-r--r-- |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
1 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
2 |
=========================================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
3 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
4 |
Mcabber module writing brief howto |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
5 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
6 |
=========================================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
7 |
|
1830 | 8 |
To obtain information on module mcabber uses struct module_info_t, that |
9 |
module should provide in public variable with name info_<modulename>. |
|
10 |
If the module name contains any extra symbols except [a-z0-9_] they |
|
11 |
should be replaced with '_'. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
12 |
|
1830 | 13 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
14 |
#include <mcabber/modules.h> |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
15 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
16 |
typedef void (*module_init_t)(void); |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
17 |
typedef void (*module_uninit_t)(void); |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
18 |
|
1752 | 19 |
typedef struct module_info_struct module_info_t; |
20 |
struct module_info_struct { |
|
21 |
const gchar *branch; |
|
22 |
guint api; |
|
23 |
const gchar *version; |
|
24 |
const gchar *description; |
|
1754
d8442bcb33b7
Reorder fields in module info struct
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1752
diff
changeset
|
25 |
const gchar **requires; |
d8442bcb33b7
Reorder fields in module info struct
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1752
diff
changeset
|
26 |
module_init_t init; |
d8442bcb33b7
Reorder fields in module info struct
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1752
diff
changeset
|
27 |
module_uninit_t uninit; |
1752 | 28 |
module_info_t *next; |
29 |
}; |
|
1830 | 30 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
31 |
|
1830 | 32 |
Callbacks init and uninit will be called after module and its |
33 |
dependencies loading. 'requires' can contain a NULL-terminated list of |
|
34 |
module names, that should be loaded before this. 'branch' and 'api' are |
|
35 |
required and should contain mcabber branch and api version, that this |
|
36 |
module is designed to work with. For these values see ChangeLog.api. |
|
37 |
'version' and 'description' fields are optional and just provide user |
|
38 |
with additional information about the module. 'description' field can |
|
39 |
contain newlines. The 'next' field can contain pointer to the next |
|
40 |
struct with another branch of mcabber, if your module can work with |
|
41 |
multiple branches. |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
42 |
|
1830 | 43 |
To load modules, mcabber uses glib's GModule, thus, in your module you |
44 |
can also use functions |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
45 |
|
1830 | 46 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
47 |
#include <glib.h> |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
48 |
#include <gmodule.h> |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
49 |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
50 |
const gchar* g_module_check_init (GModule *module); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
51 |
void g_module_unload (GModule *module); |
1830 | 52 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
53 |
|
1830 | 54 |
to do something before any version/dependency check is performed when |
55 |
your module is loaded/unloaded. On success g_module_check_init should |
|
56 |
return NULL, and error message otherwise. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
57 |
|
1830 | 58 |
As module is loaded, you can use mcabber functions, declared in |
59 |
mcabber's header files (though you should consider, that they may change |
|
60 |
their calling conventions some day). |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
61 |
|
1830 | 62 |
I will not explain them all, there are too much of them, but will |
63 |
provide description for those, provided especially for module writers. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
64 |
|
1830 | 65 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
66 |
#include <mcabber/modules.h> |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
67 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
68 |
const gchar *module_load (const gchar *name, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
69 |
gboolean manual, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
70 |
gboolean force); |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
71 |
const gchar *module_unload (const gchar *name, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
72 |
gboolean manual, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
73 |
gboolean force); |
1830 | 74 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
75 |
|
1830 | 76 |
These functions load and unload modules respectively. You can use them |
77 |
to handle optional dependencies. What happens, when module is loaded: |
|
78 |
- check if module is present, and if present just increase it's |
|
79 |
reference count |
|
80 |
- load .so via glib (and call g_module_check_init, if present) |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
81 |
- check for information structure presence |
1830 | 82 |
- find suitable branch and check api version compatibility |
83 |
- load modules, that this module requires (note, that dependency |
|
84 |
problems will be reported as error invariably, force flag have no |
|
85 |
effect on this check) |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
86 |
- module placed into a list of modules |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
87 |
- module init routine is called |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
88 |
And when unloaded: |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
89 |
- check if module is present |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
90 |
- decrease reference count, if it is not zero, return |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
91 |
- run module uninit routine |
1830 | 92 |
- unload modules, that were loaded as dependencies for this one |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
93 |
- remove from modules list |
1830 | 94 |
They return error message or NULL in case of success. 'manual' flag |
95 |
indicates, that module will be loaded by direct user request. It serves |
|
96 |
the purpose of tracking user and automatic references (user can have |
|
97 |
only one). 'force' flag on module loading causes mcabber to ignore most |
|
98 |
of the loading errors. On unload it forces unloading even if reference |
|
99 |
count is not zero. |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
100 |
|
1830 | 101 |
------------------------------------------------------------------------ |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
102 |
#include <mcabber/commands.h> |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
103 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
104 |
void cmd_add (const char *name, const char *help, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
105 |
guint flags1, guint flags2, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
106 |
void (*f)(char*), gpointer userdata); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
107 |
void cmd_del (const char *name); |
1830 | 108 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
109 |
|
1830 | 110 |
These two functions are provided to declare mcabber commands, offered by |
111 |
your module. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
112 |
- name is a command name. |
1830 | 113 |
- help is a short description of your command, however for now it is |
114 |
not used at all and can be omitted. |
|
115 |
- flags are completion identifiers for first and second command |
|
116 |
arguments, for list of built-in completions, see compl.h. You can |
|
117 |
declare your own completion lists, using functions from compl.h, |
|
118 |
described later. |
|
119 |
- f is a user-provided callback function, that will be called upon |
|
120 |
executing mcabber command. If you will provide non-NULL userdata, |
|
121 |
function must be of type |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
122 |
void (*f) (char *commandline, gpointer userdata). |
1830 | 123 |
- userdata is a pointer to data, transparently passed to callback. |
124 |
See f description. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
125 |
|
1830 | 126 |
------------------------------------------------------------------------ |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
127 |
#include <mcabber/compl.h> |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
128 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
129 |
guint compl_new_category (void); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
130 |
void compl_del_category (guint id); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
131 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
132 |
void compl_add_category_word (guint categ, |
1830 | 133 |
const char *command); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
134 |
void compl_del_category_word (guint categ, |
1830 | 135 |
const char *word); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
136 |
GSList *compl_get_category_list (guint cat_flags, |
1830 | 137 |
guint *dynlist); |
138 |
------------------------------------------------------------------------ |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
139 |
|
1830 | 140 |
These functions allow you to define and manage word lists for completion |
141 |
categories, used by your commands. First you need to obtain handle for |
|
142 |
completion type, that you later will supply as flags, when declaring |
|
143 |
your commands. For that use function compl_new_category. It returns |
|
144 |
new category id, or zero if mcabber runs out of completion ids (for now |
|
145 |
there are only 32 ids available, and 20 of them are already used for |
|
146 |
builtin commands). compl_del_category allows you to delete user-defined |
|
147 |
category, deleting all words in it too. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
148 |
|
1830 | 149 |
Now, that you have a completion category, you can at any time add or |
150 |
delete words from its completion list. To do that, use the functions |
|
151 |
compl_add_category_word and compl_del_category_word. You can obtain |
|
152 |
current contents of category by using gompl_get_category_list. If after |
|
153 |
execution dynlist is TRUE, you should free obtained list of words (both, |
|
154 |
words and list). |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
155 |
|
1830 | 156 |
------------------------------------------------------------------------ |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
157 |
#include <mcabber/hooks.h> |
1830 | 158 |
|
159 |
typedef struct { |
|
160 |
const char *name; |
|
161 |
const char *value; |
|
162 |
} hk_arg_t; |
|
163 |
||
164 |
typedef guint (*hk_handler_t) (const gchar *hookname, |
|
165 |
hk_arg_t *args, |
|
166 |
gpointer userdata); |
|
167 |
||
168 |
guint hk_add_handler (hk_handler_t handler, |
|
169 |
const gchar *hookname, |
|
170 |
gint priority, |
|
171 |
gpointer userdata); |
|
172 |
void hk_del_handler (const gchar *hookname, |
|
173 |
guint hid); |
|
174 |
------------------------------------------------------------------------ |
|
175 |
||
176 |
These functions allow your module to react to events, such as incoming |
|
177 |
and outgoing messages, buddy status changes and server connection |
|
178 |
establishment or breakup. The hookname string specifies the events the |
|
179 |
handler wants to subscribe to. The available strings can be found in |
|
180 |
hooks.h. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
181 |
|
1830 | 182 |
The hk_add_handler() function will return a handler id which you will |
183 |
use to remove the handler with hk_del_handler(). |
|
184 |
Args argument is a list of hk_arg_t structures, terminated by structure, |
|
185 |
whose name field is set to NULL. |
|
186 |
||
187 |
Your handler should return one of the values in the hk_handler_result |
|
188 |
enum (see hooks.h), usually HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS so |
|
189 |
that other handlers can be triggers as well. |
|
190 |
||
191 |
A handler can determine which event has occured by checking the hookname |
|
192 |
argument (a same hook handler can subscribe to several events by using |
|
193 |
hk_add_handler() several times). |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
194 |
|
1830 | 195 |
Currently the following events exist: |
196 |
- hook-pre-message-in (HOOK_PRE_MESSAGE_IN) with parameters |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
197 |
* jid - sender of the incoming message |
1830 | 198 |
* resource - resource of the incoming message |
199 |
* message - message body, converted to locale charset |
|
200 |
* groupchat - ("true" or "false") |
|
1892
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1830
diff
changeset
|
201 |
* delayed - message timestamp (ISO-8601 string) or empty string if |
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1830
diff
changeset
|
202 |
the message wasn't delayed |
1830 | 203 |
- hook-post-message-in (HOOK_POST_MESSAGE_IN) with parameters |
204 |
* jid - sender of the incoming message |
|
205 |
* resource - resource of the incoming message |
|
206 |
* message - message body, converted to locale charset |
|
207 |
* groupchat - ("true" or "false") |
|
208 |
* attention - In a MUC message, true if you've been highlighted |
|
209 |
In a regular message, true if the sender has requested your |
|
210 |
attention (only implemented for MUC currently) |
|
1892
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1830
diff
changeset
|
211 |
* delayed - message timestamp (ISO-8601 string) or empty string if |
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1830
diff
changeset
|
212 |
the message wasn't delayed |
1624
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
213 |
- hook-message-out (HOOK_MESSAGE_OUT) with parameters |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
214 |
* jid - recipient of the outgoing message |
1830 | 215 |
* message - message body, converted to locale charset |
1624
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
216 |
- hook-status-change (HOOK_STATUS_CHANGE) with |
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
217 |
parameters |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
218 |
* jid - buddy, whose status has changed |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
219 |
* resource - resource, whose status has changed |
1830 | 220 |
* old_status - old status of the buddy, one-char string, |
221 |
representing mcabber status letter - one of 'ofdna?_'. |
|
222 |
* new_status - new buddy status. Same as above. |
|
223 |
* message - new status message. Old one should still be |
|
224 |
available to module as the current buddy's message. |
|
1624
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
225 |
- hook-my-status-change (HOOK_MY_STATUS_CHANGE) with |
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
226 |
parameters |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
227 |
* new_status - user's new status, see |
1830 | 228 |
hook-status-change. Old one should still be |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
229 |
available as the current status of the user. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
230 |
* message - new status message |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1669
diff
changeset
|
231 |
- hook-post-connect (HOOK_POST_CONNECT) with no parameters |
1830 | 232 |
- hook-pre-disconnect (HOOK_PRE_DISCONNECT) with no parameters |
233 |
- hook-unread-list-change (HOOK_UNREAD_LIST_CHANGE) |
|
234 |
* unread - number of buffers with the pending message flag (#) |
|
235 |
* attention - number of non-MUC buffers with the attention sign (!) |
|
236 |
* muc_unread - number of MUC buffers with the unread message flag |
|
237 |
* muc_attention - number of MUC buffers with the attention sign |
|
1906
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
238 |
- hook-subscription (HOOK_SUBSCRIPTION) |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
239 |
* type - the type of the subscription message received. Can be one |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
240 |
of subscribe, unsubscribe, subscribed, unsubscribed. |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
241 |
* jid - sender of the incoming subscription message |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
242 |
* message - optional message sent with the request |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
243 |
|
1830 | 244 |
|
245 |
------------------------------------------------------------------------ |
|
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
246 |
#include <mcabber/xmpp_helper.h> |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
247 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
248 |
void xmpp_add_feature (const char *xmlns); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
249 |
void xmpp_del_feature (const char *xmlns); |
1830 | 250 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
251 |
|
1830 | 252 |
These functions may be useful, if your module implements some additional |
253 |
functionality to mcabber, that should be advertised in a client's |
|
254 |
discovery features list. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
255 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
256 |
===================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
257 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
258 |
Example: hello |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
259 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
260 |
===================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
261 |
|
1830 | 262 |
Now, let's write a simple module, called "hello", that will do no more |
263 |
than just print something on loading and unloading. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
264 |
|
1830 | 265 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
266 |
#include <glib.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
267 |
#include <gmodule.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
268 |
|
1830 | 269 |
/* We will use scr_log_print() mcabber function, |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
270 |
that does mcabber's messages output */ |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
271 |
#include <mcabber/logprint.h> |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
272 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
273 |
/* Print something on module loading */ |
1830 | 274 |
const gchar* g_module_check_init(GModule *module) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
275 |
{ |
1830 | 276 |
scr_log_print(LPRINT_NORMAL, "Hello, World!"); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
277 |
return NULL; |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
278 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
279 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
280 |
/* ... and unloading */ |
1830 | 281 |
void g_module_unload(GModule *module) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
282 |
{ |
1830 | 283 |
scr_log_print(LPRINT_NORMAL, "Bye, World!"); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
284 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
285 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
286 |
/* The End */ |
1830 | 287 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
288 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
289 |
Now, compile this file (hello.c) with |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
290 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
291 |
libtool --mode=compile gcc `pkg-config --cflags glib-2.0 \ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
292 |
gmodule-2.0 mcabber` -c hello.c |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
293 |
libtool --mode=link gcc -module -rpath /usr/lib/mcabber/ \ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
294 |
`pkg-config --libs glib-2.0 gmodule-2.0 mcabber` \ |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
295 |
-o libhello.la hello.lo |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
296 |
|
1830 | 297 |
(you should substitute /usr/lib/mcabber to the directory where |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
298 |
your modules are located) and then install obtained module with |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
299 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
300 |
libtool --mode=install install libhello.la \ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
301 |
/usr/lib/mcabber/libhello.la |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
302 |
|
1830 | 303 |
Note that you most likely need not run suggested by libtool finish |
304 |
action, as we're working with module object, not system- wide library, |
|
305 |
but maybe some systems require that. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
306 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
307 |
Now, set modules_dir mcabber variable to point to your modules |
1830 | 308 |
directory, and try to run /module -f load hello. If all goes well, |
309 |
you should see in status buffer message "Hello World!" (as well as |
|
310 |
some complaints, as we forced module loading). |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
311 |
Now unload module by running command /module unload hello, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
312 |
that should bring up message "Bye, World!". |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
313 |
|
1830 | 314 |
That's it, you just created very simple dynamically loadable mcabber |
315 |
module. But, as you noticed, it needs force to be loaded. Now, let's |
|
316 |
add the information structure that mcabber wants. |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
317 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
318 |
========================== |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
319 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
320 |
Example: info struct |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
321 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
322 |
========================== |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
323 |
|
1830 | 324 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
325 |
#include <mcabber/logprint.h> |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
326 |
/* module_info_t definition */ |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
327 |
#include <mcabber/modules.h> |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
328 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
329 |
/* Print something on module loading */ |
1830 | 330 |
void hello_init(void) |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
331 |
{ |
1830 | 332 |
scr_log_print(LPRINT_NORMAL, "Hello, World!"); |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
333 |
} |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
334 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
335 |
/* ... and unloading */ |
1830 | 336 |
void hello_uninit(void) |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
337 |
{ |
1830 | 338 |
scr_log_print(LPRINT_NORMAL, "Bye, World!"); |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
339 |
} |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
340 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
341 |
module_info_t info_hello = { |
1752 | 342 |
.branch = "dev", |
343 |
.api = 1, |
|
1830 | 344 |
.version = "0.0.1", |
345 |
.description = "Hello world module\n" |
|
346 |
" (as well as bye world module)", |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
347 |
.requires = NULL, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
348 |
.init = hello_init, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
349 |
.uninit = hello_uninit, |
1752 | 350 |
.next = NULL, |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
351 |
}; |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
352 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
353 |
/* The End */ |
1830 | 354 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
355 |
|
1830 | 356 |
Here we still do not use glib nor gmodule, so, we can omit them in |
357 |
compilation lines: |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
358 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
359 |
libtool --mode=compile gcc `pkg-config --cflags mcabber` \ |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
360 |
-c hello.c |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
361 |
libtool --mode=link gcc -module -rpath /usr/lib/mcabber/ \ |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
362 |
`pkg-config --libs mcabber` -o libhello.la hello.lo |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
363 |
|
1830 | 364 |
Again compile it, copy, and try to load, now without -f flag. As you |
365 |
may notice, when loading previous example, mcabber first printed "Hello, |
|
366 |
World!", and only then complaint about module not having information |
|
367 |
struct. That's because g_module_check_init is called right after module |
|
368 |
loading, before mcabber even has a chance to look at module, while .init |
|
369 |
from info struct is called afterwards by mcabber itself. You can try to |
|
370 |
introduce some error (e.g. too high or missing target mcabber version) |
|
371 |
and see the difference. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
372 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
373 |
======================= |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
374 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
375 |
Example: command |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
376 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
377 |
======================= |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
378 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
379 |
Now, let's allow our module to do some real work. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
380 |
|
1830 | 381 |
------------------------------------------------------------------------ |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
382 |
#include <mcabber/logprint.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
383 |
#include <mcabber/commands.h> |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
384 |
#include <mcabber/modules.h> |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
385 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
386 |
/* Handler for command */ |
1830 | 387 |
void do_hello(char *args) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
388 |
{ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
389 |
/* args contains command line with command |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
390 |
* name and any spaces after it stripped */ |
1830 | 391 |
scr_log_print(LPRINT_NORMAL, "Hello, %s!", |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
392 |
*args != '\0' ? args : "World"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
393 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
394 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
395 |
/* Register command */ |
1830 | 396 |
void hello_init(void) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
397 |
{ |
1830 | 398 |
cmd_add("hello", "", 0, 0, do_hello, NULL); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
399 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
400 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
401 |
/* Unregister command */ |
1830 | 402 |
void hello_uninit(void) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
403 |
{ |
1830 | 404 |
cmd_del("hello"); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
405 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
406 |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
407 |
module_info_t hello_info = { |
1752 | 408 |
.branch = "dev", |
409 |
.api = 1, |
|
1830 | 410 |
.version = "0.0.2", |
411 |
.description = "Hello world module\n" |
|
412 |
" Provides command /hello", |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
413 |
.requires = NULL, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
414 |
.init = hello_init, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
415 |
.uninit = hello_uninit, |
1752 | 416 |
.next = NULL, |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
417 |
} |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
418 |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
419 |
/* The End */ |
1830 | 420 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
421 |
|
1830 | 422 |
Now, compile it and try to load and run /hello with some arguments. |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
423 |
|
1830 | 424 |
Note, that we used one-argument version of command handler, as we have |
425 |
specified no userdata. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
426 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
427 |
========================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
428 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
429 |
Example: completion |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
430 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
431 |
========================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
432 |
|
1830 | 433 |
Now let's investigate how to provide custom completion to your commands. |
434 |
You can as well use built-in completions, their IDs are listed in |
|
435 |
compl.h. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
436 |
|
1830 | 437 |
------------------------------------------------------------------------ |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
438 |
#include <mcabber/logprint.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
439 |
#include <mcabber/commands.h> |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
440 |
#include <mcabber/modules.h> |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
441 |
#include <mcabber/compl.h> |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
442 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
443 |
static guint hello_cid = 0; |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
444 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
445 |
/* hello command handler */ |
1830 | 446 |
void do_hello(char *args) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
447 |
{ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
448 |
/* If argument is provided, add it to |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
449 |
* completions list. */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
450 |
if (hello_cid && *args != '\0') |
1830 | 451 |
compl_add_category_word(hello_cid, |
452 |
args); |
|
453 |
scr_log_print(LPRINT_NORMAL, "Hello, %s!", |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
454 |
*args != '\0' ? args : "World"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
455 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
456 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
457 |
/* Initialization */ |
1830 | 458 |
void hello_init(void) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
459 |
{ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
460 |
/* Obtain handle for our completion |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
461 |
* category */ |
1830 | 462 |
hello_cid = compl_new_category(); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
463 |
if (hello_cid) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
464 |
/* Add known default word to |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
465 |
* completion list */ |
1830 | 466 |
compl_add_category_word(hello_cid, |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
467 |
"World"); |
1830 | 468 |
cmd_add("hello", "", hello_cid, 0, do_hello, |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
469 |
NULL); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
470 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
471 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
472 |
/* Deinitialization */ |
1830 | 473 |
void hello_uninit(void) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
474 |
{ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
475 |
/* Give back category handle */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
476 |
if (hello_cid) |
1830 | 477 |
compl_del_category(hello_cid); |
478 |
cmd_del("hello"); |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
479 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
480 |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
481 |
module_info_t hello_info = { |
1752 | 482 |
.branch = "dev", |
483 |
.api = 1, |
|
1830 | 484 |
.version = "0.0.3", |
485 |
.description = "Hello world module" |
|
486 |
" Provides command /hello with completion", |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
487 |
.requires = NULL, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
488 |
.init = hello_init, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
489 |
.uninit = hello_uninit, |
1752 | 490 |
.next = NULL, |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
491 |
} |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
492 |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
493 |
/* The End */ |
1830 | 494 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
495 |
|
1830 | 496 |
Now you can use completion for hello command. Note, that this code have |
497 |
some serious simplifications, made for simplicity reasons. For now, |
|
498 |
compl_add_category_word does not checks, if word already exists in |
|
499 |
completions list (although it is marked as TODO, so, some day it will), |
|
500 |
so, we should check it ourselves. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
501 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
502 |
===================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
503 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
504 |
Example: hooks |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
505 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
506 |
===================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
507 |
|
1830 | 508 |
Now let's implement our own beeper. Why may anyone wish to do this? |
509 |
I am not satisfied with default mcabber's builtin beeper flexibility. |
|
510 |
I wanted beeping on any MUC conference message, not just the ones |
|
511 |
directed to me. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
512 |
|
1830 | 513 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
514 |
#include <string.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
515 |
|
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
516 |
#include <mcabber/logprint.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
517 |
#include <mcabber/commands.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
518 |
#include <mcabber/compl.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
519 |
#include <mcabber/hooks.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
520 |
#include <mcabber/screen.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
521 |
#include <mcabber/settings.h> |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
522 |
#include <mcabber/module.h> |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
523 |
|
1830 | 524 |
static guint beep_cid = 0; /* Command completion category id */ |
525 |
static guint beep_hid = 0; /* Hook handler id */ |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
526 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
527 |
/* Event handler */ |
1830 | 528 |
static guint beep_hh(const gchar *hookname, hk_arg_t *args, |
529 |
gpointer userdata) |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
530 |
{ |
1624
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
531 |
/* Check if beeping is enabled */ |
1830 | 532 |
if (settings_opt_get_int("beep_enable")) |
533 |
scr_Beep(); /* *BEEP*! */ |
|
534 |
||
535 |
return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
536 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
537 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
538 |
/* beep command handler */ |
1830 | 539 |
static void do_beep(char *args) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
540 |
{ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
541 |
/* Check arguments, and if recognized, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
542 |
* set mcabber option accordingly */ |
1830 | 543 |
if (!strcmp(args, "enable") || |
544 |
!strcmp(args, "on") || |
|
545 |
!strcmp(args, "yes") || |
|
546 |
!strcmp(args, "1")) |
|
547 |
settings_set(SETTINGS_TYPE_OPTION, |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
548 |
"beep_enable", "1"); |
1830 | 549 |
else if (!strcmp(args, "disable") || |
550 |
!strcmp(args, "off") || |
|
551 |
!strcmp(args, "no") || |
|
552 |
!strcmp(args, "0")) |
|
553 |
settings_set(SETTINGS_TYPE_OPTION, |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
554 |
"beep_enable", "0"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
555 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
556 |
/* Output current state, either if state is |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
557 |
* changed and if argument is not recognized */ |
1830 | 558 |
if (settings_opt_get_int("beep_enable")) |
559 |
scr_log_print(LPRINT_NORMAL, |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
560 |
"Beep on messages is enabled"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
561 |
else |
1830 | 562 |
scr_log_print(LPRINT_NORMAL, |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
563 |
"Beep on messages is disabled"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
564 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
565 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
566 |
/* Initialization */ |
1830 | 567 |
static void beep_init (void) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
568 |
{ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
569 |
/* Create completions */ |
1830 | 570 |
beep_cid = compl_new_category(); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
571 |
if (beep_cid) { |
1830 | 572 |
compl_add_category_word(beep_cid, "enable"); |
573 |
compl_add_category_word(beep_cid, "disable"); |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
574 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
575 |
/* Add command */ |
1830 | 576 |
cmd_add("beep", "", beep_cid, 0, do_beep, NULL); |
1624
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
577 |
/* Add handler |
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
578 |
* We are only interested in incoming message events |
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
579 |
*/ |
1830 | 580 |
beep_hid = hk_add_handler(beep_hh, HOOK_POST_MESSAGE_IN, |
581 |
G_PRIORITY_DEFAULT_IDLE, NULL); |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
582 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
583 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
584 |
/* Deinitialization */ |
1830 | 585 |
void beep_uninit(void) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
586 |
{ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
587 |
/* Unregister event handler */ |
1830 | 588 |
hk_del_handler(HOOK_POST_MESSAGE_IN, beep_hid); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
589 |
/* Unregister command */ |
1830 | 590 |
cmd_del("beep"); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
591 |
/* Give back completion handle */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
592 |
if (beep_cid) |
1830 | 593 |
compl_del_category(beep_cid); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
594 |
} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
595 |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
596 |
module_info_t beep_info = { |
1752 | 597 |
.branch = "dev", |
598 |
.api = 1, |
|
1830 | 599 |
.version = "0.0.1", |
600 |
.description = "Simple beeper module\n" |
|
601 |
" Recognizes option beep_enable\n" |
|
602 |
" Provides command /beep", |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
603 |
.requires = NULL, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
604 |
.init = beep_init, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
605 |
.uninit = beep_uninit, |
1752 | 606 |
.next = NULL, |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
607 |
} |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
608 |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
609 |
/* The End */ |
1830 | 610 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
611 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
612 |
If you use CMake (as do I), corresponding CMakeLists.txt |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
613 |
snippet: |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
614 |
|
1830 | 615 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
616 |
cmake_minimum_required(VERSION 2.6) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
617 |
project(beep C) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
618 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
619 |
find_package(PkgConfig REQUIRED) |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
620 |
pkg_check_modules(MCABBER REQUIRED mcabber) |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
621 |
# this one should be before any target definitions |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
622 |
link_directories(${MCABBER_LIBRARY_DIRS}) |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
623 |
|
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
624 |
add_library(beep MODULE beep.c) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
625 |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
626 |
include_directories(SYSTEM ${MCABBER_INCLUDE_DIRS}) |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
627 |
target_link_libraries(beep ${MCABBER_LIBRARIES) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
628 |
include_directories(${beep_SOURCE_DIR} |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
629 |
${beep_BINARY_DIR}) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
630 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
631 |
install(TARGETS beep DESTINATION lib/mcabber) |
1830 | 632 |
------------------------------------------------------------------------ |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
633 |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
634 |
=========================== |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
635 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
636 |
Example: dependencies |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
637 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
638 |
=========================== |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
639 |
|
1830 | 640 |
I will not provide here a complete example of two modules, one of which |
641 |
depends on other, only some use cases. |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
642 |
|
1830 | 643 |
Info struct for module, that depends on two other modules: |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
644 |
|
1830 | 645 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
646 |
#include <mcabber/modules.h> |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
647 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
648 |
const gchar *a_deps[] = { "b", "c", NULL }; |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
649 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
650 |
module_info_t info_a = { |
1752 | 651 |
.branch = "dev", |
652 |
.api = 1, |
|
1830 | 653 |
.version = NULL, |
654 |
.description = NULL, |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
655 |
.requires = a_deps, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
656 |
.init = a_init, |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
657 |
.uninit = a_uninit, |
1752 | 658 |
.next = NULL, |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
659 |
}; |
1830 | 660 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
661 |
|
1830 | 662 |
If your module needs to "authenticate" mcabber version too, this can be |
663 |
done in g_module_check_init: |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
664 |
|
1830 | 665 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
666 |
#include <glib.h> |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
667 |
#include <gmodule.h> |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
668 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
669 |
#include <mcabber/main.h> |
1752 | 670 |
#include <mcabber/modules.h> |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
671 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
672 |
const gchar *g_module_check_init (GModule *module) |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
673 |
{ |
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
674 |
char *ver = mcabber_version (); |
1752 | 675 |
// ver now contains version in format |
676 |
// X.X.X[-xxx][ (XXXXXXXXXXXXX)] |
|
677 |
const gchar *branch = mcabber_branch; |
|
678 |
guint api = mcabber_api_version; |
|
679 |
const gchar *error = NULL; |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
680 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
681 |
if (...) |
1752 | 682 |
error = "Incompatible mcabber version"; |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
683 |
|
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
684 |
g_free (ver); |
1752 | 685 |
return error; |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
686 |
} |
1830 | 687 |
------------------------------------------------------------------------ |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
688 |
|
1830 | 689 |
Also you can use glib check_init routine to modify module information, |
690 |
that will be checked by mcabber, e.g. if you want your module to always |
|
691 |
pass mcabber version check, you can assign branch information, obtained |
|
692 |
from mcabber_... variables to corresponding fields in your struct. |
|
693 |
Or you can modify your module's dependencies, though direct |
|
694 |
module_load() will have the same effect, and can be used for optional |
|
695 |
dependencies, that your module can still work without. |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
696 |
|
1830 | 697 |
Note: remember, that g_module_check_init will be always called, even if |
698 |
later the module will not pass checks, thus: |
|
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
699 |
- do not use functions from other modules there; |
1830 | 700 |
- provide g_module_unload to undo anything, check_init has done. |
1735
5093b5ca1572
New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1683
diff
changeset
|
701 |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
702 |
============== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
703 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
704 |
Further |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
705 |
|
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
706 |
============== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
707 |
|
1830 | 708 |
As mcabber now uses glib mainloop, you can use glib's event sources, for |
709 |
example, fifo reading already uses GIOChannels for non-blocking IO. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
710 |
|
1830 | 711 |
You can extend XMPP part of mcabber functionality by providing lm |
712 |
message handlers with high priority and allowing unhandled by your |
|
713 |
handler messages be taken care by mcabber's handlers on normal priority |
|
714 |
level. This is where you may need to modify set of advertised supported |
|
715 |
disco features. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
716 |
|
1830 | 717 |
Many useful examples can be found in my modules, that can be found at |
718 |
http://isbear.unixzone.org.ua/source. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
719 |
|
1830 | 720 |
If you think, that your module needs to change something, hardcoded in |
721 |
current implementation - feel free to mail me or join mcabber's MUC room |
|
722 |
and discuss it - for now we have only implemented things, that we have |
|
723 |
found necessary for our own modules. |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
724 |
|
1830 | 725 |
Also I am not native English speaker, so, if you find some errors or |
726 |
non-natural constructs in this howto, please, inform me (I will be glad, |
|
727 |
if you also provide a more suitable version of text in question). |
|
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
728 |
|
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
729 |
-- Myhailo Danylenko |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
730 |
-- mailto:isbear@ukrpost.net |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
731 |
-- xmpp:isbear@unixzone.org.ua |
1830 | 732 |
-- Sat, 27 Mar 2010 13:30:00 +0100 |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
733 |