3
* D-BUS Service Utilities
5
* Provides MINIMAL utilities for construction of D-BUS "Services".
7
* Copyright(C) Jason Vas Dias, Red Hat Inc., 2005
8
* Modified by Adam Tkac, Red Hat Inc., 2007
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation at
13
* http://www.fsf.org/licensing/licenses/gpl.txt
14
* and included in this software distribution as the "LICENSE" file.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
23
#include <sys/types.h>
25
#include <linux/limits.h>
27
#include <sys/socket.h>
28
#include <sys/select.h>
30
#include <sys/ioctl.h>
36
extern size_t strnlen(const char *s, size_t maxlen);
37
#include <netinet/in.h>
38
#include <arpa/inet.h>
43
typedef void (*__free_fn_t) (void *__nodep);
44
extern void tdestroy (void *__root, __free_fn_t __freefct);
50
#define DBUS_API_SUBJECT_TO_CHANGE "Very Annoying and Silly!"
51
#include <dbus/dbus.h>
53
#include <named/dbus_service.h>
54
#include <isc/result.h>
58
DBusConnection *connection;
59
DBusDispatchStatus dispatchStatus;
61
dbus_svc_WatchHandler wh;
63
const char * unique_name;
64
dbus_svc_MessageHandler mh;
66
dbus_svc_MessageHandler mf;
68
dbus_svc_ShutdownHandler sh;
70
dbus_svc_ErrorHandler eh;
71
dbus_svc_ErrorHandler dh;
85
DBusMessage *currentMessage;
87
} DBusConnectionState;
94
dbus_svc_MessageHandler mh;
102
dbus_svc_MessageHandler mh;
104
} MessageHandlerNode;
108
DBusConnectionState *cs;
109
dbus_svc_MessageHandler mf;
115
typedef struct dbto_s
118
DBusConnectionState *cs;
120
} DBusConnectionTimeout;
122
static void no_free( void *p){ p=0; }
124
static int ptr_key_comparator( const void *p1, const void *p2 )
136
static DBusHandlerResult
137
default_message_filter
138
( DBusConnection *connection,
139
DBusMessage *message,
143
DBusConnectionState *cs = p;
144
uint32_t type =dbus_message_get_type( message ),
145
serial =dbus_message_get_serial( message );
146
uint8_t reply =dbus_message_get_no_reply( message )==0;
148
*path = dbus_message_get_path( message ),
149
*dest = dbus_message_get_destination( message ),
150
*member = dbus_message_get_member( message ),
151
*interface=dbus_message_get_interface( message ),
152
*sender =dbus_message_get_sender( message ),
153
*signature=dbus_message_get_signature( message );
154
connection = connection;
157
(*(cs->mf))( cs, type, reply, serial, dest, path, member, interface, 0L,
158
sender, signature, message, 0L, 0L, 0L, cs->def_mf_obj
165
( DBusConnectionState *cs, dbus_svc_MessageHandler mh, void *obj, int n_matches, ... )
171
va_start(va, n_matches );
174
cs->def_mf_obj = obj;
176
if ( ! dbus_connection_add_filter (cs->connection, default_message_filter, cs, NULL))
178
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_add_filter: dbus_connection_add_filter failed");
185
memset(&error,'\0',sizeof(DBusError));
186
dbus_error_init(&error);
189
m = va_arg(va, char* ) ;
191
dbus_bus_add_match(cs->connection, m, &error);
193
if( dbus_error_is_set(&error))
195
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_add_filter: dbus_bus_add_match failed for %s: %s %s",
196
m, error.name, error.message
209
dbus_svc_get_args_va(DBusConnectionState *cs, DBusMessage* msg, dbus_svc_DataType firstType, va_list va)
212
memset(&error,'\0',sizeof(DBusError));
213
dbus_error_init(&error);
214
if( (!dbus_message_get_args_valist(msg, &error, firstType, va)) || dbus_error_is_set(&error) )
216
if( dbus_error_is_set(&error) )
218
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_get_args failed: %s %s",error.name, error.message);
219
dbus_error_free(&error);
221
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_get_args failed: dbus_message_get_args_valist failed");
228
dbus_svc_get_args(DBusConnectionState *cs, DBusMessage* msg, dbus_svc_DataType firstType, ...)
232
va_start(va, firstType);
233
r = dbus_svc_get_args_va( cs, msg, firstType, va);
240
( DBusConnectionState *cs,
241
dbus_svc_MessageType type,
242
int32_t reply_serial,
243
uint32_t *new_serial,
244
const char *destination,
246
const char *interface,
248
dbus_svc_DataType firstType,
252
DBusMessageIter iter;
267
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_svc_new_message failed");
271
if( type != DBUS_MESSAGE_TYPE_ERROR )
273
if( !dbus_message_append_args_valist( msg, firstType, va ) )
275
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_message_append_args_valist failed");
280
if( firstType == DBUS_TYPE_STRING )
283
e = va_arg( va, char* );
284
if( (e == 0L) || !dbus_message_set_error_name( msg, e ) )
286
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_message_set_error_name failed");
289
firstType = va_arg(va, int);
290
if( firstType == DBUS_TYPE_STRING )
293
e = va_arg( va, char* );
296
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: NULL error message");
299
dbus_message_iter_init_append (msg, &iter);
300
if( !dbus_message_iter_append_basic
301
(&iter, DBUS_TYPE_STRING, &e)
304
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_message_iter_append_basic failed");
310
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: unhandled type for error name: %c", firstType);
315
if( !dbus_connection_send(cs->connection, msg, new_serial) )
317
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_message_send failed");
320
if( cs->dh != 0L ) (*(cs->dh))("Sending message");
321
dbus_connection_flush(cs->connection);
327
( DBusConnectionState *cs,
328
dbus_svc_MessageType type,
329
int32_t reply_serial,
330
uint32_t *new_serial,
331
const char *destination,
333
const char *interface,
335
dbus_svc_DataType firstType,
341
va_start(va, firstType);
342
r = dbus_svc_send_va(cs, type, reply_serial, new_serial, destination, path,interface,member,firstType,va);
347
dbus_svc_MessageHandle
349
( DBusConnectionState* cs,
350
dbus_svc_MessageType type,
351
int32_t reply_serial,
352
const char *destination,
354
const char *interface,
358
DBusMessage *msg = dbus_message_new(type);
362
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_new_message: dbus_message_set_reply_serial failed");
366
if( reply_serial != -1 )
368
if( !dbus_message_set_reply_serial(msg,reply_serial) )
370
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_new_message: dbus_message_set_reply_serial failed");
375
if( (destination !=0L) && !dbus_message_set_destination(msg, destination) )
377
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_new_message: dbus_message_set_destination failed");
381
if( !dbus_message_set_path(msg, path) )
383
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_new_message: dbus_message_set_path failed");
387
if( ! dbus_message_set_interface(msg,interface) )
389
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_new_message: dbus_message_set_interface failed - %s", interface);
393
if( !dbus_message_set_member(msg,member) )
395
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_new_message: dbus_message_set_member failed");
403
dbus_svc_send_message
405
DBusConnectionState *cs,
406
dbus_svc_MessageHandle msg,
410
if( !dbus_connection_send(cs->connection, msg, new_serial) )
412
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_message_send failed");
415
if( cs->dh != 0L ) (*(cs->dh))("Sending message");
416
dbus_connection_flush(cs->connection);
421
dbus_svc_message_append_args(DBusConnectionState *cs, dbus_svc_MessageHandle msg, dbus_svc_DataType firstType, ...)
424
va_start(va, firstType);
425
if( !dbus_message_append_args_valist( msg, firstType, va ) )
427
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_message_append_args failed");
435
dbus_svc_MessageHandle
437
( DBusConnectionState *cs,
438
const char *destination,
441
const char *interface,
442
dbus_svc_DataType firstType,
446
DBusMessage *message=0L, *reply=0L;
449
int reply_timeout=20000;
451
va_start(va, firstType);
453
memset(&error,'\0',sizeof(DBusError));
454
dbus_error_init(&error);
457
dbus_message_new_method_call
466
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_call: dbus_message_new_method_call failed");
471
if( !dbus_message_append_args_valist( message, firstType, va ) )
473
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_call: dbus_message_append_args_valist failed");
479
dbus_connection_send_with_reply_and_block
481
message, reply_timeout,
487
if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_call: dbus_message_send_with_reply_and_block failed: %s %s",
488
error.name, error.message
497
dbus_svc_MessageIterator
498
dbus_svc_message_iterator_new( DBusConnectionState *cs, DBusMessage *msg)
500
DBusMessageIter *iter = malloc( sizeof(DBusMessageIter) );
505
if( !dbus_message_iter_init( msg, iter ))
515
dbus_svc_message_next_arg_type( DBusConnectionState *cs, dbus_svc_MessageIterator iter )
519
return dbus_message_iter_get_arg_type( iter );
523
dbus_svc_message_next_arg( DBusConnectionState *cs, dbus_svc_MessageIterator iter, void *value )
527
dbus_message_iter_get_basic( iter, value );
528
dbus_message_iter_next( iter );
532
dbus_svc_message_element_type(DBusConnectionState *cs , dbus_svc_MessageIterator iter)
536
return dbus_message_iter_get_element_type(iter);
540
dbus_svc_message_get_elements( DBusConnectionState *cs , dbus_svc_MessageIterator iter, uint32_t *n, void *array )
544
dbus_message_iter_get_fixed_array( iter, n, array);
547
void dbus_svc_message_iterator_free( DBusConnectionState *cs, dbus_svc_MessageIterator iter )
554
uint8_t dbus_svc_message_type( DBusMessage *msg )
556
return dbus_message_get_type( msg );
559
static DBusConnectionState *
560
dbcs_new( DBusConnection *connection )
562
DBusConnectionState *dbcs = (DBusConnectionState *) malloc( sizeof(DBusConnectionState) );
565
memset( dbcs, '\0', sizeof( DBusConnectionState ));
566
dbcs->connection = connection;
571
static DBusConnectionTimeout *
572
timeout_new( DBusTimeout *timeout )
574
DBusConnectionTimeout *to = (DBusConnectionTimeout *) malloc ( sizeof(DBusConnectionTimeout) );
578
dbus_timeout_set_data(timeout, to, 0L);
579
if( dbus_timeout_get_enabled(timeout) )
580
gettimeofday(&(to->tv),0L);
591
add_timeout( DBusTimeout *timeout, void *csp )
593
DBusConnectionState *cs = csp;
594
DBusConnectionTimeout *to = timeout_new(timeout);
595
if( cs->dh != 0L ) (*(cs->dh))("add_timeout: %d", dbus_timeout_get_interval(timeout));
599
if( tsearch((void*)to, &(cs->timeouts), ptr_key_comparator) != 0L )
602
if( cs->eh != 0L ) (*(cs->eh))("add_timeout: out of memory");
607
remove_timeout( DBusTimeout *timeout, void *csp )
609
DBusConnectionState *cs = csp;
610
DBusConnectionTimeout *to = dbus_timeout_get_data(timeout);
611
if( (to != 0L) && (to->to == timeout) )
613
if( cs->dh != 0L ) (*(cs->dh))("remove_timeout: %d", dbus_timeout_get_interval(to->to));
614
if( tdelete((const void*)to, &(cs->timeouts), ptr_key_comparator) != 0L )
618
if( cs->eh != 0L ) (*(cs->eh))("remove_timeout: can't happen?!?: timeout data %p not found", to);
620
if( cs->eh != 0L ) (*(cs->eh))("remove_timeout: can't happen?!?: timeout %p did not record data %p %p",
621
timeout, to, ((to != 0L) ? to->to : 0L)
626
toggle_timeout( DBusTimeout *timeout, void *csp )
628
DBusConnectionState *cs = csp;
629
DBusConnectionTimeout **top = tfind( (const void*) dbus_timeout_get_data(timeout),
634
if( (top != 0L) && ((to=*top) != 0L) && (to->to == timeout) )
636
if( cs->dh != 0L ) (*(cs->dh))("toggle_timeout: %d", dbus_timeout_get_interval(to->to));
637
if( dbus_timeout_get_enabled(timeout) )
638
gettimeofday(&(to->tv),0L);
645
if( cs->eh != 0L ) (*(cs->eh))("toggle_timeout: can't happen?!?: timeout %p %s %p %p", timeout,
646
((to==0L) ? "did not record data" : "not found"),
647
to, ((to != 0L) ? to->to : 0L)
652
process_timeout( const void *p, const VISIT which, const int level)
654
DBusConnectionState *cs;
655
void * const *tpp = p;
656
DBusConnectionTimeout *to;
658
float now, then, interval;
659
int l = level ? 1 : 0;
662
gettimeofday(&tv,0L);
664
if( (tpp != 0L) && (*tpp != 0L) && ((which == postorder) || (which == leaf)) )
666
to = (DBusConnectionTimeout*)*tpp;
668
if ( !dbus_timeout_get_enabled(to->to) )
670
cs = dbus_timeout_get_data(to->to);
671
then = ((float)to->tv.tv_sec) + (((float)to->tv.tv_usec) / 1000000.0);
674
interval = ((float)dbus_timeout_get_interval(to->to)) / 1000.0;
675
now = ((float)tv.tv_sec) + (( (float)tv.tv_usec) / 1000000.0);
676
if( (now - then) >= interval )
678
if( cs->dh != 0L ) (*(cs->dh))("handle_timeout: %d - %f %f %f", dbus_timeout_get_interval(to->to), then, now, interval);
679
dbus_timeout_handle( to->to );
690
process_timeouts ( DBusConnectionState *cs )
692
twalk( cs->timeouts, process_timeout );
696
set_watch_fds( DBusWatch *watch, DBusConnectionState *cs )
698
uint8_t flags = dbus_watch_get_flags(watch);
699
int fd = dbus_watch_get_fd(watch);
704
if ( dbus_watch_get_enabled(watch) )
706
if ( flags & DBUS_WATCH_READABLE )
708
FD_SET(fd , &(cs->r_fds));
710
(*(cs->wh))( fd, WATCH_ENABLE | WATCH_READ, cs->wh_arg );
713
FD_CLR(fd , &(cs->r_fds));
715
(*(cs->wh))( fd, WATCH_READ, cs->wh_arg );
718
if ( flags & DBUS_WATCH_WRITABLE )
720
FD_SET(fd , &(cs->w_fds));
722
(*(cs->wh))( fd, WATCH_ENABLE | WATCH_WRITE, cs->wh_arg );
725
FD_CLR(fd , &(cs->w_fds));
727
(*(cs->wh))( fd, WATCH_WRITE, cs->wh_arg );
729
if ( flags & DBUS_WATCH_ERROR )
731
FD_SET(fd , &(cs->e_fds));
733
(*(cs->wh))( fd, WATCH_ENABLE | WATCH_ERROR, cs->wh_arg );
736
FD_CLR(fd , &(cs->e_fds));
738
(*(cs->wh))( fd, WATCH_ERROR, cs->wh_arg );
742
if( FD_ISSET( fd, &(cs->r_fds)) )
744
(*(cs->wh))( fd, WATCH_READ, cs->wh_arg );
745
FD_CLR(fd , &(cs->r_fds));
747
if( FD_ISSET( fd, &(cs->w_fds)) )
749
(*(cs->wh))( fd, WATCH_WRITE, cs->wh_arg );
750
FD_CLR(fd , &(cs->w_fds));
752
if( FD_ISSET( fd, &(cs->e_fds)) )
754
(*(cs->wh))( fd, WATCH_ERROR, cs->wh_arg );
755
FD_CLR(fd , &(cs->e_fds));
760
add_watch ( DBusWatch *watch, void *csp )
762
DBusConnectionState *cs = csp;
764
dbus_watch_set_data(watch, cs, no_free );
765
if( cs->dh != 0L ) (*(cs->dh))("add_watch: %d", dbus_watch_get_fd(watch));
766
if( tsearch((const void*)watch,&(cs->watches),ptr_key_comparator) == 0L )
768
if( cs->eh != 0L ) (*(cs->eh))("add_watch: out of memory");
771
set_watch_fds(watch,cs);
776
remove_watch ( DBusWatch *watch, void *csp )
778
DBusConnectionState *cs = csp;
779
int fd = dbus_watch_get_fd(watch);
780
if( tdelete((const void*)watch, &(cs->watches), ptr_key_comparator) == 0L )
781
if( cs->eh != 0L ) (*(cs->eh))("remove_watch: can't happen?!?: watch not found");
782
if( cs->dh != 0L ) (*(cs->dh))("remove_watch: %d", dbus_watch_get_fd(watch));
783
FD_CLR(fd , &(cs->r_fds));
784
FD_CLR(fd , &(cs->w_fds));
785
FD_CLR(fd , &(cs->e_fds));
787
(*(cs->wh))(dbus_watch_get_fd(watch), WATCH_READ | WATCH_WRITE | WATCH_ERROR, cs->wh_arg );
791
toggle_watch ( DBusWatch *watch, void *csp )
793
DBusConnectionState *cs = csp;
794
if( cs->dh != 0L ) (*(cs->dh))("toggle_watch: %d", dbus_watch_get_fd(watch));
795
set_watch_fds(watch,cs);
799
process_watch( const void *p, const VISIT which, const int level)
805
DBusConnectionState *cs;
806
int l = level ? 1 : 0;
809
if((wpp != 0L) && (*wpp != 0L) && ( (which == postorder) || (which == leaf) ) )
811
w = (DBusWatch*)*wpp;
812
cs = dbus_watch_get_data( w );
815
if( ! dbus_watch_get_enabled(w) )
817
fd = dbus_watch_get_fd( w );
818
flags = dbus_watch_get_flags( w );
819
if( cs->dh != 0L ) (*(cs->dh))("handle_watch: %d", dbus_watch_get_fd( w ));
820
if ( (flags & DBUS_WATCH_READABLE) && (FD_ISSET(fd, &(cs->s_r_fds))) )
821
dbus_watch_handle(w, DBUS_WATCH_READABLE);
822
if ( (flags & DBUS_WATCH_WRITABLE) && (FD_ISSET(fd, &(cs->s_w_fds))) )
823
dbus_watch_handle(w, DBUS_WATCH_READABLE);
824
if ( (flags & DBUS_WATCH_ERROR) && (FD_ISSET(fd, &(cs->s_e_fds))) )
825
dbus_watch_handle(w, DBUS_WATCH_ERROR);
830
process_watches ( DBusConnectionState *cs )
832
twalk( cs->watches, process_watch );
835
void dbus_svc_handle_watch( DBusConnectionState *cs, int fd, dbus_svc_WatchFlags action )
840
FD_SET(fd, &(cs->s_r_fds));
844
FD_SET(fd, &(cs->s_w_fds));
848
FD_SET(fd, &(cs->s_e_fds));
855
( DBusConnection *connection,
856
DBusDispatchStatus new_status,
860
connection=connection;
861
DBusConnectionState *cs = csp;
862
cs->dispatchStatus = new_status;
866
dbus_svc_main_loop( DBusConnectionState *cs, void (*idle_handler)(DBusConnectionState *) )
868
struct timeval timeout={0,200000};
871
while( cs->status != SHUTDOWN )
873
cs->s_r_fds = cs->r_fds;
874
cs->s_w_fds = cs->w_fds;
875
cs->s_e_fds = cs->e_fds;
878
timeout.tv_usec= 200000;
880
if ( (n_fds = select(cs->n, &(cs->s_r_fds), &(cs->s_w_fds), &(cs->s_e_fds), &timeout)) < 0 )
884
if( cs->eh != 0L ) (*(cs->eh))( "select failed: %d : %s", errno, strerror(errno));
892
process_timeouts(cs);
894
if ( cs->dispatchStatus != DBUS_DISPATCH_COMPLETE )
895
dbus_connection_dispatch( cs->connection );
897
if( idle_handler != 0L )
902
void dbus_svc_dispatch(DBusConnectionState *cs)
906
FD_ZERO(&(cs->s_r_fds));
907
FD_ZERO(&(cs->s_w_fds));
908
FD_ZERO(&(cs->s_e_fds));
910
process_timeouts(cs);
912
while ( cs->dispatchStatus != DBUS_DISPATCH_COMPLETE )
913
dbus_connection_dispatch( cs->connection );
917
dbus_svc_quit( DBusConnectionState *cs )
919
cs->status = SHUTDOWN;
924
( DBusConnection *connection,
926
dbus_svc_WatchHandler wh,
927
dbus_svc_ErrorHandler eh,
928
dbus_svc_ErrorHandler dh,
932
*dbus = dbcs_new( connection );
936
if(eh)(*(eh))("connection_setup: out of memory");
940
(*dbus)->wh_arg = wh_arg;
944
if (!dbus_connection_set_watch_functions
945
( (*dbus)->connection,
954
if( (*dbus)->eh != 0L ) (*((*dbus)->eh))("connection_setup: dbus_connection_set_watch_functions failed");
958
if (!dbus_connection_set_timeout_functions
968
if( (*dbus)->eh != 0L ) (*((*dbus)->eh))("connection_setup: dbus_connection_set_timeout_functions failed");
972
dbus_connection_set_dispatch_status_function
979
if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
980
dbus_connection_ref(connection);
982
return ISC_R_SUCCESS;
988
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
989
dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
990
dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
992
return ISC_R_FAILURE;
998
dbus_svc_DBUS_TYPE bus,
1001
dbus_svc_WatchHandler wh ,
1002
dbus_svc_ErrorHandler eh ,
1003
dbus_svc_ErrorHandler dh ,
1007
DBusConnection *connection;
1009
char *session_bus_address=0L;
1011
memset(&error,'\0',sizeof(DBusError));
1013
dbus_error_init(&error);
1017
/* DBUS_PRIVATE_* bus types are the only type which allow reconnection if the dbus-daemon is restarted
1019
case DBUS_PRIVATE_SYSTEM:
1021
if ( (connection = dbus_connection_open_private("unix:path=/var/run/dbus/system_bus_socket", &error)) == 0L )
1023
if(eh)(*eh)("dbus_svc_init failed: %s %s",error.name, error.message);
1024
return ISC_R_FAILURE;
1027
if ( ! dbus_bus_register(connection,&error) )
1029
if(eh)(*eh)("dbus_bus_register failed: %s %s", error.name, error.message);
1030
dbus_connection_close(connection);
1032
return ISC_R_FAILURE;
1036
case DBUS_PRIVATE_SESSION:
1038
session_bus_address = getenv("DBUS_SESSION_BUS_ADDRESS");
1039
if ( session_bus_address == 0L )
1041
if(eh)(*eh)("dbus_svc_init failed: DBUS_SESSION_BUS_ADDRESS environment variable not set");
1042
return ISC_R_FAILURE;
1045
if ( (connection = dbus_connection_open_private(session_bus_address, &error)) == 0L )
1047
if(eh)(*eh)("dbus_svc_init failed: %s %s",error.name, error.message);
1048
return ISC_R_FAILURE;
1051
if ( ! dbus_bus_register(connection,&error) )
1053
if(eh)(*eh)("dbus_bus_register failed: %s %s", error.name, error.message);
1054
dbus_connection_close(connection);
1056
return ISC_R_FAILURE;
1063
if ( (connection = dbus_bus_get (bus, &error)) == 0L )
1065
if(eh)(*eh)("dbus_svc_init failed: %s %s",error.name, error.message);
1066
return ISC_R_FAILURE;
1071
if(eh)(*eh)("dbus_svc_init failed: unknown bus type %d", bus);
1072
return ISC_R_FAILURE;
1075
dbus_connection_set_exit_on_disconnect(connection, FALSE);
1077
if ( (connection_setup(connection, dbus, wh, eh, dh, wh_arg)) != ISC_R_SUCCESS)
1079
if(eh)(*eh)("dbus_svc_init failed: connection_setup failed");
1080
return ISC_R_FAILURE;
1084
return ISC_R_SUCCESS;
1086
(*dbus)->unique_name = dbus_bus_get_unique_name(connection);
1089
( dbus_bus_request_name
1091
#ifdef DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT
1092
DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT ,
1100
case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
1102
case DBUS_REQUEST_NAME_REPLY_EXISTS:
1103
case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
1104
case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
1105
if(eh)(*eh)("dbus_svc_init: dbus_bus_request_name failed: Name already registered");
1108
if(eh)(*eh)("dbus_svc_init: dbus_bus_request_name failed: %s %s", error.name, error.message);
1111
return ISC_R_SUCCESS;
1114
dbus_connection_close( connection );
1115
dbus_connection_unref( connection );
1118
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
1119
dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
1120
dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
1123
return ISC_R_FAILURE;
1126
const char *dbus_svc_unique_name(DBusConnectionState *cs)
1128
return cs->unique_name;
1132
dbus_svc_shutdown ( DBusConnectionState *cs )
1134
if (!dbus_connection_set_watch_functions
1136
NULL, NULL, NULL, NULL, NULL
1138
) if( cs->eh != 0L ) (*(cs->eh))("connection_shutdown: dbus_connection_set_watch_functions: No Memory."
1139
"Setting watch functions to NULL failed."
1142
if (!dbus_connection_set_timeout_functions
1144
NULL, NULL, NULL, NULL, NULL
1146
) if( cs->eh != 0L ) (*(cs->eh))("connection_shutdown: dbus_connection_set_timeout_functions: No Memory."
1147
"Setting timeout functions to NULL failed."
1150
dbus_connection_set_dispatch_status_function (cs->connection, NULL, NULL, NULL);
1152
tdestroy( cs->timeouts, free);
1154
tdestroy( cs->watches, no_free);
1157
dbus_connection_close( cs->connection );
1158
dbus_connection_unref( cs->connection );