X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dbus%2Fdbus-watch.c;h=b82c57d407bb8b2ef06ecb09001215ff27b3bbc0;hb=61d97215c317a4154df47fbfb882aab60b92fbab;hp=484dbbe65380a81995279b402b3c7c0a18b45ef2;hpb=6db588b8544e117241a3be2c595dfc8fdcdc8f59;p=platform%2Fupstream%2Fdbus.git diff --git a/dbus/dbus-watch.c b/dbus/dbus-watch.c index 484dbbe..b82c57d 100644 --- a/dbus/dbus-watch.c +++ b/dbus/dbus-watch.c @@ -21,6 +21,7 @@ * */ +#include #include "dbus-internals.h" #include "dbus-watch.h" #include "dbus-list.h" @@ -49,6 +50,7 @@ struct DBusWatch void *data; /**< Application data. */ DBusFreeFunction free_data_function; /**< Free the application data. */ unsigned int enabled : 1; /**< Whether it's enabled. */ + unsigned int oom_last_time : 1; /**< Whether it was OOM last time. */ }; dbus_bool_t @@ -57,6 +59,19 @@ _dbus_watch_get_enabled (DBusWatch *watch) return watch->enabled; } +dbus_bool_t +_dbus_watch_get_oom_last_time (DBusWatch *watch) +{ + return watch->oom_last_time; +} + +void +_dbus_watch_set_oom_last_time (DBusWatch *watch, + dbus_bool_t oom) +{ + watch->oom_last_time = oom; +} + /** * Creates a new DBusWatch. Used to add a file descriptor to be polled * by a main loop. @@ -128,6 +143,9 @@ _dbus_watch_unref (DBusWatch *watch) watch->refcount -= 1; if (watch->refcount == 0) { + if (watch->fd != -1) + _dbus_warn ("this watch should have been invalidated"); + dbus_watch_set_data (watch, NULL, NULL); /* call free_data_function */ if (watch->free_handler_data_function) @@ -241,6 +259,25 @@ _dbus_watch_list_free (DBusWatchList *watch_list) dbus_free (watch_list); } +#ifdef DBUS_ENABLE_VERBOSE_MODE +static const char* +watch_flags_to_string (int flags) +{ + const char *watch_type; + + if ((flags & DBUS_WATCH_READABLE) && + (flags & DBUS_WATCH_WRITABLE)) + watch_type = "readwrite"; + else if (flags & DBUS_WATCH_READABLE) + watch_type = "read"; + else if (flags & DBUS_WATCH_WRITABLE) + watch_type = "write"; + else + watch_type = "not read or write"; + return watch_type; +} +#endif /* DBUS_ENABLE_VERBOSE_MODE */ + /** * Sets the watch functions. This function is the "backend" * for dbus_connection_set_watch_functions() and @@ -274,27 +311,9 @@ _dbus_watch_list_set_functions (DBusWatchList *watch_list, DBusList *next = _dbus_list_get_next_link (&watch_list->watches, link); -#ifdef DBUS_ENABLE_VERBOSE_MODE - { - const char *watch_type; - int flags; - - flags = dbus_watch_get_flags (link->data); - if ((flags & DBUS_WATCH_READABLE) && - (flags & DBUS_WATCH_WRITABLE)) - watch_type = "readwrite"; - else if (flags & DBUS_WATCH_READABLE) - watch_type = "read"; - else if (flags & DBUS_WATCH_WRITABLE) - watch_type = "write"; - else - watch_type = "not read or write"; - - _dbus_verbose ("Adding a %s watch on fd %d using newly-set add watch function\n", - watch_type, - dbus_watch_get_socket (link->data)); - } -#endif /* DBUS_ENABLE_VERBOSE_MODE */ + _dbus_verbose ("Adding a %s watch on fd %d using newly-set add watch function\n", + watch_flags_to_string (dbus_watch_get_flags (link->data)), + dbus_watch_get_socket (link->data)); if (!(* add_function) (link->data, data)) { @@ -495,6 +514,8 @@ _dbus_watch_set_handler (DBusWatch *watch, int dbus_watch_get_fd (DBusWatch *watch) { + _dbus_return_val_if_fail (watch != NULL, -1); + return dbus_watch_get_unix_fd(watch); } @@ -514,6 +535,8 @@ dbus_watch_get_fd (DBusWatch *watch) int dbus_watch_get_unix_fd (DBusWatch *watch) { + _dbus_return_val_if_fail (watch != NULL, -1); + /* FIXME remove #ifdef and do this on a lower level * (watch should have set_socket and set_unix_fd and track * which it has, and the transport should provide the @@ -541,6 +564,8 @@ dbus_watch_get_unix_fd (DBusWatch *watch) int dbus_watch_get_socket (DBusWatch *watch) { + _dbus_return_val_if_fail (watch != NULL, -1); + return watch->fd; } @@ -560,6 +585,7 @@ dbus_watch_get_socket (DBusWatch *watch) unsigned int dbus_watch_get_flags (DBusWatch *watch) { + _dbus_return_val_if_fail (watch != NULL, 0); _dbus_assert ((watch->flags & VALID_WATCH_FLAGS) == watch->flags); return watch->flags; @@ -575,6 +601,8 @@ dbus_watch_get_flags (DBusWatch *watch) void* dbus_watch_get_data (DBusWatch *watch) { + _dbus_return_val_if_fail (watch != NULL, NULL); + return watch->data; } @@ -594,6 +622,8 @@ dbus_watch_set_data (DBusWatch *watch, void *data, DBusFreeFunction free_data_function) { + _dbus_return_if_fail (watch != NULL); + _dbus_verbose ("Setting watch fd %d data to data = %p function = %p from data = %p function = %p\n", dbus_watch_get_socket (watch), data, free_data_function, watch->data, watch->free_data_function); @@ -615,7 +645,8 @@ dbus_watch_set_data (DBusWatch *watch, dbus_bool_t dbus_watch_get_enabled (DBusWatch *watch) { - _dbus_assert (watch != NULL); + _dbus_return_val_if_fail (watch != NULL, FALSE); + return watch->enabled; } @@ -646,11 +677,12 @@ dbus_bool_t dbus_watch_handle (DBusWatch *watch, unsigned int flags) { + _dbus_return_val_if_fail (watch != NULL, FALSE); + #ifndef DBUS_DISABLE_CHECKS if (watch->fd < 0 || watch->flags == 0) { - _dbus_warn_check_failed ("%s: Watch is invalid, it should have been removed\n", - _DBUS_FUNCTION_NAME); + _dbus_warn_check_failed ("Watch is invalid, it should have been removed\n"); return TRUE; } #endif