register_method.c

Go to the documentation of this file.
00001 /*
00002  EasyDbus: 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:  register_method.c
00020 
00021   Description: This file contains functions for manage creation of
00022                method to insert on an object that must be published
00023                to DBUS.
00024 
00025   Version:  1.0
00026   Created:  06/17/07 12:40:05 CEST
00027   Revision:
00028     0 - created
00029     1 - 10/08/07   use opaque structs.
00030     2 - added doxygen documentation and renamed 
00031         EasyDbus_method_core object to 
00032         EasyDbus_obj_method. (ge@@ru) 11/06/07
00033 
00034   Author:   Daniele Rondina aka Ge@@ru (geaaru@gmail.com) 
00035   License:  GPL 2.0
00036 */
00037 
00043 #include <stdlib.h>
00044 #include <string.h>
00045 // easydbus includes 
00046 #include "easydbus-core.h"
00047 #include "introspect_internal.h"
00048 #include "debug.h"
00049 #include "utils.h"
00050 
00057 EasyDbus_obj_method *
00058 easydbus_obj_method_create (char *method)
00059 {
00060    int string_length;
00061    struct EasyDbus_obj_method *method_skeleton = NULL;
00062 
00063    if (!method)
00064       return NULL;
00065 
00066    method_skeleton = (struct EasyDbus_obj_method *)
00067       malloc (sizeof (struct EasyDbus_obj_method));
00068 
00069    if (!method_skeleton)
00070       return NULL;
00071 
00072    method_skeleton->input_info = method_skeleton->output_info = NULL;
00073    method_skeleton->next = NULL;
00074 
00075    string_length = strlen (method) + 1;
00076    method_skeleton->name = (char *) malloc (string_length);
00077 
00078    if (!method_skeleton->name)
00079       goto out_of_memory;
00080 
00081    EASYDBUS_MEMCOPY (method_skeleton->name, method,
00082                      string_length);
00083 
00084    EasyDbusDebug ("Create method_core %s", method_skeleton->name);
00085 
00086    return method_skeleton;
00087 
00088  out_of_memory:
00089    free (method_skeleton);
00090    return NULL;
00091 }
00092 
00098 void
00099 easydbus_obj_method_free (EasyDbus_obj_method * method)
00100 {
00101    struct easydbus_introspect_arg_info *el = NULL;
00102 
00103    if (!method)
00104       return;
00105 
00106    el = method->output_info;
00107    while (el) {
00108       method->output_info = el->next;
00109       easydbus_free_introspect_info_arg (el);
00110       el = method->output_info;
00111       EasyDbusDebug ("Free of output arg element");
00112    }
00113 
00114    el = method->input_info;
00115    while (el) {
00116       method->input_info = el->next;
00117       easydbus_free_introspect_info_arg (el);
00118       el = method->input_info;
00119       EasyDbusDebug ("Free of input arg element");
00120    }
00121 
00122    free (method->name);
00123 
00124    free (method);
00125 }
00126 
00137 int
00138 easydbus_obj_method_set_callback (EasyDbus_obj_method * method,
00139                                   easydbus_obj_method_callback_f method_callback)
00140 {
00141    if (!method || !method_callback)
00142       return -1;
00143 
00144    method->method_callback = method_callback;
00145 
00146    return 0;
00147 }
00148 
00149 // vim: ts=3 shiftwidth=3 expandtab

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