libpurple/plugins/debug_example.c

Mon, 16 Sep 2013 23:02:23 +0530

author
Ankit Vani <a@nevitus.org>
date
Mon, 16 Sep 2013 23:02:23 +0530
branch
soc.2013.gobjectification.plugins
changeset 36753
a1d2fa3be516
parent 36739
472bef54ba0a
child 36792
764b45883fba
permissions
-rw-r--r--

Use g_object_[sg]et_data in joinpart

19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2 * Debug Example Plugin
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
19878
aa9d2cfa70bf 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: 19875
diff changeset
4 * Copyright (C) 2007, John Bailey <rekkanoryo@cpw.pidgin.im>
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
5 *
ace837283c37 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
ace837283c37 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
ace837283c37 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
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
9 * License, or (at your option) any later version.
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 *
ace837283c37 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
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
14 * General Public License for more details.
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 *
ace837283c37 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
ace837283c37 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
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
19 * 02111-1301, USA.
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
20 *
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
21 */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
22
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
24 # include <config.h>
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
25 #endif
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
26
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
27 /* We're including glib.h again for the gboolean type. */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
28 #include <glib.h>
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
29
20084
7b3c24de3714 applied changes from f4700a52b60d8473e9671ceabfec7772211fe424
Richard Laager <rlaager@pidgin.im>
parents: 19878
diff changeset
30 /* This will prevent compiler errors in some instances and is better explained in the
7b3c24de3714 applied changes from f4700a52b60d8473e9671ceabfec7772211fe424
Richard Laager <rlaager@pidgin.im>
parents: 19878
diff changeset
31 * how-to documents on the wiki */
7b3c24de3714 applied changes from f4700a52b60d8473e9671ceabfec7772211fe424
Richard Laager <rlaager@pidgin.im>
parents: 19878
diff changeset
32 #ifndef G_GNUC_NULL_TERMINATED
7b3c24de3714 applied changes from f4700a52b60d8473e9671ceabfec7772211fe424
Richard Laager <rlaager@pidgin.im>
parents: 19878
diff changeset
33 # if __GNUC__ >= 4
7b3c24de3714 applied changes from f4700a52b60d8473e9671ceabfec7772211fe424
Richard Laager <rlaager@pidgin.im>
parents: 19878
diff changeset
34 # define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
7b3c24de3714 applied changes from f4700a52b60d8473e9671ceabfec7772211fe424
Richard Laager <rlaager@pidgin.im>
parents: 19878
diff changeset
35 # else
7b3c24de3714 applied changes from f4700a52b60d8473e9671ceabfec7772211fe424
Richard Laager <rlaager@pidgin.im>
parents: 19878
diff changeset
36 # define G_GNUC_NULL_TERMINATED
7b3c24de3714 applied changes from f4700a52b60d8473e9671ceabfec7772211fe424
Richard Laager <rlaager@pidgin.im>
parents: 19878
diff changeset
37 # endif
7b3c24de3714 applied changes from f4700a52b60d8473e9671ceabfec7772211fe424
Richard Laager <rlaager@pidgin.im>
parents: 19878
diff changeset
38 #endif
7b3c24de3714 applied changes from f4700a52b60d8473e9671ceabfec7772211fe424
Richard Laager <rlaager@pidgin.im>
parents: 19878
diff changeset
39
19875
ace837283c37 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,
ace837283c37 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
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
42 * already and this would cause an unneeded compiler warning. */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
43 #ifndef PURPLE_PLUGINS
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
44 # define PURPLE_PLUGINS
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
45 #endif
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
46
ace837283c37 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
ace837283c37 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
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
49 * we do this throughout our source for consistency. */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
50 #include "debug.h"
36367
891eea799578 Renamed plugin.[ch] to plugins.[ch], since we (will) no longer have a PurplePlugin structure.
Ankit Vani <a@nevitus.org>
parents: 33955
diff changeset
51 #include "plugins.h"
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
52 #include "version.h"
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
53
ace837283c37 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
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
55 * "core-debugexample", so define this convenience macro. */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
56 #define PLUGIN_ID "core-debugexample"
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
57
ace837283c37 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
ace837283c37 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
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
60 * purposes of demonstration. */
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
61 #define PLUGIN_AUTHORS { "John Bailey <rekkanoryo@cpw.pidgin.im>", NULL }
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
62
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
63 static PurplePluginInfo *
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
64 plugin_query(GError **error)
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
65 {
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
66 const gchar * const authors[] = PLUGIN_AUTHORS;
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
67
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
68 return purple_plugin_info_new(
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
69 "id", PLUGIN_ID,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
70 "name", "Debug API Example",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
71 "version", DISPLAY_VERSION,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
72 "category", "Example",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
73 "summary", "Debug API Example",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
74 "description", "Debug API Example",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
75 "authors", authors,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
76 "website", "https://pidgin.im",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
77 "abi-version", PURPLE_ABI_VERSION,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
78 NULL
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
79 );
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
80 }
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
81
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
82 /* As we've covered before, libpurple calls this function, if present, when it
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
83 * loads the plugin. Here we're using it to show off the capabilities of the
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
84 * debug API and just blindly returning TRUE to tell libpurple it's safe to
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
85 * continue loading. */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
86 static gboolean
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
87 plugin_load(PurplePlugin *plugin, GError **error)
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
88 {
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
89 /* Define these for convenience--we're just using them to show the
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
90 * similarities of the debug functions to the standard printf(). */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
91 gint i = 256;
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
92 gfloat f = 512.1024;
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
93 const gchar *s = "example string";
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
94
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
95 /* Introductory message */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
96 purple_debug_info(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
97 "Called plugin_load. Beginning debug demonstration\n");
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
98
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
99 /* Show off the debug API a bit */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
100 purple_debug_misc(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
101 "MISC level debug message. i = %d, f = %f, s = %s\n", i, f, s);
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
102
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
103 purple_debug_info(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
104 "INFO level debug message. i = %d, f = %f, s = %s\n", i, f, s);
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
105
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
106 purple_debug_warning(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
107 "WARNING level debug message. i = %d, f = %f, s = %s\n", i, f, s);
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
108
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
109 purple_debug_error(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
110 "ERROR level debug message. i = %d, f = %f, s = %s\n", i, f, s);
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
111
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
112 purple_debug_fatal(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
113 "FATAL level debug message. i = %d, f = %f, s = %s\n", i, f, s);
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
114
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
115 /* Now just return TRUE to tell libpurple to finish loading. */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
116 return TRUE;
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
117 }
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
118
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
119 static gboolean
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
120 plugin_unload(PurplePlugin *plugin, GError **error)
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
121 {
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
122 return TRUE;
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
123 }
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
124
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
125 PURPLE_PLUGIN_INIT(debugexample, plugin_query, plugin_load, plugin_unload);
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
126

mercurial