Permalink
Browse files

2008-06-25 Aaron Bockover <abock@gnome.org>

    This commit integrates AvahiDBus provider into the build, cleans up the
    DBus iteration and starts to implement the DBus stuff; not working, and
    the avahi-sharp provider is disabled in the build for now. Do not use
    this revision.


svn path=/trunk/Mono.Zeroconf/; revision=106593
  • Loading branch information...
abock committed Jun 25, 2008
1 parent 6d968e2 commit 9252be99e89f432722169e195cc2cfd36bb1a78c
View
@@ -1,3 +1,10 @@
+2008-06-25 Aaron Bockover <abock@gnome.org>
+
+ This commit integrates AvahiDBus provider into the build, cleans up the
+ DBus iteration and starts to implement the DBus stuff; not working, and
+ the avahi-sharp provider is disabled in the build for now. Do not use
+ this revision.
+
2008-04-02 Aaron Bockover <abockover@novell.com>
* src/Mono.Zeroconf.Providers.Bonjour/Mono.Zeroconf.Providers.Bonjour/BrowseService.cs:
View
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Zeroconf", "src\Mono.Z
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Zeroconf.Providers.Bonjour", "src\Mono.Zeroconf.Providers.Bonjour\Mono.Zeroconf.Providers.Bonjour.csproj", "{623325E2-5821-4701-A40C-3759097008DD}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Zeroconf.Providers.AvahiDBus", "src\Mono.Zeroconf.Providers.AvahiDBus\Mono.Zeroconf.Providers.AvahiDBus.csproj", "{EF6ED6D1-D201-42ED-B680-5A77641BEB77}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -18,6 +20,13 @@ Global
{623325E2-5821-4701-A40C-3759097008DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{839D9048-31CF-4010-B427-6A8362556485}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{839D9048-31CF-4010-B427-6A8362556485}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EF6ED6D1-D201-42ED-B680-5A77641BEB77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EF6ED6D1-D201-42ED-B680-5A77641BEB77}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ name = Mono.Zeroconf
+ version = 0.1
+ StartupItem = src\MZClient\MZClient.csproj
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
@@ -77,6 +77,7 @@ src/Mono.Zeroconf/Makefile
src/Mono.Zeroconf.Providers.Bonjour/Makefile
src/Mono.Zeroconf.Providers.Bonjour/Mono.Zeroconf.Providers.Bonjour.dll.config
src/Mono.Zeroconf.Providers.Avahi/Makefile
+src/Mono.Zeroconf.Providers.AvahiDBus/Makefile
src/MZClient/Makefile
src/MZClient/mzclient
docs/Makefile
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -33,7 +33,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mono.Zeroconf\Mono.Zeroconf.csproj">
- <Project>{5CF88E3A-13DD-4114-BAD9-DA826946516F}</Project>
+ <Project>{839D9048-31CF-4010-B427-6A8362556485}</Project>
<Name>Mono.Zeroconf</Name>
</ProjectReference>
</ItemGroup>
View
@@ -1,7 +1,7 @@
SUBDIRS = \
Mono.Zeroconf \
Mono.Zeroconf.Providers.Bonjour \
- Mono.Zeroconf.Providers.Avahi \
+ Mono.Zeroconf.Providers.AvahiDBus \
MZClient
pkgconfigdir = $(libdir)/pkgconfig
@@ -0,0 +1,32 @@
+ASSEMBLY_NAME = Mono.Zeroconf.Providers.AvahiDBus
+ASSEMBLY = $(ASSEMBLY_NAME).dll
+
+MONO_ZEROCONF_PROVIDERS_AVAHI_SRC = \
+ Mono.Zeroconf.Providers.AvahiDBus/DBusManager.cs \
+ Mono.Zeroconf.Providers.AvahiDBus/IAvahiServer.cs \
+ Mono.Zeroconf.Providers.AvahiDBus/IAvahiServiceBrowser.cs \
+ Mono.Zeroconf.Providers.AvahiDBus/ServiceBrowser.cs \
+ Mono.Zeroconf.Providers.AvahiDBus/ZeroconfProvider.cs
+
+SOURCES = \
+ $(top_srcdir)/src/AssemblyInfo.cs \
+ $(foreach source,$(MONO_ZEROCONF_PROVIDERS_AVAHI_SRC),$(srcdir)/$(source))
+
+if BUILD_AVAHI
+
+assemblydir = $(libdir)/mono-zeroconf
+assembly_SCRIPTS = $(ASSEMBLY) $(ASSEMBLY).mdb
+
+all: $(ASSEMBLY)
+
+$(ASSEMBLY): $(top_builddir)/src/Mono.Zeroconf/Mono.Zeroconf.dll $(SOURCES)
+ $(MCS) -debug -target:library -out:$@ -r:$< $(AVAHI_LIBS) $(SOURCES) -pkg:ndesk-dbus-1.0 -pkg:ndesk-dbus-glib-1.0 -pkg:glib-sharp-2.0
+
+endif
+
+EXTRA_DIST = $(SOURCES)
+CLEANFILES = *.dll *.exe *.mdb
+DISTCLEANFILES = *.pidb
+MAINTAINERCLEANFILES = \
+ Makefile.in
+
@@ -1,138 +0,0 @@
-//
-// DBusManager.cs
-//
-// Authors:
-// Aaron Bockover <abockover@novell.com>
-//
-// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.IO;
-using System.Reflection;
-using System.Threading;
-
-using NDesk.DBus;
-
-namespace Mono.Zeroconf.Providers.Avahi
-{
- internal static class DBusManager
- {
- private const uint MINIMUM_AVAHI_API_VERSION = 515;
-
- private static object iterate_thread_mutex = new object();
- private static int iterate_freeze_count = 0;
- private static Thread iterate_thread;
-
- private static Bus bus;
-
- private static IAvahiServer server;
- public static IAvahiServer Server {
- get { return server; }
- }
-
- private static void InitializeSystemBusConnection()
- {
- string address = Environment.GetEnvironmentVariable("DBUS_SYSTEM_BUS_ADDRESS");
- if(String.IsNullOrEmpty(address)) {
- address = "unix:path=/var/run/dbus/system_bus_socket";
- }
-
- bus = Bus.Open(address);
- }
-
- public static void Initialize()
- {
- InitializeSystemBusConnection();
-
- if(!bus.NameHasOwner("org.freedesktop.Avahi")) {
- throw new ApplicationException("Could not find org.freedesktop.Avahi");
- }
-
- server = bus.GetObject<IAvahiServer>("org.freedesktop.Avahi", new ObjectPath("/"));
- uint api_version = server.GetAPIVersion();
-
- if(api_version < MINIMUM_AVAHI_API_VERSION) {
- throw new ApplicationException(String.Format("Avahi API version " +
- "{0} is required, but {1} is what the server returned.",
- MINIMUM_AVAHI_API_VERSION, api_version));
- }
-
- // If you remove this you will see that the events
- // come through -- it'll work for the first object,
- // but once the thread is created you are hosed.
- // Leaving this call here for testing/debugging
- // while the iterate issue is looked into. For
- // production, this call will be deferred until
- // it's necessary.
- EnsureIterate();
- }
-
- public static T GetObject<T>(string object_path)
- {
- return GetObject<T>(new ObjectPath(object_path));
- }
-
- public static T GetObject<T>(ObjectPath object_path)
- {
- return bus.GetObject<T>("org.freedesktop.Avahi", object_path);
- }
-
- public static void EnsureIterate()
- {
- lock(iterate_thread_mutex) {
- if(iterate_thread != null) {
- return;
- }
-
- iterate_thread = new Thread(Iterate);
- iterate_thread.IsBackground = true;
- iterate_thread.Start();
- }
- }
-
- private static void Iterate()
- {
- while(true) {
- if(iterate_freeze_count == 0) {
- Console.WriteLine("Start Iterate");
- bus.Iterate();
- Console.WriteLine("End Iterate");
- }
- }
- }
-
- public static void BusLock()
- {
- Interlocked.Increment(ref iterate_freeze_count);
- Console.WriteLine("Freeze: {0}", iterate_freeze_count);
- EnsureIterate();
- }
-
- public static void BusUnlock()
- {
- Interlocked.Decrement(ref iterate_freeze_count);
- Console.WriteLine("Unfreeze: {0}", iterate_freeze_count);
- EnsureIterate();
- }
- }
-}
@@ -0,0 +1,110 @@
+//
+// DBusManager.cs
+//
+// Authors:
+// Aaron Bockover <abockover@novell.com>
+//
+// Copyright (C) 2007-2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+using System.Reflection;
+using System.Threading;
+
+using NDesk.DBus;
+
+namespace Mono.Zeroconf.Providers.Avahi
+{
+ internal static class DBusManager
+ {
+ private const uint MINIMUM_AVAHI_API_VERSION = 515;
+
+ private static object thread_wait = new object ();
+ private static bool initialized;
+ private static Bus bus;
+
+ private static IAvahiServer server;
+ public static IAvahiServer Server {
+ get { return server; }
+ }
+
+ private static void ConnectToSystemBus ()
+ {
+ string address = Environment.GetEnvironmentVariable ("DBUS_SYSTEM_BUS_ADDRESS");
+ if (String.IsNullOrEmpty (address)) {
+ address = "unix:path=/var/run/dbus/system_bus_socket";
+ }
+
+ bus = Bus.Open (address);
+ }
+
+ private static void IterateThread (object o)
+ {
+ lock (thread_wait) {
+ ConnectToSystemBus ();
+ Monitor.Pulse (thread_wait);
+ }
+
+ while (true) {
+ bus.Iterate ();
+ }
+ }
+
+ public static void Initialize ()
+ {
+ if (initialized) {
+ return;
+ }
+
+ initialized = true;
+
+ lock (thread_wait) {
+ ThreadPool.QueueUserWorkItem (IterateThread);
+ Monitor.Wait (thread_wait);
+ }
+
+ if (!bus.NameHasOwner("org.freedesktop.Avahi")) {
+ throw new ApplicationException ("Could not find org.freedesktop.Avahi");
+ }
+
+ server = GetObject<IAvahiServer> ("/");
+ uint api_version = server.GetAPIVersion ();
+
+ if (api_version < MINIMUM_AVAHI_API_VERSION) {
+ throw new ApplicationException (String.Format ("Avahi API version " +
+ "{0} is required, but {1} is what the server returned.",
+ MINIMUM_AVAHI_API_VERSION, api_version));
+ }
+ }
+
+ public static T GetObject<T> (string objectPath)
+ {
+ return GetObject<T> (new ObjectPath (objectPath));
+ }
+
+ public static T GetObject<T> (ObjectPath objectPath)
+ {
+ return bus.GetObject<T> ("org.freedesktop.Avahi", objectPath);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 9252be9

Please sign in to comment.