annotate libpurple/plugins/debug_example.c @ 31447:1884f1f2013b

propagate from branch 'im.pidgin.pidgin' (head 47179f04bde4a1cd3857fd05eb4e40f25ee9e26f) to branch 'im.pidgin.cpw.qulogic.cairo' (head c10b48bebcd04adcd6dad3d199fe09675a28219d)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 21 Aug 2010 05:42:17 +0000
parents 3cc856ca2338
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19908
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2 * Debug Example Plugin
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
19911
bdffee131b80 Fix my e-mail address to match my MTN key since it now is a real e-mail address.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19908
diff changeset
4 * Copyright (C) 2007, John Bailey <rekkanoryo@cpw.pidgin.im>
19908
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
5 *
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
8 * published by the Free Software Foundation; either version 2 of the
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
9 * License, or (at your option) any later version.
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 *
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
14 * General Public License for more details.
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 *
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
19 * 02111-1301, USA.
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
20 *
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
21 */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
22
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
24 # include <config.h>
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
25 #endif
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
26
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
27 /* We're including glib.h again for the gboolean type. */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
28 #include <glib.h>
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
29
20101
3a5f152e7ed0 This fixes compilation issues where old glib and either an old gcc or a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19911
diff changeset
30 /* This will prevent compiler errors in some instances and is better explained in the
3a5f152e7ed0 This fixes compilation issues where old glib and either an old gcc or a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19911
diff changeset
31 * how-to documents on the wiki */
3a5f152e7ed0 This fixes compilation issues where old glib and either an old gcc or a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19911
diff changeset
32 #ifndef G_GNUC_NULL_TERMINATED
3a5f152e7ed0 This fixes compilation issues where old glib and either an old gcc or a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19911
diff changeset
33 # if __GNUC__ >= 4
3a5f152e7ed0 This fixes compilation issues where old glib and either an old gcc or a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19911
diff changeset
34 # define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
3a5f152e7ed0 This fixes compilation issues where old glib and either an old gcc or a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19911
diff changeset
35 # else
3a5f152e7ed0 This fixes compilation issues where old glib and either an old gcc or a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19911
diff changeset
36 # define G_GNUC_NULL_TERMINATED
3a5f152e7ed0 This fixes compilation issues where old glib and either an old gcc or a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19911
diff changeset
37 # endif
3a5f152e7ed0 This fixes compilation issues where old glib and either an old gcc or a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19911
diff changeset
38 #endif
3a5f152e7ed0 This fixes compilation issues where old glib and either an old gcc or a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19911
diff changeset
39
19908
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
40 /* This is the required definition of PURPLE_PLUGINS as required for a plugin,
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
41 * but we protect it with an #ifndef because config.h may define it for us
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
42 * already and this would cause an unneeded compiler warning. */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
43 #ifndef PURPLE_PLUGINS
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
44 # define PURPLE_PLUGINS
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
45 #endif
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
46
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
47 /* Here we're including the necessary libpurple headers for this plugin. Note
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
48 * that we're including them in alphabetical order. This isn't necessary but
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
49 * we do this throughout our source for consistency. */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
50 #include "debug.h"
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
51 #include "plugin.h"
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
52 #include "version.h"
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
53
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
54 /* It's more convenient to type PLUGIN_ID all the time than it is to type
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
55 * "core-debugexample", so define this convenience macro. */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
56 #define PLUGIN_ID "core-debugexample"
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
57
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
58 /* Common practice in third-party plugins is to define convenience macros for
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
59 * many of the fields of the plugin info struct, so we'll do that for the
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
60 * purposes of demonstration. */
19911
bdffee131b80 Fix my e-mail address to match my MTN key since it now is a real e-mail address.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19908
diff changeset
61 #define PLUGIN_AUTHOR "John Bailey <rekkanoryo@cpw.pidgin.im>"
19908
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
62
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
63 /* As we've covered before, libpurple calls this function, if present, when it
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
64 * loads the plugin. Here we're using it to show off the capabilities of the
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
65 * debug API and just blindly returning TRUE to tell libpurple it's safe to
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
66 * continue loading. */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
67 static gboolean
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
68 plugin_load(PurplePlugin *plugin)
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
69 {
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
70 /* Define these for convenience--we're just using them to show the
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
71 * similarities of the debug functions to the standard printf(). */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
72 gint i = 256;
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
73 gfloat f = 512.1024;
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
74 const gchar *s = "example string";
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
75
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
76 /* Introductory message */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
77 purple_debug_info(PLUGIN_ID,
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
78 "Called plugin_load. Beginning debug demonstration\n");
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
79
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
80 /* Show off the debug API a bit */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
81 purple_debug_misc(PLUGIN_ID,
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
82 "MISC level debug message. i = %d, f = %f, s = %s\n", i, f, s);
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
83
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
84 purple_debug_info(PLUGIN_ID,
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
85 "INFO level debug message. i = %d, f = %f, s = %s\n", i, f, s);
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
86
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
87 purple_debug_warning(PLUGIN_ID,
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
88 "WARNING level debug message. i = %d, f = %f, s = %s\n", i, f, s);
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
89
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
90 purple_debug_error(PLUGIN_ID,
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
91 "ERROR level debug message. i = %d, f = %f, s = %s\n", i, f, s);
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
92
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
93 purple_debug_fatal(PLUGIN_ID,
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
94 "FATAL level debug message. i = %d, f = %f, s = %s\n", i, f, s);
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
95
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
96 /* Now just return TRUE to tell libpurple to finish loading. */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
97 return TRUE;
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
98 }
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
99
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
100 static PurplePluginInfo info = {
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
101 PURPLE_PLUGIN_MAGIC, /* magic number */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
102 PURPLE_MAJOR_VERSION, /* purple major */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
103 PURPLE_MINOR_VERSION, /* purple minor */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
104 PURPLE_PLUGIN_STANDARD, /* plugin type */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
105 NULL, /* UI requirement */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
106 0, /* flags */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
107 NULL, /* dependencies */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
108 PURPLE_PRIORITY_DEFAULT, /* priority */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
109
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
110 PLUGIN_ID, /* id */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
111 "Debug API Example", /* name */
21030
3cc856ca2338 Add a --with-extraversion option to ./configure so packagers can fine tune
Stu Tomlinson <stu@nosnilmot.com>
parents: 20101
diff changeset
112 DISPLAY_VERSION, /* version */
19908
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
113 "Debug API Example", /* summary */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
114 "Debug API Example", /* description */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
115 PLUGIN_AUTHOR, /* author */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
116 "http://pidgin.im", /* homepage */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
117
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
118 plugin_load, /* load */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
119 NULL, /* unload */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
120 NULL, /* destroy */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
121
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
122 NULL, /* ui info */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
123 NULL, /* extra info */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
124 NULL, /* prefs info */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
125 NULL, /* actions */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
126 NULL, /* reserved */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
127 NULL, /* reserved */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
128 NULL, /* reserved */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
129 NULL /* reserved */
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
130 };
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
131
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
132 static void
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
133 init_plugin(PurplePlugin *plugin)
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
134 {
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
135 }
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
136
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
137 PURPLE_INIT_PLUGIN(debugexample, init_plugin, info)
0715328a0be3 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
138