register_interface.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_interface.c
00020 
00021  Description:
00022 
00023  Version:  1.0
00024  Created:  09/18/07 09:00:23 CEST
00025  Revision:
00026     0 - created
00027     1 - added doxygen documentation, use opaque struct, and renamed 
00028         EasyDbus_interface_core object to
00029         EasyDbus_obj_interface. (ge@@ru) 11/06/07
00030 
00031  Author:   Daniele Rondina aka Ge@@ru (geaaru@gmail.com)
00032  License:  GPL 2.0
00033 */
00034 
00041 #include <string.h>
00042 #include <stdlib.h>
00043 // easydbus includes
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       // check member
00225       if (!strcmp (member_name, method->name)) {
00226          if (interface_string) {
00227             if (!strcmp (interface_string, interface->name))
00228                break;
00229          } else
00230             // if interface isn't set and method matching,
00231             // then first method matching it is used.
00232             break;
00233       }
00234    }
00235 
00236    return method;
00237 }
00238 
00239 
00240 // vim: ts=3 shiftwidth=3 expandtab

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