[gupnp/wip/win32: 5/5] Add windows-specific context manager
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp/wip/win32: 5/5] Add windows-specific context manager
- Date: Fri, 26 Oct 2012 19:58:18 +0000 (UTC)
commit 637db85931643e48104ab22c14ea6d053ffb4a5e
Author: Jens Georg <mail jensge org>
Date: Thu Aug 19 23:14:04 2010 +0300
Add windows-specific context manager
configure.ac | 1 +
libgupnp/Makefile.am | 8 ++-
libgupnp/gupnp-context-manager.c | 3 +
libgupnp/gupnp-windows-context-manager.c | 104 ++++++++++++++++++++++++++++++
libgupnp/gupnp-windows-context-manager.h | 73 +++++++++++++++++++++
5 files changed, 188 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 1d0c8ff..0fd0b4d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -66,6 +66,7 @@ if test "x$os_win32" = "xno"; then
[with_context_manager="none"])
else
LIBGUPNP_LIBS="$LIBGUPNP_LIBS -lrpcrt4"
+ with_context_manager="windows"
fi
if test "x$with_context_manager" = "xnone"; then
diff --git a/libgupnp/Makefile.am b/libgupnp/Makefile.am
index 8b98525..24898c0 100644
--- a/libgupnp/Makefile.am
+++ b/libgupnp/Makefile.am
@@ -1,6 +1,10 @@
LTVERSION = 4:0:0
if OS_WIN32
+CONTEXT_MANAGER_IMPL = gupnp-windows-context-manager.c \
+ gupnp-windows-context-manager.h
+CONTEXT_MANAGER_CFLAGS =
+CONTEXT_MANAGER_LIBS = -lws2_32 -liphlpapi
WIN32_LDFLAGS = -no-undefined
else
CONTEXT_MANAGER_IMPL = gupnp-unix-context-manager.c \
@@ -113,7 +117,9 @@ EXTRA_DIST = gupnp-marshal.list \
gupnp-linux-context-manager.c \
gupnp-linux-context-manager.h \
gupnp-unix-context-manager.c \
- gupnp-unix-context-manager.h
+ gupnp-unix-context-manager.h \
+ gupnp-windows-context-manager.c \
+ gupnp-windows-context-manager.h
-include $(INTROSPECTION_MAKEFILE)
INTROSPECTION_GIRS =
diff --git a/libgupnp/gupnp-context-manager.c b/libgupnp/gupnp-context-manager.c
index 724b94f..45f6252 100644
--- a/libgupnp/gupnp-context-manager.c
+++ b/libgupnp/gupnp-context-manager.c
@@ -338,6 +338,9 @@ gupnp_context_manager_create (guint port)
GUPnPContextManager *impl;
GType impl_type = G_TYPE_INVALID;
#ifdef G_OS_WIN32
+#include "gupnp-windows-context-manager.h"
+
+ impl_type = GUPNP_TYPE_WINDOWS_CONTEXT_MANAGER;
#else
#ifdef USE_NETWORK_MANAGER
#include "gupnp-network-manager.h"
diff --git a/libgupnp/gupnp-windows-context-manager.c b/libgupnp/gupnp-windows-context-manager.c
new file mode 100644
index 0000000..c888507
--- /dev/null
+++ b/libgupnp/gupnp-windows-context-manager.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2009, 2010 Jens Georg
+ * Copyright (C) 2009 Nokia Corporation.
+ * Copyright (C) 2006, 2007, 2008 OpenedHand Ltd.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ * Jorn Baayen <jorn openedhand com>
+ * Jens Georg <mail jensge org>
+ *
+ * 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.
+ */
+
+/**
+ * SECTION:gupnp-windows-context-manager
+ * @short_description: Windows-specific implementation of #GUPnPContextManager.
+ */
+
+#include <config.h>
+#include <string.h>
+#define _WIN32_WINNT 0x0502
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <iphlpapi.h>
+
+#include "gupnp-windows-context-manager.h"
+#include "gupnp-context.h"
+
+G_DEFINE_TYPE (GUPnPWindowsContextManager,
+ gupnp_windows_context_manager,
+ GUPNP_TYPE_SIMPLE_CONTEXT_MANAGER);
+
+/*
+ * Create a context for all network interfaces that are up.
+ */
+static GList *
+gupnp_windows_context_manager_get_interfaces
+ (GUPnPSimpleContextManager *manager)
+{
+ GList *interfaces = NULL;
+ ULONG flags = GAA_FLAG_INCLUDE_PREFIX |
+ GAA_FLAG_SKIP_DNS_SERVER |
+ GAA_FLAG_SKIP_MULTICAST;
+ /* use 15k buffer initially as documented in MSDN */
+ DWORD size = 0x3C00;
+ DWORD ret;
+ PIP_ADAPTER_ADDRESSES adapters_addresses;
+ PIP_ADAPTER_ADDRESSES adapter;
+
+ do {
+ adapters_addresses = (PIP_ADAPTER_ADDRESSES) g_malloc0 (size);
+ ret = GetAdaptersAddresses (AF_UNSPEC,
+ flags,
+ NULL,
+ adapters_addresses,
+ &size);
+ if (ret == ERROR_BUFFER_OVERFLOW) {
+ g_free (adapters_addresses);
+ }
+ } while (ret == ERROR_BUFFER_OVERFLOW);
+
+ if (ret != ERROR_SUCCESS)
+ return NULL;
+
+ for (adapter = adapters_addresses;
+ adapter != NULL;
+ adapter = adapter->Next) {
+ if (adapter->FirstUnicastAddress == NULL)
+ continue;
+ if (adapter->OperStatus != IfOperStatusUp)
+ continue;
+ interfaces = g_list_append (interfaces,
+ g_strdup (adapter->AdapterName));
+ }
+
+ return interfaces;
+}
+
+static void
+gupnp_windows_context_manager_init (GUPnPWindowsContextManager *manager)
+{
+}
+
+static void
+gupnp_windows_context_manager_class_init (GUPnPWindowsContextManagerClass *klass)
+{
+ GUPnPSimpleContextManagerClass *parent_class;
+
+ parent_class = GUPNP_SIMPLE_CONTEXT_MANAGER_CLASS (klass);
+ parent_class->get_interfaces =
+ gupnp_windows_context_manager_get_interfaces;
+}
diff --git a/libgupnp/gupnp-windows-context-manager.h b/libgupnp/gupnp-windows-context-manager.h
new file mode 100644
index 0000000..2387d12
--- /dev/null
+++ b/libgupnp/gupnp-windows-context-manager.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009, 2010 Jens Georg
+ * Copyright (C) 2009 Nokia Corporation.
+ * Copyright (C) 2006, 2007, 2008 OpenedHand Ltd.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ * Jorn Baayen <jorn openedhand com>
+ * Jens Georg <mail jensge org>
+ *
+ * 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 __GUPNP_WINDOWS_CONTEXT_MANAGER_H__
+#define __GUPNP_WINDOWS_CONTEXT_MANAGER_H__
+
+#include "gupnp-simple-context-manager.h"
+
+G_BEGIN_DECLS
+
+GType
+gupnp_windows_context_manager_get_type (void) G_GNUC_CONST;
+
+#define GUPNP_TYPE_WINDOWS_CONTEXT_MANAGER \
+ (gupnp_windows_context_manager_get_type ())
+#define GUPNP_WINDOWS_CONTEXT_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ GUPNP_TYPE_WINDOWS_CONTEXT_MANAGER, \
+ GUPnPWindowsContextManager))
+#define GUPNP_WINDOWS_CONTEXT_MANAGER_CLASS(obj) \
+ (G_TYPE_CHECK_CLASS_CAST ((obj), \
+ GUPNP_TYPE_WINDOWS_CONTEXT_MANAGER, \
+ GUPnPWindowsContextManagerClass))
+#define GUPNP_IS_WINDOWS_CONTEXT_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ GUPNP_TYPE_WINDOWS_CONTEXT_MANAGER))
+#define GUPNP_IS_WINDOWS_CONTEXT_MANAGER_CLASS(obj) \
+ (G_TYPE_CHECK_CLASS_TYPE ((obj), \
+ GUPNP_TYPE_WINDOWS_CONTEXT_MANAGER))
+#define GUPNP_WINDOWS_CONTEXT_MANAGER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ GUPNP_TYPE_WINDOWS_CONTEXT_MANAGER, \
+ GUPnPWindowsContextManagerClass))
+
+typedef struct {
+ GUPnPSimpleContextManager parent;
+} GUPnPWindowsContextManager;
+
+typedef struct {
+ GUPnPSimpleContextManagerClass parent_class;
+
+ /* future padding */
+ void (* _gupnp_reserved1) (void);
+ void (* _gupnp_reserved2) (void);
+ void (* _gupnp_reserved3) (void);
+ void (* _gupnp_reserved4) (void);
+} GUPnPWindowsContextManagerClass;
+
+G_END_DECLS
+
+#endif /* __GUPNP_WINDOWS_CONTEXT_MANAGER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]