index.html
Main Page
|
modules.html
Modules
|
namespaces.html
Namespace List
|
hierarchy.html
Class Hierarchy
|
annotated.html
Data Structures
|
dirs.html
Directories
|
files.html
File List
|
namespacemembers.html
Namespace Members
|
functions.html
Data Fields
|
pages.html
Related Pages
dir_000004.html
dbus
dbus-timeout.c
00001
/* -*- mode: C; c-file-style: "gnu" -*- */
00002
/* dbus-timeout.c DBusTimeout implementation
00003
*
00004
* Copyright (C) 2003  CodeFactory AB
00005
*
00006
* Licensed under the Academic Free License version 2.1
00007
*
00008
* This program is free software; you can redistribute it and/or modify
00009
* it under the terms of the GNU General Public License as published by
00010
* the Free Software Foundation; either version 2 of the License, or
00011
* (at your option) any later version.
00012
*
00013
* This program is distributed in the hope that it will be useful,
00014
* but WITHOUT ANY WARRANTY; without even the implied warranty of
00015
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016
* GNU General Public License for more details.
00017
*
00018
* You should have received a copy of the GNU General Public License
00019
* along with this program; if not, write to the Free Software
00020
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021
*
00022
*/
00023
00024
#include "dbus-internals.h"
00025
#include "dbus-timeout.h"
00026
#include "dbus-list.h"
00027
structDBusTimeout.html
00039
struct
structDBusTimeout.html
DBusTimeout
00040 {
structDBusTimeout.html#o0
00041
int
structDBusTimeout.html#o0
refcount
;
structDBusTimeout.html#o1
00042
int
structDBusTimeout.html#o1
interval
;
structDBusTimeout.html#o2
00044
DBusTimeoutHandler
structDBusTimeout.html#o2
handler
;
structDBusTimeout.html#o3
00045
void
*
structDBusTimeout.html#o3
handler_data
;
structDBusTimeout.html#o4
00046
group__DBusMemory.html#ga8
DBusFreeFunction
structDBusTimeout.html#o4
free_handler_data_function
;
structDBusTimeout.html#o5
00048
void
*
structDBusTimeout.html#o5
data
;
structDBusTimeout.html#o6
00049
group__DBusMemory.html#ga8
DBusFreeFunction
structDBusTimeout.html#o6
free_data_function
;
structDBusTimeout.html#o7
00050
unsigned
int
structDBusTimeout.html#o7
enabled
: 1;
00051 };
00052
00061
structDBusTimeout.html
DBusTimeout
*
group__DBusTimeoutInternals.html#ga0
00062
group__DBusTimeoutInternals.html#ga0
_dbus_timeout_new
(
int
interval,
00063                    DBusTimeoutHandler  handler,
00064
void
*data,
00065
group__DBusMemory.html#ga8
DBusFreeFunction
free_data_function)
00066 {
00067
structDBusTimeout.html
DBusTimeout
*timeout;
00068
00069   timeout =
group__DBusMemory.html#ga7
dbus_new0
(
structDBusTimeout.html
DBusTimeout
, 1);
00070
if
(timeout ==
group__DBusMacros.html#ga4
NULL
)
00071
return
group__DBusMacros.html#ga4
NULL
;
00072
00073   timeout->
structDBusTimeout.html#o0
refcount
= 1;
00074   timeout->
structDBusTimeout.html#o1
interval
= interval;
00075
00076   timeout->
structDBusTimeout.html#o2
handler
= handler;
00077   timeout->
structDBusTimeout.html#o3
handler_data
= data;
00078   timeout->
structDBusTimeout.html#o4
free_handler_data_function
= free_data_function;
00079
00080   timeout->
structDBusTimeout.html#o7
enabled
=
group__DBusMacros.html#ga2
TRUE
;
00081
00082
return
timeout;
00083 }
00084
00091
structDBusTimeout.html
DBusTimeout
*
group__DBusTimeoutInternals.html#ga1
00092
group__DBusTimeoutInternals.html#ga1
_dbus_timeout_ref
(
structDBusTimeout.html
DBusTimeout
*timeout)
00093 {
00094   timeout->
structDBusTimeout.html#o0
refcount
+= 1;
00095
00096
return
timeout;
00097 }
00098
00105
void
group__DBusTimeoutInternals.html#ga2
00106
group__DBusTimeoutInternals.html#ga2
_dbus_timeout_unref
(
structDBusTimeout.html
DBusTimeout
*timeout)
00107 {
00108
group__DBusInternalsUtils.html#ga130
_dbus_assert
(timeout !=
group__DBusMacros.html#ga4
NULL
);
00109
group__DBusInternalsUtils.html#ga130
_dbus_assert
(timeout->
structDBusTimeout.html#o0
refcount
> 0);
00110
00111   timeout->
structDBusTimeout.html#o0
refcount
-= 1;
00112
if
(timeout->
structDBusTimeout.html#o0
refcount
== 0)
00113     {
00114
group__DBusTimeout.html#ga2
dbus_timeout_set_data
(timeout,
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
/* call free_data_function */
00115
00116
if
(timeout->
structDBusTimeout.html#o4
free_handler_data_function
)
00117         (* timeout->
structDBusTimeout.html#o4
free_handler_data_function
) (timeout->
structDBusTimeout.html#o3
handler_data
);
00118
00119
group__DBusMemory.html#ga3
dbus_free
(timeout);
00120     }
00121 }
00122
00132
void
group__DBusTimeoutInternals.html#ga3
00133
group__DBusTimeoutInternals.html#ga3
_dbus_timeout_set_interval
(
structDBusTimeout.html
DBusTimeout
*timeout,
00134
int
interval)
00135 {
00136
group__DBusInternalsUtils.html#ga130
_dbus_assert
(interval >= 0);
00137
00138   timeout->
structDBusTimeout.html#o1
interval
= interval;
00139 }
00140
00151
void
group__DBusTimeoutInternals.html#ga4
00152
group__DBusTimeoutInternals.html#ga4
_dbus_timeout_set_enabled
(
structDBusTimeout.html
DBusTimeout
*timeout,
00153
group__DBusTypes.html#ga2
dbus_bool_t
enabled)
00154 {
00155   timeout->
structDBusTimeout.html#o7
enabled
= enabled !=
group__DBusMacros.html#ga3
FALSE
;
00156 }
00157
00158
structDBusTimeoutList.html
00175
struct
structDBusTimeoutList.html
DBusTimeoutList
00176 {
structDBusTimeoutList.html#o0
00177
structDBusList.html
DBusList
*
structDBusTimeoutList.html#o0
timeouts
;
structDBusTimeoutList.html#o1
00179
DBusAddTimeoutFunction
structDBusTimeoutList.html#o1
add_timeout_function
;
structDBusTimeoutList.html#o2
00180
DBusRemoveTimeoutFunction
structDBusTimeoutList.html#o2
remove_timeout_function
;
structDBusTimeoutList.html#o3
00181
DBusTimeoutToggledFunction
structDBusTimeoutList.html#o3
timeout_toggled_function
;
structDBusTimeoutList.html#o4
00182
void
*
structDBusTimeoutList.html#o4
timeout_data
;
structDBusTimeoutList.html#o5
00183
group__DBusMemory.html#ga8
DBusFreeFunction
structDBusTimeoutList.html#o5
timeout_free_data_function
;
00184 };
00185
00192
structDBusTimeoutList.html
DBusTimeoutList
*
group__DBusTimeoutInternals.html#ga5
00193
group__DBusTimeoutInternals.html#ga5
_dbus_timeout_list_new
(
void
)
00194 {
00195
structDBusTimeoutList.html
DBusTimeoutList
*timeout_list;
00196
00197   timeout_list =
group__DBusMemory.html#ga7
dbus_new0
(
structDBusTimeoutList.html
DBusTimeoutList
, 1);
00198
if
(timeout_list ==
group__DBusMacros.html#ga4
NULL
)
00199
return
group__DBusMacros.html#ga4
NULL
;
00200
00201
return
timeout_list;
00202 }
00203
00209
void
group__DBusTimeoutInternals.html#ga6
00210
group__DBusTimeoutInternals.html#ga6
_dbus_timeout_list_free
(
structDBusTimeoutList.html
DBusTimeoutList
*timeout_list)
00211 {
00212
/* free timeout_data and remove timeouts as a side effect */
00213
group__DBusTimeoutInternals.html#ga7
_dbus_timeout_list_set_functions
(timeout_list,
00214
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00215
00216
group__DBusList.html#ga22
_dbus_list_foreach
(&timeout_list->
structDBusTimeoutList.html#o0
timeouts
,
00217                       (
group__DBusInternalsUtils.html#ga161
DBusForeachFunction
)
group__DBusTimeoutInternals.html#ga2
_dbus_timeout_unref
,
00218
group__DBusMacros.html#ga4
NULL
);
00219
group__DBusList.html#ga12
_dbus_list_clear
(&timeout_list->
structDBusTimeoutList.html#o0
timeouts
);
00220
00221
group__DBusMemory.html#ga3
dbus_free
(timeout_list);
00222 }
00223
00237
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusTimeoutInternals.html#ga7
00238
group__DBusTimeoutInternals.html#ga7
_dbus_timeout_list_set_functions
(
structDBusTimeoutList.html
DBusTimeoutList
*timeout_list,
00239                                   DBusAddTimeoutFunction     add_function,
00240                                   DBusRemoveTimeoutFunction  remove_function,
00241                                   DBusTimeoutToggledFunction toggled_function,
00242
void
*data,
00243
group__DBusMemory.html#ga8
DBusFreeFunction
free_data_function)
00244 {
00245
/* Add timeouts with the new function, failing on OOM */
00246
if
(add_function !=
group__DBusMacros.html#ga4
NULL
)
00247     {
00248
structDBusList.html
DBusList
*link;
00249
00250       link =
group__DBusList.html#ga13
_dbus_list_get_first_link
(&timeout_list->
structDBusTimeoutList.html#o0
timeouts
);
00251
while
(link !=
group__DBusMacros.html#ga4
NULL
)
00252         {
00253
structDBusList.html
DBusList
*next =
group__DBusList.html#ga24
_dbus_list_get_next_link
(&timeout_list->
structDBusTimeoutList.html#o0
timeouts
,
00254                                                      link);
00255
00256
if
(!(* add_function) (link->
structDBusList.html#o2
data
, data))
00257             {
00258
/* remove it all again and return FALSE */
00259
structDBusList.html
DBusList
*link2;
00260
00261               link2 =
group__DBusList.html#ga13
_dbus_list_get_first_link
(&timeout_list->
structDBusTimeoutList.html#o0
timeouts
);
00262
while
(link2 != link)
00263                 {
00264
structDBusList.html
DBusList
*next =
group__DBusList.html#ga24
_dbus_list_get_next_link
(&timeout_list->
structDBusTimeoutList.html#o0
timeouts
,
00265                                                              link2);
00266
00267                   (* remove_function) (link2->
structDBusList.html#o2
data
, data);
00268
00269                   link2 = next;
00270                 }
00271
00272
return
group__DBusMacros.html#ga3
FALSE
;
00273             }
00274
00275           link = next;
00276         }
00277     }
00278
00279
/* Remove all current timeouts from previous timeout handlers */
00280
00281
if
(timeout_list->
structDBusTimeoutList.html#o2
remove_timeout_function
!=
group__DBusMacros.html#ga4
NULL
)
00282     {
00283
group__DBusList.html#ga22
_dbus_list_foreach
(&timeout_list->
structDBusTimeoutList.html#o0
timeouts
,
00284                           (
group__DBusInternalsUtils.html#ga161
DBusForeachFunction
) timeout_list->
structDBusTimeoutList.html#o2
remove_timeout_function
,
00285                           timeout_list->
structDBusTimeoutList.html#o4
timeout_data
);
00286     }
00287
00288
if
(timeout_list->
structDBusTimeoutList.html#o5
timeout_free_data_function
!=
group__DBusMacros.html#ga4
NULL
)
00289     (* timeout_list->
structDBusTimeoutList.html#o5
timeout_free_data_function
) (timeout_list->
structDBusTimeoutList.html#o4
timeout_data
);
00290
00291   timeout_list->
structDBusTimeoutList.html#o1
add_timeout_function
= add_function;
00292   timeout_list->
structDBusTimeoutList.html#o2
remove_timeout_function
= remove_function;
00293   timeout_list->
structDBusTimeoutList.html#o3
timeout_toggled_function
= toggled_function;
00294   timeout_list->
structDBusTimeoutList.html#o4
timeout_data
= data;
00295   timeout_list->
structDBusTimeoutList.html#o5
timeout_free_data_function
= free_data_function;
00296
00297
return
group__DBusMacros.html#ga2
TRUE
;
00298 }
00299
00308
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusTimeoutInternals.html#ga8
00309
group__DBusTimeoutInternals.html#ga8
_dbus_timeout_list_add_timeout
(
structDBusTimeoutList.html
DBusTimeoutList
*timeout_list,
00310
structDBusTimeout.html
DBusTimeout
*timeout)
00311 {
00312
if
(!
group__DBusList.html#ga2
_dbus_list_append
(&timeout_list->
structDBusTimeoutList.html#o0
timeouts
, timeout))
00313
return
group__DBusMacros.html#ga3
FALSE
;
00314
00315
group__DBusTimeoutInternals.html#ga1
_dbus_timeout_ref
(timeout);
00316
00317
if
(timeout_list->
structDBusTimeoutList.html#o1
add_timeout_function
!=
group__DBusMacros.html#ga4
NULL
)
00318     {
00319
if
(!(* timeout_list->
structDBusTimeoutList.html#o1
add_timeout_function
) (timeout,
00320                                                    timeout_list->
structDBusTimeoutList.html#o4
timeout_data
))
00321         {
00322
group__DBusList.html#ga8
_dbus_list_remove_last
(&timeout_list->
structDBusTimeoutList.html#o0
timeouts
, timeout);
00323
group__DBusTimeoutInternals.html#ga2
_dbus_timeout_unref
(timeout);
00324
return
group__DBusMacros.html#ga3
FALSE
;
00325         }
00326     }
00327
00328
return
group__DBusMacros.html#ga2
TRUE
;
00329 }
00330
00338
void
group__DBusTimeoutInternals.html#ga9
00339
group__DBusTimeoutInternals.html#ga9
_dbus_timeout_list_remove_timeout
(
structDBusTimeoutList.html
DBusTimeoutList
*timeout_list,
00340
structDBusTimeout.html
DBusTimeout
*timeout)
00341 {
00342
if
(!
group__DBusList.html#ga7
_dbus_list_remove
(&timeout_list->
structDBusTimeoutList.html#o0
timeouts
, timeout))
00343
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Nonexistent timeout was removed"
);
00344
00345
if
(timeout_list->
structDBusTimeoutList.html#o2
remove_timeout_function
!=
group__DBusMacros.html#ga4
NULL
)
00346     (* timeout_list->
structDBusTimeoutList.html#o2
remove_timeout_function
) (timeout,
00347                                                timeout_list->
structDBusTimeoutList.html#o4
timeout_data
);
00348
00349
group__DBusTimeoutInternals.html#ga2
_dbus_timeout_unref
(timeout);
00350 }
00351
00360
void
group__DBusTimeoutInternals.html#ga10
00361
group__DBusTimeoutInternals.html#ga10
_dbus_timeout_list_toggle_timeout
(
structDBusTimeoutList.html
DBusTimeoutList
*timeout_list,
00362
structDBusTimeout.html
DBusTimeout
*timeout,
00363
group__DBusTypes.html#ga2
dbus_bool_t
enabled)
00364 {
00365   enabled = !!enabled;
00366
00367
if
(enabled == timeout->
structDBusTimeout.html#o7
enabled
)
00368
return
;
00369
00370   timeout->
structDBusTimeout.html#o7
enabled
= enabled;
00371
00372
if
(timeout_list->
structDBusTimeoutList.html#o3
timeout_toggled_function
!=
group__DBusMacros.html#ga4
NULL
)
00373     (* timeout_list->
structDBusTimeoutList.html#o3
timeout_toggled_function
) (timeout,
00374                                                 timeout_list->
structDBusTimeoutList.html#o4
timeout_data
);
00375 }
00376
00411
int
group__DBusTimeout.html#ga0
00412
group__DBusTimeout.html#ga0
dbus_timeout_get_interval
(
structDBusTimeout.html
DBusTimeout
*timeout)
00413 {
00414
return
timeout->
structDBusTimeout.html#o1
interval
;
00415 }
00416
00424
void
*
group__DBusTimeout.html#ga1
00425
group__DBusTimeout.html#ga1
dbus_timeout_get_data
(
structDBusTimeout.html
DBusTimeout
*timeout)
00426 {
00427
return
timeout->
structDBusTimeout.html#o5
data
;
00428 }
00429
00441
void
group__DBusTimeout.html#ga2
00442
group__DBusTimeout.html#ga2
dbus_timeout_set_data
(
structDBusTimeout.html
DBusTimeout
*timeout,
00443
void
*data,
00444
group__DBusMemory.html#ga8
DBusFreeFunction
free_data_function)
00445 {
00446
if
(timeout->
structDBusTimeout.html#o6
free_data_function
!=
group__DBusMacros.html#ga4
NULL
)
00447     (* timeout->
structDBusTimeout.html#o6
free_data_function
) (timeout->
structDBusTimeout.html#o5
data
);
00448
00449   timeout->
structDBusTimeout.html#o5
data
= data;
00450   timeout->
structDBusTimeout.html#o6
free_data_function
= free_data_function;
00451 }
00452
00467
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusTimeout.html#ga3
00468
group__DBusTimeout.html#ga3
dbus_timeout_handle
(
structDBusTimeout.html
DBusTimeout
*timeout)
00469 {
00470
return
(* timeout->
structDBusTimeout.html#o2
handler
) (timeout->
structDBusTimeout.html#o3
handler_data
);
00471 }
00472
00473
00481
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusTimeout.html#ga4
00482
group__DBusTimeout.html#ga4
dbus_timeout_get_enabled
(
structDBusTimeout.html
DBusTimeout
*timeout)
00483 {
00484
return
timeout->
structDBusTimeout.html#o7
enabled
;
00485 }
00486
Generated on Tue Sep 13 01:28:07 2005 for D-BUS by
http://www.doxygen.org/index.html
doxygen
1.4.4
