[wing/wip/source] Provide a public wing_create_source
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [wing/wip/source] Provide a public wing_create_source
- Date: Tue, 20 Sep 2016 11:42:02 +0000 (UTC)
commit 315ee3c01fa49d46df1312217623e9129f511ae9
Author: Ignacio Casal Quinteiro <ignacio casal nice-software com>
Date: Tue Sep 20 13:40:55 2016 +0200
Provide a public wing_create_source
This allows to pull on a specific condition on a windows HANDLE.
This was already in the code and this patch makes it public api.
wing/Makefile.sources | 4 +-
wing/wingnamedpipelistener.c | 7 ++-
wing/{wingasynchelper.c => wingsource.c} | 74 +++++++++++++++++++-----------
wing/{wingasynchelper.h => wingsource.h} | 17 ++++---
4 files changed, 63 insertions(+), 39 deletions(-)
---
diff --git a/wing/Makefile.sources b/wing/Makefile.sources
index 875ca95..dbdc472 100644
--- a/wing/Makefile.sources
+++ b/wing/Makefile.sources
@@ -3,14 +3,14 @@ NULL =
# Base and default-included sources and headers
WING_BASE_sources = \
- wingasynchelper.c \
- wingasynchelper.h \
wingnamedpipeclient.c \
wingnamedpipeconnection.c \
wingnamedpipelistener.c \
wingservice.c \
wingservice-private.h \
wingservicemanager.c \
+ wingsource.c \
+ wingsource.h \
wingutils.c \
$(NULL)
diff --git a/wing/wingnamedpipelistener.c b/wing/wingnamedpipelistener.c
index f65f7e3..81f1e61 100644
--- a/wing/wingnamedpipelistener.c
+++ b/wing/wingnamedpipelistener.c
@@ -19,7 +19,7 @@
#include "wingnamedpipelistener.h"
#include "wingnamedpipeconnection.h"
-#include "wingasynchelper.h"
+#include "wingsource.h"
#include <windows.h>
@@ -325,8 +325,9 @@ add_sources (WingNamedPipeListener *listener,
{
data = priv->named_pipes->pdata[i];
- source = _wing_handle_create_source (data->overlapped.hEvent,
- cancellable);
+ source = wing_create_source (data->overlapped.hEvent,
+ G_IO_IN,
+ cancellable);
g_source_set_callback (source,
(GSourceFunc) callback,
callback_data, NULL);
diff --git a/wing/wingasynchelper.c b/wing/wingsource.c
similarity index 50%
rename from wing/wingasynchelper.c
rename to wing/wingsource.c
index 564a1b3..0e7f615 100644
--- a/wing/wingasynchelper.c
+++ b/wing/wingsource.c
@@ -16,49 +16,49 @@
*/
-#include "wingasynchelper.h"
+#include "wingsource.h"
typedef struct {
GSource source;
GPollFD pollfd;
-} WingHandleSource;
+} WingSource;
static gboolean
-wing_handle_source_prepare (GSource *source,
- gint *timeout)
+wing_source_prepare (GSource *source,
+ gint *timeout)
{
*timeout = -1;
return FALSE;
}
static gboolean
-wing_handle_source_check (GSource *source)
+wing_source_check (GSource *source)
{
- WingHandleSource *hsource = (WingHandleSource *)source;
+ WingSource *hsource = (WingSource *)source;
return hsource->pollfd.revents;
}
static gboolean
-wing_handle_source_dispatch (GSource *source,
- GSourceFunc callback,
- gpointer user_data)
+wing_source_dispatch (GSource *source,
+ GSourceFunc callback,
+ gpointer user_data)
{
- WingHandleSourceFunc func = (WingHandleSourceFunc)callback;
- WingHandleSource *hsource = (WingHandleSource *)source;
+ WingSourceFunc func = (WingSourceFunc)callback;
+ WingSource *hsource = (WingSource *)source;
return func (hsource->pollfd.fd, user_data);
}
static void
-wing_handle_source_finalize (GSource *source)
+wing_source_finalize (GSource *source)
{
}
static gboolean
-wing_handle_source_closure_callback (HANDLE handle,
- gpointer data)
+wing_source_closure_callback (HANDLE handle,
+ gpointer data)
{
GClosure *closure = data;
@@ -80,24 +80,44 @@ wing_handle_source_closure_callback (HANDLE handle,
return result;
}
-GSourceFuncs wing_handle_source_funcs = {
- wing_handle_source_prepare,
- wing_handle_source_check,
- wing_handle_source_dispatch,
- wing_handle_source_finalize,
- (GSourceFunc)wing_handle_source_closure_callback,
+GSourceFuncs wing_source_funcs = {
+ wing_source_prepare,
+ wing_source_check,
+ wing_source_dispatch,
+ wing_source_finalize,
+ (GSourceFunc)wing_source_closure_callback,
};
+/**
+ * wing_create_source:
+ * @handle: a windows HANDLE
+ * @condition: a #GIOCondition mask to monitor
+ * @cancellable: (allow-none): a %GCancellable or %NULL
+ *
+ * Creates a #GSource that can be attached to a %GMainContext to monitor
+ * for the availability of the specified @condition on the handle.
+ *
+ * The callback on the source is of the #WingSourceFunc type.
+ *
+ * @cancellable if not %NULL can be used to cancel the source, which will
+ * cause the source to trigger, reporting the current condition (which
+ * is likely 0 unless cancellation happened at the same time as a
+ * condition change). You can check for this in the callback using
+ * g_cancellable_is_cancelled().
+ *
+ * Returns: (transfer full): a newly allocated %GSource, free with g_source_unref().
+ */
GSource *
-_wing_handle_create_source (HANDLE handle,
- GCancellable *cancellable)
+wing_create_source (HANDLE handle,
+ GIOCondition condition,
+ GCancellable *cancellable)
{
- WingHandleSource *hsource;
+ WingSource *hsource;
GSource *source;
- source = g_source_new (&wing_handle_source_funcs, sizeof (WingHandleSource));
- hsource = (WingHandleSource *)source;
- g_source_set_name (source, "WingHandle");
+ source = g_source_new (&wing_source_funcs, sizeof (WingSource));
+ hsource = (WingSource *)source;
+ g_source_set_name (source, "WingSource");
if (cancellable)
{
@@ -110,7 +130,7 @@ _wing_handle_create_source (HANDLE handle,
}
hsource->pollfd.fd = (gint)handle;
- hsource->pollfd.events = G_IO_IN;
+ hsource->pollfd.events = condition;
hsource->pollfd.revents = 0;
g_source_add_poll (source, &hsource->pollfd);
diff --git a/wing/wingasynchelper.h b/wing/wingsource.h
similarity index 64%
rename from wing/wingasynchelper.h
rename to wing/wingsource.h
index e6f1dba..5d8abe0 100644
--- a/wing/wingasynchelper.h
+++ b/wing/wingsource.h
@@ -15,21 +15,24 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef __WING_ASYNC_HELPER_H__
-#define __WING_ASYNC_HELPER_H__
+#ifndef __WING_SOURCE_H__
+#define __WING_SOURCE_H__
#include <gio/gio.h>
#include <windows.h>
+#include <wing/wingversionmacros.h>
G_BEGIN_DECLS
-typedef gboolean (* WingHandleSourceFunc) (HANDLE handle,
- gpointer user_data);
+typedef gboolean (* WingSourceFunc) (HANDLE handle,
+ gpointer user_data);
-GSource *_wing_handle_create_source (HANDLE handle,
- GCancellable *cancellable);
+WING_AVAILABLE_IN_ALL
+GSource *wing_create_source (HANDLE handle,
+ GIOCondition condition,
+ GCancellable *cancellable);
G_END_DECLS
-#endif /* __WING_ASYNC_HELPER_H__ */
+#endif /* __WING_SOURCE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]