match_rules.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:  match_rules.c
00020  
00021  Description:  
00022  
00023  Version:  1.0
00024  Created:  09/05/07 09:38:11 CEST
00025  Revision:  
00026     0 - created
00027     1 - created doxygen documentation and added support for
00028         opaque struct (Ge@@ru) - 11/03/07 
00029  
00030  Author:   Daniele Rondina aka Ge@@ru (geaaru@gmail.com) 
00031  License:  GPL 2.0
00032 */
00033 
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <string.h>
00043 #include "easydbus-core.h"
00044 #include "debug.h"
00045 #include "utils.h"
00046 
00060 inline int
00061 easydbus_conn_add_match_rule (EasyDbus_conn *data,
00062                               enum event_type type, char *sender,
00063                               char *interface, char *member, char *path,
00064                               char *destination)
00065 {
00066    DBusError err;
00067 
00068    dbus_error_init (&err);
00069 
00070    struct EasyDbus_core *core = (struct EasyDbus_core *) data;
00071    char *buffer = NULL;
00072 
00073    buffer = prepare_match_string (type, sender,
00074                                   interface, member, path,
00075                                   destination);
00076    if (buffer == NULL)
00077       return -1;
00078 
00079    EasyDbusDebug ("MATCH_RULE = %s\n", buffer);
00080 
00081    dbus_bus_add_match (core->conn, buffer, &err);
00082    dbus_connection_flush (core->conn);
00083 
00084    if (dbus_error_is_set (&err)) {
00085       EasyDbusDebug ("Matched error (%s)\n", err.message);
00086       free (buffer);
00087       dbus_error_free (&err);
00088       return -1;
00089    }
00090 
00091    dbus_error_free (&err);
00092    free (buffer);
00093    return 0;
00094 }
00095 
00109 inline int
00110 easydbus_conn_remove_match_rule (EasyDbus_conn *data,
00111                                  enum event_type type, char *sender,
00112                                  char *interface, char *member, char *path,
00113                                  char *destination)
00114 {
00115    DBusError err;
00116 
00117    struct EasyDbus_core *core = (struct EasyDbus_core *) data;
00118    char *buffer = NULL;
00119 
00120    dbus_error_init (&err);
00121 
00122    buffer = prepare_match_string (type, sender,
00123                                   interface, member, path,
00124                                   destination);
00125    if (buffer == NULL)
00126       return -1;
00127 
00128    EasyDbusDebug ("Remove MATCH_RULE = %s\n", buffer);
00129 
00130    dbus_bus_remove_match (core->conn, buffer, &err);
00131    dbus_connection_flush (core->conn);
00132 
00133    if (dbus_error_is_set (&err)) {
00134       EasyDbusDebug ("Remove match error (%s)\n", err.message);
00135       dbus_error_free (&err);
00136       free (buffer);
00137       return -1;
00138    }
00139 
00140    dbus_error_free (&err);
00141    free (buffer);
00142    return 0;
00143 }
00144 
00145 // vim: ts=3 shiftwidth=3 expandtab

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