Mon, 24 Sep 2018 21:12:06 -0500
Remove a missed reference of valgrind.h
|
35389
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
1 | <?xml version='1.0' encoding="ISO-8859-1"?> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
2 | <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
3 | "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [ |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
4 | ]> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
5 | <chapter id="chapter-tut-signals"> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
6 | <title>Signals tutorial</title> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
7 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
8 | <sect2 id="tut-signals-introduction"> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
9 | <title>Introduction</title> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
10 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
11 | The libpurple signals interface is used for general event notification, such |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
12 | as plugins being loaded or unloaded, allowing the GUI frontend to respond |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
13 | appropriately to changing internal data. Unfortunately, its use is not at all |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
14 | obvious from the information in the header files. This document uses code |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
15 | snippets from the Pidgin/libpurple plugin systems to illustrate the proper |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
16 | use of signals. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
17 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
18 | </sect2> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
19 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
20 | <sect2 id="tut-signals-overview"> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
21 | <title>Overview of Purple-signals</title> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
22 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
23 | Signals in libpurple are very similar to those in GTK+. When certain events |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
24 | happen, a named signal is "emitted" from a certain object. Emitting the |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
25 | signal triggers a series of callbacks that have been "connected" to that |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
26 | signal for that object. These callbacks take appropriate action in response |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
27 | to the signal. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
28 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
29 | </sect2> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
30 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
31 | <sect2 id="tut-signals-registering"> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
32 | <title>Registering a Signal</title> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
33 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
34 | The first step of using a signal is registering it with libpurple so that |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
35 | callbacks may be connected to it. This is done using |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
36 | <link linkend="purple-signal-register"><function>purple_signal_register()</function></link>. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
37 | Here is a slightly modified example from |
|
35427
d8b39c2329dd
Use func() format for functions in signals tuts
Ankit Vani <a@nevitus.org>
parents:
35389
diff
changeset
|
38 | <link linkend="purple-plugins-init"><function>purple_plugins_init()</function></link> |
|
37028
ec211f9d9e81
Fix file name in tut_signals.xml
Ankit Vani <a@nevitus.org>
parents:
36921
diff
changeset
|
39 | in <literal>plugins.c</literal>: |
|
35389
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
40 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
41 | <programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
42 | purple_signal_register(purple_plugins_get_handle(), /* Instance */ |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
43 | "plugin-load", /* Signal name */ |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
44 | purple_marshal_VOID__POINTER,/* Marshal function */ |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
45 | G_TYPE_NONE, /* Callback return type */ |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
46 | 1, /* Number of callback arguments (not including void *data) */ |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
47 | PURPLE_TYPE_PLUGIN /* Type of first callback argument */ |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
48 | ); |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
49 | </programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
50 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
51 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
52 | <sect3> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
53 | <title>Instance</title> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
54 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
55 | A reference to the object from which this signal is emitted, and to which |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
56 | potential callbacks should be connected. In this case, it will be the entire |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
57 | plugin module emitting the signal. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
58 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
59 | </sect3> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
60 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
61 | <sect3> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
62 | <title>Signal Name</title> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
63 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
64 | Unique identifier for the signal itself. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
65 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
66 | </sect3> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
67 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
68 | <sect3> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
69 | <title>Callback function definition</title> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
70 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
71 | The rest of the arguments specify the form of the callback function. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
72 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
73 | <itemizedlist> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
74 | <listitem><para><emphasis>Marshal function</emphasis></para><para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
75 | <literal>purple_marshal_VOID__POINTER</literal> represents the callback |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
76 | function prototype, not including a "data" argument, explained later. The form |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
77 | is <literal>purple_marshal_RETURNVALUETYPE__ARG1TYPE_ARG2TYPE_ETC</literal>. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
78 | See <link linkend="libpurple-signals">signals.h</link> for more possible types. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
79 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
80 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
81 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
82 | In this case, the callback will have the form |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
83 | <programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
84 | void cb(void *arg1, void *data) |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
85 | </programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
86 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
87 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
88 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
89 | If <literal>purple_marshal_BOOLEAN__POINTER_POINTER_POINTER</literal> were |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
90 | specified, it would be: |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
91 | <programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
92 | gboolean cb(void *arg1, void *arg2, void *arg3, void *data) |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
93 | </programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
94 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
95 | The <literal>void *data</literal> argument at the end of each callback function |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
96 | provides the data argument given to |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
97 | <link linkend="purple-signal-connect"><function>purple_signal_connect()</function></link>. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
98 | </para></listitem> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
99 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
100 | <listitem><para><emphasis>Callback return type</emphasis></para><para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
101 | In our case, this is G_TYPE_NONE, meaning "returns void". |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
102 | <!-- TODO This could be described better. --> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
103 | </para></listitem> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
104 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
105 | <listitem><para><emphasis>Number of callback arguments</emphasis></para><para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
106 | The number of arguments (not including <literal>data</literal>) that the callback function |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
107 | will take. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
108 | </para></listitem> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
109 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
110 | <listitem><para><emphasis>Type of argument</emphasis></para><para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
111 | <literal>PURPLE_TYPE_PLUGIN</literal> specifies that the first argument given to the callback |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
112 | will be a <literal>PurplePlugin*</literal>. You will need as many "type of argument" |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
113 | arguments to |
|
35427
d8b39c2329dd
Use func() format for functions in signals tuts
Ankit Vani <a@nevitus.org>
parents:
35389
diff
changeset
|
114 | <link linkend="purple-signal-register"><function>purple_signal_register()</function></link> |
|
35389
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
115 | as you specified in |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
116 | "Number of arguments" above. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
117 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
118 | <!-- TODO Describe this more. --> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
119 | </para></listitem> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
120 | </itemizedlist> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
121 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
122 | </sect3> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
123 | </sect2> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
124 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
125 | <sect2 id="tut-signals-connect"> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
126 | <title>Connecting to the signal</title> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
127 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
128 | Once the signal is registered, you can connect callbacks to it. First, you |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
129 | must define a callback function, such as this one from gtkplugin.c : |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
130 | <programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
131 | static void plugin_load_cb(PurplePlugin *plugin, gpointer data) |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
132 | { |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
133 | GtkTreeView *view = (GtkTreeView *)data; |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
134 | plugin_loading_common(plugin, view, TRUE); |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
135 | } |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
136 | </programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
137 | Note that the callback function prototype matches that specified in the call |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
138 | to <link linkend="purple-signal-register"><function>purple_signal_register()</function></link> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
139 | above. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
140 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
141 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
142 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
143 | Once the callback function is defined, you can connect it to the signal. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
144 | Again from gtkplugin.c , in <function>pidgin_plugin_dialog_show()</function>: |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
145 | <programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
146 | purple_signal_connect(purple_plugins_get_handle(), "plugin-load", /* What to connect to */ |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
147 | plugin_dialog, /* Object receiving the signal */ |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
148 | PURPLE_CALLBACK(plugin_load_cb), /* Callback function */ |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
149 | event_view, /* Data to pass to the callback function |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
150 | ); |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
151 | </programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
152 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
153 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
154 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
155 | The first two arguments ("What to connect to") specify the object emitting |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
156 | the signal (the plugin module) and what signal to listen for ("plugin-load"). |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
157 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
158 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
159 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
160 | The object receiving the signal is <literal>plugin_dialog</literal> , the Pidgin plugins |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
161 | dialog. When <literal>plugin_dialog</literal> is deleted, then |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
162 | <literal>purple_signals_disconnect_by_handle(plugin_dialog)</literal> should be called to |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
163 | remove all signal connections it is associated with. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
164 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
165 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
166 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
167 | The callback function is given using a helper macro, and finally the |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
168 | <literal>data</literal> argument to be passed to |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
169 | <literal>plugin_load_cb</literal> is given as <literal>event_view</literal>, |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
170 | a pointer to the GTK widget that <literal>plugin_load_cb</literal> needs to update. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
171 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
172 | </sect2> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
173 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
174 | <sect2 id="tut-signals-emit-signal"> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
175 | <title>Emitting a signal</title> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
176 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
177 | Connecting callbacks to signals is all well and good, but how do you "fire" |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
178 | the signal and trigger the callback? At some point, you must "emit" the |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
179 | signal, which immediately calls all connected callbacks. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
180 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
181 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
182 | <para> |
|
35427
d8b39c2329dd
Use func() format for functions in signals tuts
Ankit Vani <a@nevitus.org>
parents:
35389
diff
changeset
|
183 | As seen in <link linkend="purple-plugin-load"><function>purple_plugin_load()</function></link> |
|
35389
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
184 | in plugin.c: |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
185 | <programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
186 | purple_signal_emit(purple_plugins_get_handle(), "plugin-load", plugin); |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
187 | </programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
188 | This causes the signal "plugin-load" to be emitted from the plugin module |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
189 | (given by |
|
35427
d8b39c2329dd
Use func() format for functions in signals tuts
Ankit Vani <a@nevitus.org>
parents:
35389
diff
changeset
|
190 | <link linkend="purple-plugins-get-handle"><function>purple_plugins_get_handle()</function></link>), |
|
35389
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
191 | with the newly loaded plugin as |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
192 | the argument to pass to any registered callback functions. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
193 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
194 | |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
195 | <para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
196 | In our example, <literal>plugin_load_cb</literal> is called immediately as |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
197 | <programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
198 | plugin_load_cb(plugin, event_view); |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
199 | </programlisting> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
200 | and does whatever it does. |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
201 | </para> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
202 | </sect2> |
|
884a5385bb2c
Added doc/reference directory with the documentation .xml files
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
203 | </chapter> |