dbus: remove export_symbols_internal, it will always be empty
[platform/upstream/dbus.git] / dbus / dbus-watch.c
index 634ab24..b9f4ac2 100644 (file)
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /* dbus-watch.c DBusWatch implementation
  *
  * Copyright (C) 2002, 2003  Red Hat Inc.
  * 
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
 
+#include <config.h>
 #include "dbus-internals.h"
 #include "dbus-watch.h"
 #include "dbus-list.h"
@@ -49,8 +50,28 @@ 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
+_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.
@@ -122,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)
@@ -489,11 +513,9 @@ _dbus_watch_set_handler (DBusWatch        *watch,
 int
 dbus_watch_get_fd (DBusWatch *watch)
 {
-#ifdef DBUS_WIN_FIXME
-  return watch->fd;
-#else
+  _dbus_return_val_if_fail (watch != NULL, -1);
+
   return dbus_watch_get_unix_fd(watch);
-#endif
 }
 
 /**
@@ -512,6 +534,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
@@ -520,7 +544,7 @@ dbus_watch_get_unix_fd (DBusWatch *watch)
 #ifdef DBUS_UNIX
   return watch->fd;
 #else
-  return -1;
+  return dbus_watch_get_socket( watch );
 #endif
 }
 
@@ -539,6 +563,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;
 }
 
@@ -558,6 +584,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;
@@ -573,6 +600,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;
 }
 
@@ -592,6 +621,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);
@@ -613,7 +644,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;
 }
 
@@ -644,11 +676,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