4141
4242#include "mdm-signal-handler.h"
4343
44- #define MDM_SIGNAL_HANDLER_GET_PRIVATE (o ) \
45- (G_TYPE_INSTANCE_GET_PRIVATE((o), MDM_TYPE_SIGNAL_HANDLER, MdmSignalHandlerPrivate))
46-
4744#ifdef __GNUC__
4845#define UNUSED_VARIABLE __attribute__ ((unused))
4946#else
@@ -57,7 +54,8 @@ typedef struct {
5754 guint id ;
5855} CallbackData ;
5956
60- struct MdmSignalHandlerPrivate {
57+ struct _MdmSignalHandler {
58+ GObject parent_instance ;
6159 GHashTable * lookup ;
6260 GHashTable * id_lookup ;
6361 GHashTable * action_lookup ;
@@ -124,7 +122,7 @@ static gboolean signal_io_watch(GIOChannel* ioc, GIOCondition condition, MdmSign
124122 signum = (gint32 ) buf [i ];
125123
126124 g_debug ("MdmSignalHandler: handling signal %d" , signum );
127- handlers = g_hash_table_lookup (handler -> priv -> lookup , GINT_TO_POINTER (signum ));
125+ handlers = g_hash_table_lookup (handler -> lookup , GINT_TO_POINTER (signum ));
128126
129127 g_debug ("MdmSignalHandler: Found %u callbacks" , g_slist_length (handlers ));
130128
@@ -133,7 +131,7 @@ static gboolean signal_io_watch(GIOChannel* ioc, GIOCondition condition, MdmSign
133131 gboolean res ;
134132 CallbackData * data ;
135133
136- data = g_hash_table_lookup (handler -> priv -> id_lookup , l -> data );
134+ data = g_hash_table_lookup (handler -> id_lookup , l -> data );
137135
138136 if (data != NULL )
139137 {
@@ -156,10 +154,10 @@ static gboolean signal_io_watch(GIOChannel* ioc, GIOCondition condition, MdmSign
156154
157155 if (is_fatal )
158156 {
159- if (handler -> priv -> fatal_func != NULL )
157+ if (handler -> fatal_func != NULL )
160158 {
161159 g_debug ("MdmSignalHandler: Caught termination signal - calling fatal func" );
162- handler -> priv -> fatal_func (handler -> priv -> fatal_data );
160+ handler -> fatal_func (handler -> fatal_data );
163161 }
164162 else
165163 {
@@ -310,7 +308,7 @@ static void catch_signal(MdmSignalHandler *handler, int signal_number)
310308
311309 sigaction (signal_number , & action , old_action );
312310
313- g_hash_table_insert (handler -> priv -> action_lookup , GINT_TO_POINTER (signal_number ), old_action );
311+ g_hash_table_insert (handler -> action_lookup , GINT_TO_POINTER (signal_number ), old_action );
314312}
315313
316314static void uncatch_signal (MdmSignalHandler * handler , int signal_number )
@@ -319,8 +317,8 @@ static void uncatch_signal(MdmSignalHandler* handler, int signal_number)
319317
320318 g_debug ("MdmSignalHandler: Unregistering for %d signals" , signal_number );
321319
322- old_action = g_hash_table_lookup (handler -> priv -> action_lookup , GINT_TO_POINTER (signal_number ));
323- g_hash_table_remove (handler -> priv -> action_lookup , GINT_TO_POINTER (signal_number ));
320+ old_action = g_hash_table_lookup (handler -> action_lookup , GINT_TO_POINTER (signal_number ));
321+ g_hash_table_remove (handler -> action_lookup , GINT_TO_POINTER (signal_number ));
324322
325323 sigaction (signal_number , old_action , NULL );
326324
@@ -338,22 +336,22 @@ guint mdm_signal_handler_add(MdmSignalHandler* handler, int signal_number, MdmSi
338336 cdata -> signal_number = signal_number ;
339337 cdata -> func = callback ;
340338 cdata -> data = data ;
341- cdata -> id = handler -> priv -> next_id ++ ;
339+ cdata -> id = handler -> next_id ++ ;
342340
343341 g_debug ("MdmSignalHandler: Adding handler %u: signum=%d %p" , cdata -> id , cdata -> signal_number , cdata -> func );
344342
345- if (g_hash_table_lookup (handler -> priv -> action_lookup , GINT_TO_POINTER (signal_number )) == NULL )
343+ if (g_hash_table_lookup (handler -> action_lookup , GINT_TO_POINTER (signal_number )) == NULL )
346344 {
347345 catch_signal (handler , signal_number );
348346 }
349347
350348 /* ID lookup owns the CallbackData */
351- g_hash_table_insert (handler -> priv -> id_lookup , GUINT_TO_POINTER (cdata -> id ), cdata );
349+ g_hash_table_insert (handler -> id_lookup , GUINT_TO_POINTER (cdata -> id ), cdata );
352350
353- list = g_hash_table_lookup (handler -> priv -> lookup , GINT_TO_POINTER (signal_number ));
351+ list = g_hash_table_lookup (handler -> lookup , GINT_TO_POINTER (signal_number ));
354352 list = g_slist_prepend (list , GUINT_TO_POINTER (cdata -> id ));
355353
356- g_hash_table_insert (handler -> priv -> lookup , GINT_TO_POINTER (signal_number ), list );
354+ g_hash_table_insert (handler -> lookup , GINT_TO_POINTER (signal_number ), list );
357355
358356 return cdata -> id ;
359357}
@@ -380,7 +378,7 @@ static void mdm_signal_handler_remove_and_free_data(MdmSignalHandler* handler, C
380378
381379 g_return_if_fail (MDM_IS_SIGNAL_HANDLER (handler ));
382380
383- list = g_hash_table_lookup (handler -> priv -> lookup , GINT_TO_POINTER (cdata -> signal_number ));
381+ list = g_hash_table_lookup (handler -> lookup , GINT_TO_POINTER (cdata -> signal_number ));
384382 list = g_slist_remove_all (list , GUINT_TO_POINTER (cdata -> id ));
385383
386384 if (list == NULL )
@@ -390,9 +388,9 @@ static void mdm_signal_handler_remove_and_free_data(MdmSignalHandler* handler, C
390388
391389 g_debug ("MdmSignalHandler: Removing handler %u: signum=%d %p" , cdata -> signal_number , cdata -> id , cdata -> func );
392390 /* put changed list back in */
393- g_hash_table_insert (handler -> priv -> lookup , GINT_TO_POINTER (cdata -> signal_number ), list );
391+ g_hash_table_insert (handler -> lookup , GINT_TO_POINTER (cdata -> signal_number ), list );
394392
395- g_hash_table_remove (handler -> priv -> id_lookup , GUINT_TO_POINTER (cdata -> id ));
393+ g_hash_table_remove (handler -> id_lookup , GUINT_TO_POINTER (cdata -> id ));
396394}
397395
398396void mdm_signal_handler_remove (MdmSignalHandler * handler , guint id )
@@ -401,7 +399,7 @@ void mdm_signal_handler_remove(MdmSignalHandler* handler, guint id)
401399
402400 g_return_if_fail (MDM_IS_SIGNAL_HANDLER (handler ));
403401
404- found = g_hash_table_lookup (handler -> priv -> id_lookup , GUINT_TO_POINTER (id ));
402+ found = g_hash_table_lookup (handler -> id_lookup , GUINT_TO_POINTER (id ));
405403
406404 if (found != NULL )
407405 {
@@ -418,7 +416,7 @@ static CallbackData* find_callback_data_by_func(MdmSignalHandler* handler, guint
418416
419417 found = NULL ;
420418
421- list = g_hash_table_lookup (handler -> priv -> lookup , GINT_TO_POINTER (signal_number ));
419+ list = g_hash_table_lookup (handler -> lookup , GINT_TO_POINTER (signal_number ));
422420
423421 for (l = list ; l != NULL ; l = l -> next )
424422 {
@@ -427,7 +425,7 @@ static CallbackData* find_callback_data_by_func(MdmSignalHandler* handler, guint
427425
428426 id = GPOINTER_TO_UINT (l -> data );
429427
430- d = g_hash_table_lookup (handler -> priv -> id_lookup , GUINT_TO_POINTER (id ));
428+ d = g_hash_table_lookup (handler -> id_lookup , GUINT_TO_POINTER (id ));
431429
432430 if (d != NULL && d -> func == callback && d -> data == data )
433431 {
@@ -461,8 +459,6 @@ static void mdm_signal_handler_class_init(MdmSignalHandlerClass* klass)
461459 GObjectClass * object_class = G_OBJECT_CLASS (klass );
462460
463461 object_class -> finalize = mdm_signal_handler_finalize ;
464-
465- g_type_class_add_private (klass , sizeof (MdmSignalHandlerPrivate ));
466462}
467463
468464static void signal_list_free (GSList * list )
@@ -474,21 +470,19 @@ void mdm_signal_handler_set_fatal_func(MdmSignalHandler* handler, MdmShutdownHan
474470{
475471 g_return_if_fail (MDM_IS_SIGNAL_HANDLER (handler ));
476472
477- handler -> priv -> fatal_func = func ;
478- handler -> priv -> fatal_data = user_data ;
473+ handler -> fatal_func = func ;
474+ handler -> fatal_data = user_data ;
479475}
480476
481477static void mdm_signal_handler_init (MdmSignalHandler * handler )
482478{
483479 GIOChannel * ioc ;
484480
485- handler -> priv = MDM_SIGNAL_HANDLER_GET_PRIVATE ( handler ) ;
481+ handler -> next_id = 1 ;
486482
487- handler -> priv -> next_id = 1 ;
488-
489- handler -> priv -> lookup = g_hash_table_new (NULL , NULL );
490- handler -> priv -> id_lookup = g_hash_table_new (NULL , NULL );
491- handler -> priv -> action_lookup = g_hash_table_new (NULL , NULL );
483+ handler -> lookup = g_hash_table_new (NULL , NULL );
484+ handler -> id_lookup = g_hash_table_new (NULL , NULL );
485+ handler -> action_lookup = g_hash_table_new (NULL , NULL );
492486
493487 if (pipe (signal_pipes ) == -1 )
494488 {
@@ -514,28 +508,26 @@ static void mdm_signal_handler_finalize(GObject* object)
514508
515509 g_debug ("MdmSignalHandler: Finalizing signal handler" );
516510
517- g_return_if_fail (handler -> priv != NULL );
518-
519- for (l = g_hash_table_get_values (handler -> priv -> lookup ); l != NULL ; l = l -> next )
511+ for (l = g_hash_table_get_values (handler -> lookup ); l != NULL ; l = l -> next )
520512 {
521513 signal_list_free ((GSList * ) l -> data );
522514 }
523515
524- g_hash_table_destroy (handler -> priv -> lookup );
516+ g_hash_table_destroy (handler -> lookup );
525517
526- for (l = g_hash_table_get_values (handler -> priv -> id_lookup ); l != NULL ; l = l -> next )
518+ for (l = g_hash_table_get_values (handler -> id_lookup ); l != NULL ; l = l -> next )
527519 {
528520 callback_data_free ((CallbackData * ) l -> data );
529521 }
530522
531- g_hash_table_destroy (handler -> priv -> id_lookup );
523+ g_hash_table_destroy (handler -> id_lookup );
532524
533- for (l = g_hash_table_get_values (handler -> priv -> action_lookup ); l != NULL ; l = l -> next )
525+ for (l = g_hash_table_get_values (handler -> action_lookup ); l != NULL ; l = l -> next )
534526 {
535527 g_free (l -> data );
536528 }
537529
538- g_hash_table_destroy (handler -> priv -> action_lookup );
530+ g_hash_table_destroy (handler -> action_lookup );
539531
540532 close (signal_pipes [0 ]);
541533 close (signal_pipes [1 ]);
0 commit comments