register_ext_signal.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_ext_signal.c
00020 
00021  Description:
00022 
00023  Version:  1.0
00024  Created:  09/22/07 21:04:16 CEST
00025  Revision:
00026       0 - created
00027       1 - add doxygen documentation and added support
00028           for opaque structs (Ge@@ru) - 11/02/07 18:45:00 CEST
00029 
00030  Author:   Daniele Rondina aka Ge@@ru (geaaru@gmail.com) 
00031  License:  GPL 2.0
00032 */
00033 
00040 #include <string.h>
00041 #include <stdlib.h>
00042 // easydbus includes
00043 #include "debug.h"
00044 #include "easydbus-core.h"
00045 #include "reply_internal.h"
00046 #include "introspect_internal.h"
00047 #include "register_obj_internal.h"
00048 
00056 int
00057 easydbus_ext_signal_add_to_service (EasyDbus_conn * data,
00058                                     EasyDbus_ext_signal * signal)
00059 {
00060    struct EasyDbus_core *core = (struct EasyDbus_core *) data;
00061    EasyDbus_ext_signal *el = NULL;
00062 
00063    if (!data || !signal || !signal->signal || 
00064         !signal->signal_callback)
00065       return -1;
00066 
00067    el = core->handled_ext_signals;
00068 
00069    if (el) {
00070       while (el->next != NULL)
00071          el = el->next;
00072       el->next = signal;
00073    }
00074    else {
00075       core->handled_signal = 1;
00076       core->handled_ext_signals = signal;
00077    }
00078 
00079    return 0;
00080 }
00081 
00086 void 
00087 easydbus_ext_signal_free_skeleton (EasyDbus_ext_signal * signal) 
00088 {
00089    if (!signal)
00090       return;
00091 
00092    if (signal->signal)
00093       free (signal->signal);
00094 
00095    if (signal->path)
00096       free (signal->path);
00097 
00098    if (signal->interface)
00099       free (signal->interface);
00100 
00101    if (signal->sender)
00102       free (signal->sender);
00103 
00104    if (signal->destination)
00105       free (signal->destination);
00106 
00107    free (signal);
00108 }
00109 
00124 EasyDbus_ext_signal *
00125 easydbus_ext_signal_create (char *signal,
00126                             char *path,
00127                             char *interface,
00128                             char *sender,
00129                             char *destination,
00130                             easydbus_ext_signal_callback_f
00131                             signal_callback)
00132 {
00133    struct EasyDbus_ext_signal *ext_signal = NULL;
00134    int string_len;
00135 
00136    if (!signal || !signal_callback)
00137       return NULL;
00138 
00139    ext_signal = (struct EasyDbus_ext_signal *)
00140       malloc (sizeof (struct EasyDbus_ext_signal));
00141 
00142    if (!ext_signal)
00143       return NULL;
00144 
00145    memset (ext_signal, 0, sizeof (struct EasyDbus_ext_signal));
00146 
00147    ext_signal->signal = ext_signal->path =
00148       ext_signal->interface = ext_signal->sender = NULL;
00149    ext_signal->signal_callback = NULL;
00150    ext_signal->next = NULL;
00151 
00152    /* save signal string name */
00153    string_len = strlen (signal) + 1;
00154    ext_signal->signal = (char *) malloc (string_len);
00155    if (!ext_signal->signal)
00156       goto out_of_memory;
00157    EASYDBUS_MEMCOPY (ext_signal->signal, signal, string_len);
00158 
00159    /* save signal path string */
00160    if (path) {
00161       string_len = strlen (path) + 1;
00162       ext_signal->path = (char *) malloc (string_len);
00163       if (!ext_signal->path)
00164          goto out_of_memory;
00165       EASYDBUS_MEMCOPY (ext_signal->path, path, string_len);
00166    }
00167 
00168    /* save signal interface string */
00169    if (interface) {
00170       string_len = strlen (interface) + 1;
00171       ext_signal->interface = (char *) malloc (string_len);
00172       if (!ext_signal->interface)
00173          goto out_of_memory;
00174       EASYDBUS_MEMCOPY (ext_signal->interface, interface,
00175                         string_len);
00176    }
00177 
00178    /* save signal sender string */
00179    if (sender) {
00180       string_len = strlen (sender) + 1;
00181       ext_signal->sender = (char *) malloc (string_len);
00182       if (!ext_signal->sender)
00183          goto out_of_memory;
00184       EASYDBUS_MEMCOPY (ext_signal->sender, sender, string_len);
00185    }
00186 
00187    if (destination) {
00188       string_len = strlen (destination) + 1;
00189       ext_signal->destination = (char *) malloc (string_len);
00190       if (!ext_signal->destination)
00191          goto out_of_memory;
00192       EASYDBUS_MEMCOPY (ext_signal->destination, destination,
00193                         string_len);
00194    }
00195 
00196    ext_signal->signal_callback = signal_callback;
00197 
00198    return ext_signal;
00199 
00200  out_of_memory:
00201    if (ext_signal)
00202       easydbus_ext_signal_free_skeleton (ext_signal);
00203 
00204    return NULL;
00205 }
00206 
00207 // vim: ts=3 shiftwidth=3 expandtab

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