Mercurial > pidgin
comparison plugins/dbus-example.c @ 14035:8bda65b88e49
[gaim-migrate @ 16638]
A bunch of small changes. Mostly remove "if not null" checks before
calling g_free, g_list_free, g_slist_free and g_strdup. Also use
g_list_foreach() to call g_free to free strings in an array. And
some whitespace changes here and there.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sat, 05 Aug 2006 08:27:39 +0000 |
| parents | b43aec5fa9eb |
| children |
comparison
equal
deleted
inserted
replaced
| 14034:0839a7b71325 | 14035:8bda65b88e49 |
|---|---|
| 49 #define DBUS_API_SUBJECT_TO_CHANGE | 49 #define DBUS_API_SUBJECT_TO_CHANGE |
| 50 #include "dbus-maybe.h" | 50 #include "dbus-maybe.h" |
| 51 #include "dbus-bindings.h" | 51 #include "dbus-bindings.h" |
| 52 | 52 |
| 53 typedef struct { | 53 typedef struct { |
| 54 char *text; | 54 char *text; |
| 55 } GaimText; | 55 } GaimText; |
| 56 | 56 |
| 57 /* This makes the structure GaimText visible to the gaim-dbus type | 57 /* This makes the structure GaimText visible to the gaim-dbus type |
| 58 system. It defines GaimText as a type with no parent. From now | 58 system. It defines GaimText as a type with no parent. From now |
| 59 on, we will be able to register pointers to structures of this | 59 on, we will be able to register pointers to structures of this |
| 60 type. You to dbus-define types you want to be directly accessible | 60 type. You to dbus-define types you want to be directly accessible |
| 61 by external applications. */ | 61 by external applications. */ |
| 62 GAIM_DBUS_DEFINE_TYPE(GaimText) | 62 GAIM_DBUS_DEFINE_TYPE(GaimText) |
| 63 | 63 |
| 64 /* Here we make four functions accessible to other applications by | 64 /* Here we make four functions accessible to other applications by |
| 65 DBus. These functions can access types defined in gaim proper | 65 DBus. These functions can access types defined in gaim proper |
| 66 (GaimBuddy) as well as the types defined in the plugin (GaimText). */ | 66 (GaimBuddy) as well as the types defined in the plugin (GaimText). */ |
| 67 DBUS_EXPORT GaimText* dbus_example_get_hello_object(void); | 67 DBUS_EXPORT GaimText* dbus_example_get_hello_object(void); |
| 76 | 76 |
| 77 /* This is the GaimText object we want to make publicly visible. */ | 77 /* This is the GaimText object we want to make publicly visible. */ |
| 78 static GaimText hello; | 78 static GaimText hello; |
| 79 | 79 |
| 80 /* Here come the definitions of the four exported functions. */ | 80 /* Here come the definitions of the four exported functions. */ |
| 81 GaimText* dbus_example_get_hello_object(void) | 81 GaimText* dbus_example_get_hello_object(void) |
| 82 { | 82 { |
| 83 return &hello; | 83 return &hello; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void dbus_example_set_text(GaimText *obj, const char *text) | 86 void dbus_example_set_text(GaimText *obj, const char *text) |
| 87 { | 87 { |
| 88 if (obj != NULL) { | 88 if (obj != NULL) { |
| 89 g_free(obj->text); | 89 g_free(obj->text); |
| 90 obj->text = g_strdup(text); | 90 obj->text = g_strdup(text); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 const char *dbus_example_get_text(GaimText *obj) | 94 const char *dbus_example_get_text(GaimText *obj) |
| 95 { | 95 { |
| 96 if (obj != NULL) | 96 if (obj != NULL) |
| 97 return obj->text; | 97 return obj->text; |
| 98 else | 98 else |
| 99 return NULL; | 99 return NULL; |
| 100 } | 100 } |
| 101 | 101 |
| 102 const char *dbus_example_get_buddy_name(GaimBuddy *buddy) | 102 const char *dbus_example_get_buddy_name(GaimBuddy *buddy) |
| 103 { | 103 { |
| 104 return gaim_buddy_get_name(buddy); | 104 return gaim_buddy_get_name(buddy); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /* And now standard plugin stuff */ | 107 /* And now standard plugin stuff */ |
| 108 | 108 |
| 109 static gboolean | 109 static gboolean |
| 110 plugin_load(GaimPlugin *plugin) | 110 plugin_load(GaimPlugin *plugin) |
| 111 { | 111 { |
| 112 GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin); | 112 GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin); |
| 113 | 113 |
| 114 /* First, we have to register our four exported functions with the | 114 /* First, we have to register our four exported functions with the |
| 115 main gaim dbus loop. Without this statement, the gaim dbus | 115 main gaim dbus loop. Without this statement, the gaim dbus |
| 116 code wouldn't know about our functions. */ | 116 code wouldn't know about our functions. */ |
| 117 GAIM_DBUS_REGISTER_BINDINGS(plugin); | 117 GAIM_DBUS_REGISTER_BINDINGS(plugin); |
| 118 | 118 |
| 119 /* Then, we register the hello object of type GaimText. Note that | 119 /* Then, we register the hello object of type GaimText. Note that |
| 120 pointer registrations / unregistrations are completely dynamic; | 120 pointer registrations / unregistrations are completely dynamic; |
| 121 they don't have to be made when the plugin is loaded / | 121 they don't have to be made when the plugin is loaded / |
| 122 unloaded. Without this statement the dbus gaim code wouldn't | 122 unloaded. Without this statement the dbus gaim code wouldn't |
| 123 know about the hello object. */ | 123 know about the hello object. */ |
| 124 GAIM_DBUS_REGISTER_POINTER(&hello, GaimText); | 124 GAIM_DBUS_REGISTER_POINTER(&hello, GaimText); |
| 125 | 125 |
| 126 hello.text = g_strdup("Hello."); | 126 hello.text = g_strdup("Hello."); |
| 127 | 127 |
| 128 return TRUE; | 128 return TRUE; |
| 129 } | 129 } |
| 130 | 130 |
| 131 | 131 |
| 132 static gboolean | 132 static gboolean |
| 133 plugin_unload(GaimPlugin *plugin) | 133 plugin_unload(GaimPlugin *plugin) |
| 134 { | 134 { |
| 135 g_free(hello.text); | 135 g_free(hello.text); |
| 136 | 136 |
| 137 /* It is necessary to unregister all pointers registered by the module. */ | 137 /* It is necessary to unregister all pointers registered by the module. */ |
| 138 GAIM_DBUS_UNREGISTER_POINTER(&hello); | 138 GAIM_DBUS_UNREGISTER_POINTER(&hello); |
| 139 | 139 |
| 140 return TRUE; | 140 return TRUE; |
| 141 } | 141 } |
| 142 | 142 |
| 143 static GaimPluginInfo info = | 143 static GaimPluginInfo info = |
| 144 { | 144 { |
| 145 GAIM_PLUGIN_MAGIC, | 145 GAIM_PLUGIN_MAGIC, |
