annotate plugins/dbus-example.c @ 12693:07d6cc1b5a98

[gaim-migrate @ 15036] Don't show Unset in the list of status types. This has been bugging me for a while. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Tue, 03 Jan 2006 09:05:14 +0000
parents 4295083cf489
children a7b24ba66570
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11173
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
1 /*
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
2 This is an example of a gaim dbus plugin. After enabling this
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
3 plugin, the following commands should work from the command line:
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
4
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
5 prompt$ gaim-send DbusExampleGetHelloObject
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
6
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
7 returns, say: int32 74
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
8
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
9 prompt$ gaim-send DbusExampleGetText int32:74
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
10
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
11 returns: string "Hello."
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
12
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
13 prompt$ gaim-send DbusExampleSetText int32:74 string:Bye!
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
14
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
15 prompt$ gaim-send DbusExampleGetText int32:74
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
16
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
17 returns: string "Bye!"
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
18
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
19 */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
20
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
21 #include "internal.h"
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
22
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
23 #include "plugin.h"
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
24 #include "blist.h"
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
25 #include "version.h"
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
26
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
27 #include <stdio.h>
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
28 #include <stdlib.h>
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
29 #include <string.h>
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
30
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
31 #define DBUS_API_SUBJECT_TO_CHANGE
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
32 #include "dbus-maybe.h"
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
33 #include "dbus-bindings.h"
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
34
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
35 typedef struct {
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
36 char *text;
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
37 } GaimText;
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
38
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
39 /* This makes the structure GaimText visible to the gaim-dbus type
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
40 system. It defines GaimText as a type with no parent. From now
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
41 on, we will be able to register pointers to structures of this
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
42 type. You to dbus-define types you want to be directly accessible
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
43 by external applications. */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
44 GAIM_DBUS_DEFINE_TYPE(GaimText)
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
45
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
46 /* Here we make four functions accessible to other applications by
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
47 DBus. These functions can access types defined in gaim proper
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
48 (GaimBuddy) as well as the types defined in the plugin (GaimText). */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
49 DBUS_EXPORT GaimText* dbus_example_get_hello_object(void);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
50 DBUS_EXPORT void dbus_example_set_text(GaimText *obj, const char *text);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
51 DBUS_EXPORT const char *dbus_example_get_text(GaimText *obj);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
52 DBUS_EXPORT const char *dbus_example_get_buddy_name(GaimBuddy *buddy);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
53
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
54 /* This file has been generated by the #dbus-analize-functions.py
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
55 script. It contains dbus wrappers for the four functions declared
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
56 above. */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
57 #include "dbus-example-bindings.c"
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
58
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
59 /* This is the GaimText object we want to make publicly visible. */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
60 static GaimText hello;
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
61
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
62 /* Here come the definitions of the four exported functions. */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
63 GaimText* dbus_example_get_hello_object(void)
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
64 {
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
65 return &hello;
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
66 }
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
67
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
68 void dbus_example_set_text(GaimText *obj, const char *text)
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
69 {
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
70 if (obj != NULL) {
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
71 g_free(obj->text);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
72 obj->text = g_strdup(text);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
73 }
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
74 }
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
75
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
76 const char *dbus_example_get_text(GaimText *obj)
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
77 {
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
78 if (obj != NULL)
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
79 return obj->text;
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
80 else
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
81 return NULL;
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
82 }
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
83
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
84 const char *dbus_example_get_buddy_name(GaimBuddy *buddy)
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
85 {
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
86 return gaim_buddy_get_name(buddy);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
87 }
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
88
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
89 /* And now standard plugin stuff */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
90
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
91 static gboolean
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
92 plugin_load(GaimPlugin *plugin)
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
93 {
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
94 /* First, we have to register our four exported functions with the
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
95 main gaim dbus loop. Without this statement, the gaim dbus
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
96 code wouldn't know about our functions. */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
97 GAIM_DBUS_REGISTER_BINDINGS(plugin);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
98
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
99 /* Then, we register the hello object of type GaimText. Note that
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
100 pointer registrations / unregistrations are completely dynamic;
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
101 they don't have to be made when the plugin is loaded /
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
102 unloaded. Without this statement the dbus gaim code wouldn't
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
103 know about the hello object. */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
104 GAIM_DBUS_REGISTER_POINTER(&hello, GaimText);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
105
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
106 hello.text = g_strdup("Hello.");
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
107
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
108 return TRUE;
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
109 }
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
110
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
111
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
112 static gboolean
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
113 plugin_unload(GaimPlugin *plugin)
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
114 {
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
115 g_free(hello.text);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
116
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
117 /* It is necessary to unregister all pointers registered by the module. */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
118 GAIM_DBUS_UNREGISTER_POINTER(&hello);
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
119
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
120 return TRUE;
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
121 }
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
122
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
123 static GaimPluginInfo info =
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
124 {
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
125 GAIM_PLUGIN_MAGIC,
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
126 GAIM_MAJOR_VERSION,
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
127 GAIM_MINOR_VERSION,
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
128 GAIM_PLUGIN_STANDARD, /**< type */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
129 NULL, /**< ui_requirement */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
130 0, /**< flags */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
131 NULL, /**< dependencies */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
132 GAIM_PRIORITY_DEFAULT, /**< priority */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
133
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
134 "dbus-example", /**< id */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
135 N_("DBus"), /**< name */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
136 VERSION, /**< version */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
137 /** summary */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
138 N_("DBus Plugin Example"),
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
139 /** description */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
140 N_("DBus Plugin Example"),
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
141 "Piotr Zielinski (http://cl.cam.ac.uk/~pz215)", /**< author */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
142 GAIM_WEBSITE, /**< homepage */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
143
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
144 plugin_load, /**< load */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
145 plugin_unload, /**< unload */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
146 NULL, /**< destroy */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
147
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
148 NULL, /**< ui_info */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
149 NULL, /**< extra_info */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
150 NULL, /**< prefs_info */
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
151 NULL
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
152 };
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
153
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
154 static void init_plugin(GaimPlugin *plugin)
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
155 {
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
156 }
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
157
91ca67258564 [gaim-migrate @ 13278]
Piotr Zielinski <zielaj>
parents:
diff changeset
158 GAIM_INIT_PLUGIN(dbus_example, init_plugin, info)