00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00041 #include <string.h>
00042 #include <stdlib.h>
00043
00044 #include "debug.h"
00045 #include "easydbus-core.h"
00046 #include "reply_internal.h"
00047 #include "introspect_internal.h"
00048 #include "register_obj_internal.h"
00049
00050
00058 EasyDbus_obj_interface *
00059 easydbus_obj_interface_create_skeleton (char *name)
00060 {
00061 struct EasyDbus_obj_interface *interface = NULL;
00062 unsigned int name_length = 0;
00063
00064 if (!name)
00065 return NULL;
00066
00067 interface = (struct EasyDbus_obj_interface *)
00068 malloc (sizeof (struct EasyDbus_obj_interface));
00069 if (!interface)
00070 return NULL;
00071
00072 memset (interface, 0, sizeof (struct EasyDbus_obj_interface));
00073
00074 interface->name = NULL;
00075 interface->handled_signals = NULL;
00076 interface->handled_methods = NULL;
00077
00078 if (name) {
00079 name_length = strlen (name) + 1;
00080 interface->name = (char *) malloc (name_length);
00081 if (!interface->name)
00082 goto out_of_memory;
00083
00084 EASYDBUS_MEMCOPY (interface->name, name, name_length);
00085 }
00086
00087 EasyDbusDebug ("Create Interface Skeleton struct with name %s",
00088 name);
00089
00090 return interface;
00091 out_of_memory:
00092 if (interface)
00093 free (interface);
00094 return NULL;
00095 }
00096
00107 int
00108 easydbus_obj_interface_add_method (EasyDbus_obj_interface * interface,
00109 EasyDbus_obj_method * method)
00110 {
00111 struct EasyDbus_obj_method *temp;
00112
00113 if (!interface || !method)
00114 return -1;
00115
00116 if (interface->n_methods) {
00117 temp = interface->handled_methods;
00118 while (temp->next)
00119 temp = temp->next;
00120 temp->next = method;
00121 }
00122 else
00123 interface->handled_methods = method;
00124 interface->n_methods++;
00125
00126 EasyDbusDebug ("Added method to interface skeleton");
00127
00128 return 0;
00129 }
00130
00141 int
00142 easydbus_obj_interface_add_signal (EasyDbus_obj_interface * interface,
00143 EasyDbus_obj_signal * signal)
00144 {
00145 struct EasyDbus_obj_signal *temp = NULL;
00146
00147 if (!interface || !signal)
00148 return -1;
00149
00150 if (interface->n_signals) {
00151 temp = interface->handled_signals;
00152 while (temp->next)
00153 temp = temp->next;
00154 temp->next = signal;
00155 }
00156 else
00157 interface->handled_signals = signal;
00158 interface->n_signals++;
00159
00160 EasyDbusDebug ("Added signal to skeleton interface");
00161
00162 return 0;
00163 }
00164
00169 void
00170 easydbus_obj_interface_free_skeleton
00171 (EasyDbus_obj_interface * interface)
00172 {
00173 struct EasyDbus_obj_signal *signal;
00174 struct EasyDbus_obj_method *method;
00175 int i;
00176
00177 if (!interface)
00178 return;
00179
00180 if (interface->name)
00181 free (interface->name);
00182
00183 if (interface->n_methods) {
00184 for (i = 0; i < interface->n_methods; i++) {
00185 method = interface->handled_methods;
00186 if (method)
00187 interface->handled_methods = method->next;
00188 easydbus_obj_method_free (method);
00189 }
00190 }
00191
00192 if (interface->n_signals) {
00193 for (i = 0; i < interface->n_methods; i++) {
00194 signal = interface->handled_signals;
00195 if (signal)
00196 interface->handled_signals = signal->next;
00197 easydbus_obj_signal_free (signal);
00198 }
00199 }
00200 free (interface);
00201 EasyDbusDebug ("Free Interface skeleton");
00202 }
00203
00212 EasyDbus_obj_method *
00213 easydbus_obj_interface_get_method (const char *member_name,
00214 const char *interface_string,
00215 const EasyDbus_obj_interface *interface)
00216 {
00217 EasyDbus_obj_method *method = NULL;
00218
00219 if (!member_name || !interface)
00220 return NULL;
00221
00222 for (method = interface->handled_methods; method;
00223 method = method->next) {
00224
00225 if (!strcmp (member_name, method->name)) {
00226 if (interface_string) {
00227 if (!strcmp (interface_string, interface->name))
00228 break;
00229 } else
00230
00231
00232 break;
00233 }
00234 }
00235
00236 return method;
00237 }
00238
00239
00240