introspect.c

Go to the documentation of this file.
00001 /*
00002  EasyDbus Library: DBUS Binding Library
00003  Copyright (C) 2007  Daniele Rondina aka Ge@@ru, geaaru@gmail.com 
00004 
00005  This program is free software; you can redistribute it and/or
00006  modify it under the terms of the GNU General Public License
00007  as published by the Free Software Foundation; either version 2
00008  of the License, or (at your option) any later version.
00009 
00010  This program is distributed in the hope that it will be useful,
00011  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  GNU General Public License for more details.
00014 
00015  You should have received a copy of the GNU General Public License
00016  along with this program; if not, write to the Free Software
00017  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 
00019  Filename:  introspect.c
00020  
00021  Description: Functions for insert informations about 
00022         methods/signals managed on a register object. 
00023  
00024  Version:  1.0
00025  Created:  09/12/07 12:36:15 CEST
00026  Revision:  
00027     0 - created
00028     1 - created functions for creation of instropect XML
00029         string.
00030     2 - created doxygen documentation and added support for
00031         opaque struct (Ge@@ru) - 11/03/07 18:32:00 CEST
00032  
00033  Author:   Daniele Rondina aka ge@@ru (geaaru@gmail.com) 
00034  License:  GPL 2.0
00035 */
00036 
00043 #include <stdlib.h>
00044 #include <string.h>
00045 #include <stdarg.h>
00046 // easydbus includes
00047 #include "easydbus-core.h"
00048 #include "debug.h"
00049 #include "introspect_internal.h"
00050 #include "utils.h"
00051 
00062 int 
00063 easydbus_add_info_field_on_register_method (EasyDbus_obj_method * method,
00064                                             unsigned char offset,
00065                                             char *name_field, 
00066                                             unsigned char type, ...) 
00067 {
00068    struct easydbus_introspect_arg_info *el, *list;
00069    struct easydbus_signature_elem_stack *list_elem;
00070    enum el_type elem = EASYDBUS_ELTYPE_INVALID;
00071    int name_length = 0;
00072    va_list ap;
00073 
00074    if (method == NULL || name_field == NULL || type > 1)
00075       return -1;
00076 
00077    list = el = NULL;
00078    list_elem = NULL;
00079 
00080    if (type)
00081       list = method->output_info;
00082    else
00083       list = method->input_info;
00084 
00085    if (list != NULL) {
00086       // check if there is already a info about
00087       // a field with an offset == offset
00088       el = list;
00089       while (el != NULL) {
00090          if (el->offset == offset)
00091             return -1;
00092          el = el->next;
00093       }
00094    }
00095 
00096    el = (struct easydbus_introspect_arg_info *)
00097       malloc (sizeof (struct easydbus_introspect_arg_info));
00098    if (el == NULL)
00099       return -1;
00100 
00101    /* initialize new element */
00102    memset (el, 0,
00103            sizeof (struct easydbus_introspect_arg_info));
00104    el->name = el->signature = NULL;
00105    el->next = NULL;
00106 
00107    /* get elements list */
00108    va_start (ap, type);
00109 
00110    /* recover data from input params list */
00111    elem = va_arg (ap, enum el_type);
00112 
00113    while (elem != EASYDBUS_ELTYPE_INVALID) {
00114       list_elem =
00115          easydbus_add_elem_to_stack (elem, list_elem);
00116       elem = va_arg (ap, enum el_type);
00117    }
00118    va_end (ap);
00119 
00120    el->signature =
00121       easydbus_create_arg_signature (list_elem);
00122    if (el->signature == NULL)
00123       goto error;
00124    list_elem = NULL;
00125 
00126    name_length = strlen (name_field) + 1;
00127    el->name = (char *) malloc (name_length);
00128    if (el->name == NULL)
00129       goto error;
00130 
00131    EASYDBUS_MEMCOPY (el->name, name_field, name_length);
00132    el->offset = offset;
00133 
00134    if (easydbus_add_new_field_to_list (el, &list))
00135       goto error;
00136 
00137    if (type)
00138       method->output_info = list;
00139    else
00140       method->input_info = list;
00141 
00142 
00143    return 0;
00144 
00145  error:
00146    if (el != NULL)
00147       easydbus_free_introspect_info_arg (el);
00148 
00149    easydbus_free_elem_from_stack_list (list_elem);
00150 
00151    return -1;
00152 }
00153 
00154 
00164 int
00165 easydbus_add_info_field_on_register_signal (EasyDbus_obj_signal * signal, 
00166                                             unsigned char offset,
00167                                             char *name_field, ...) 
00168 {
00169    struct easydbus_introspect_arg_info *el = NULL;
00170    struct easydbus_signature_elem_stack *list_elem;
00171    enum el_type elem = EASYDBUS_ELTYPE_INVALID;
00172    int name_length = 0;
00173    va_list ap;
00174 
00175    if (signal == NULL || name_field == NULL)
00176       return -1;
00177 
00178    list_elem = NULL;
00179 
00180    if (signal->output_info != NULL) {
00181       // check if there is already a info about
00182       // a field with an offset == offset
00183       el = signal->output_info;
00184       while (el != NULL) {
00185          if (el->offset == offset)
00186             return -1;
00187          el = el->next;
00188       }
00189    }
00190 
00191    el = (struct easydbus_introspect_arg_info *)
00192       malloc (sizeof (struct easydbus_introspect_arg_info));
00193    if (el == NULL)
00194       return -1;
00195 
00196    /* initialize new element */
00197    memset (el, 0,
00198            sizeof (struct easydbus_introspect_arg_info));
00199    el->name = NULL;
00200    el->next = NULL;
00201 
00202    /* get elements list */
00203    va_start (ap, name_field);
00204 
00205    /* recover data from input params list */
00206    elem = va_arg (ap, enum el_type);
00207 
00208    while (elem != EASYDBUS_ELTYPE_INVALID) {
00209       list_elem =
00210          easydbus_add_elem_to_stack (elem, list_elem);
00211       elem = va_arg (ap, enum el_type);
00212    }
00213    va_end (ap);
00214 
00215    el->signature =
00216       easydbus_create_arg_signature (list_elem);
00217    if (el->signature == NULL)
00218       goto error;
00219    list_elem = NULL;
00220 
00221    name_length = strlen (name_field) + 1;
00222    el->name = (char *) malloc (name_length);
00223    if (el->name == NULL)
00224       goto error;
00225 
00226    EASYDBUS_MEMCOPY (el->name, name_field, name_length);
00227    el->offset = offset;
00228 
00229    if (easydbus_add_new_field_to_list
00230        (el, &signal->output_info))
00231       goto error;
00232 
00233    return 0;
00234 
00235  error:
00236    if (el != NULL)
00237       easydbus_free_introspect_info_arg (el);
00238 
00239    easydbus_free_elem_from_stack_list (list_elem);
00240 
00241    return -1;
00242 }
00243 
00244 
00255 int
00256 easydbus_enable_introspect_check (EasyDbus_conn * data,
00257                                   EasyDbus_object * object,
00258                                   char *obj_path)
00259 {
00260    struct EasyDbus_core *core =
00261       (struct EasyDbus_core *) data;
00262    char *introspect_string = NULL;
00263    introspect_objs_tree *t = NULL;
00264 
00265    if (!data || !object)
00266       return -1;
00267 
00268 
00269    t = easydbus_introspect_objs_tree_build ((struct EasyDbus_object_box *)
00270                                              object);
00271    if (!t) return -1;
00272 
00273    /* check if this is needed */
00274    introspect_string = 
00275       easydbus_introspect_create_reply_string (obj_path, t, 
00276                                                (struct EasyDbus_object_box *)
00277                                                 object);
00278 
00279    easydbus_introspect_objs_tree_destroy (t); 
00280 
00281    if (!introspect_string)
00282       return -1;
00283    free (introspect_string);
00284 
00285    core->handled_introspect = 1;
00286 
00287    return 0;
00288 }
00289 
00290 // vim: ts=3 shiftwidth=3 expandtab

Generated on Thu Apr 10 10:00:18 2008 for EasyDbus-0.2 by  doxygen 1.5.4