summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2009-11-02 08:44:17 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2009-11-02 08:44:17 +0800
commitff3205d84c829561a8623487f847d24d571f4605 (patch)
treef636d4102020ca509737afb2b5116d67a4bdf24a
parent3a302647569ab477fc816599028ad3c8631f89dc (diff)
milkway: add mw-idle-source
-rw-r--r--milkway/Makefile.am6
-rw-r--r--milkway/mw-idle-source.c75
-rw-r--r--milkway/mw-idle-source.h47
3 files changed, 126 insertions, 2 deletions
diff --git a/milkway/Makefile.am b/milkway/Makefile.am
index 25163d1..7a51f8e 100644
--- a/milkway/Makefile.am
+++ b/milkway/Makefile.am
@@ -33,7 +33,8 @@ milkway_headers = \
mw-poll-imp.h \
mw-main-context.h \
mw-main-loop.h \
- mw-timeout-source.h
+ mw-timeout-source.h \
+ mw-idle-source.h
libmilkway_la_LDFLAGS = -version-info $(LT_VERSION_INFO) -no-undefined
libmilkway_la_LIBADD = @DEP_LIBS@ $(PTHREAD_LIBS)
@@ -82,7 +83,8 @@ libmilkway_la_SOURCES = \
mw-main-context-private.h \
mw-main-context.c \
mw-main-loop.c \
- mw-timeout-source.c
+ mw-timeout-source.c \
+ mw-idle-source.c
milkwayincludedir = $(includedir)/milkway/milkway
milkwayinclude_HEADERS = $(milkway_headers)
diff --git a/milkway/mw-idle-source.c b/milkway/mw-idle-source.c
new file mode 100644
index 0000000..11c0dca
--- /dev/null
+++ b/milkway/mw-idle-source.c
@@ -0,0 +1,75 @@
+/* Milkway
+ *
+ * Copyright (C) 2008- Luo Jinghua <sunmoon1997@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "milkwayint.h"
+#include "milkway/mw-idle-source.h"
+
+#include <stdlib.h>
+
+mw_idle_source_t*
+mw_idle_source_init(mw_idle_source_t *self)
+{
+ if (!mw_source_init(&self->base))
+ return NULL;
+ return self;
+}
+
+mw_idle_source_t*
+mw_idle_source_new(void)
+{
+ mw_idle_source_t *self;
+
+ self = mw_object_alloc(MW_IDLE_SOURCE_TYPE);
+ if (!self)
+ return NULL;
+ return mw_idle_source_init(self);
+}
+
+static mw_bool_t
+mw_idle_source_prepare(mw_source_t *super,
+ int *timeout)
+{
+ /* mw_idle_source_t* self = (mw_idle_source_t*)super; */
+ *timeout = 0;
+ return MW_TRUE;
+}
+
+static mw_bool_t
+mw_idle_source_check(mw_source_t *super)
+{
+ /* mw_idle_source_t* self = (mw_idle_source_t*)super; */
+ return MW_TRUE;
+}
+
+static void
+mw_idle_source_finalize(mw_object_t *super)
+{
+ MW_SUPER_FINALIZE(super, MW_IDLE_SOURCE_TYPE)(super);
+}
+
+static void
+mw_idle_source_type_init(mw_idle_source_type_t *self)
+{
+ self->base.base.finalize = mw_idle_source_finalize;
+ self->base.prepare = mw_idle_source_prepare;
+ self->base.check = mw_idle_source_check;
+}
+
+MW_DEFINE_GET_TYPE(mw_idle_source, mw_idle_source_type_t,
+ MW_SOURCE_TYPE, "MWIdleSource", 0);
diff --git a/milkway/mw-idle-source.h b/milkway/mw-idle-source.h
new file mode 100644
index 0000000..440237c
--- /dev/null
+++ b/milkway/mw-idle-source.h
@@ -0,0 +1,47 @@
+/* Milkway
+ *
+ * Copyright (C) 2008- Luo Jinghua <sunmoon1997@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef MW_IDLE_SOURCE_H
+#define MW_IDLE_SOURCE_H
+
+#include <milkway/mw-source.h>
+
+typedef struct _mw_idle_source_type mw_idle_source_type_t;
+typedef struct _mw_idle_source mw_idle_source_t;
+
+#define MW_IDLE_SOURCE_TYPE mw_idle_source_get_type()
+
+struct _mw_idle_source_type {
+ mw_source_type_t base;
+};
+
+struct _mw_idle_source {
+ mw_source_t base;
+};
+
+mw_public mw_idle_source_type_t*
+mw_idle_source_get_type(void);
+
+mw_public mw_idle_source_t*
+mw_idle_source_init(mw_idle_source_t *self);
+
+mw_public mw_idle_source_t*
+mw_idle_source_new(void);
+
+#endif