Search code examples
windowsdbus

Specify dbus session address on windows


The default session.conf for DBus on Windows (https://code.google.com/p/dbus-windows-installer/downloads/list) uses <listen>autolaunch:scope=install-path</listen> which, as the name implies, uses the current path of the dbus-daemon executable to somehow determine the session address.

Is there a way to specify an explicit path instead? perhaps something with tcp:?


Solution

  • After many attempts, I have found the solution. Even though the 1.4.3 version of DBus for Windows that is (at least for now) available at https://code.google.com/p/dbus-windows-installer/downloads/list is quite old, it does in fact support tcp: syntax.

    Installing DBus-Windows-Installer-1.4.1-2.exe does two things:

    1. It delivers the DBus libraries and default configuration in C:\Program Files (x86)\DBus
    2. It adds C:\Program Files (x86)\DBus\bin to the %PATH%

    Having the latter is necessary so that your application can access DBus DLLs and EXEs at runtime. To make this installation use the tcp: syntax, you have to

    1. Edit C:\Program Files (x86)\DBus\etc\session.conf to <listen>tcp:host=localhost,port=54321,family=ipv4</listen>
    2. Edit C:\Program Files (x86)\DBus\bin\dbus-env.bat to set DBUS_SESSION_BUS_ADDRESS=tcp:host=localhost,port=54321,family=ipv4
    3. Launch the session daemon from an environment that first executes dbus-env.bat and then run dbus-daemon.exe --session
    4. (Optional) Launch the session monitor from an environment that first executes dbus-env.bat and then run dbus-monitor.exe --session
    5. Launch your application from an environment that first executes dbus-env.bat and then actually runs your application

    As I said above, DBus 1.4.3 is quite old. In fact, according to https://code.google.com/p/support/wiki/ReadOnlyTransition it might not even be available for download soon. At the time of this writing, the latest stable branch is 1.10. So, here are the instructions for building your own latest DBus

    1. Install Visual Studio
      • Any version 2010 and later should suffice, including the free Express versions
    2. Install CMake

    3. Get libexpat

    4. Get the DBus source
      • git clone git://anongit.freedesktop.org/git/dbus/dbus
      • cd dbus
        • Let's call this ${dbusSrcDir}
      • git checkout dbus-1.10
        • this is the current stable branch
    5. Start Developer Command Prompt for VS2015
      • cd ${dbusSrcDir}
      • cd ..
      • mkdir dbus-build
      • cd dbus-build
      • "c:\Program Files (x86)\CMake\bin\cmake.exe" -G "NMake Makefiles" -DCMAKE_INCLUDE_PATH:PATH="${expatDir}\Source\lib" -DCMAKE_LIBRARY_PATH:PATH="${expatDir}\Bin" -DDBUS_BUILD_TESTS:BOOL=OFF -DDBUS_DISABLE_ASSERT:BOOL=ON -DDBUS_USE_OUTPUT_DEBUG_STRING:BOOL=ON -DDBUS_ENABLE_DOXYGEN_DOCS:BOOL=OFF ..\dbus\cmake
      • nmake
    6. At this point, you can either do nmake install to install to C:\Program Files (x86)\DBus or you can make a distributable "deploy package" by
      • mkdir c:\temp\dbus-deploy
      • mkdir c:\temp\dbus-deploy\bin
      • mkdir c:\temp\dbus-deploy\share
      • mkdir c:\temp\dbus-deploy\share\dbus-1
      • copy bin\dbus-1-3.dll c:\temp\dbus-deploy\bin
      • copy bin\dbus-daemon.exe c:\temp\dbus-deploy\bin
      • copy bin\dbus-env.bat c:\temp\dbus-deploy\bin
      • copy bin\dbus-launch.exe c:\temp\dbus-deploy\bin
      • copy bin\dbus-monitor.exe c:\temp\dbus-deploy\bin
      • copy bin\dbus-send.exe c:\temp\dbus-deploy\bin
      • copy ${expatDir}\Bin\libexpat.dll c:\temp\dbus-deploy\bin
      • Create a c:\temp\dbus-deploy\share\dbus-1\session.conf with the usual contents which includes <listen>tcp:host=localhost,port=54321,family=ipv4</listen>
      • Edit c:\temp\dbus-deploy\bin\dbus-env.bat to set DBUS_SESSION_BUS_ADDRESS=tcp:host=localhost,port=54321,family=ipv4
    7. To use "the deploy package" in your application, modify %PATH% to point to your "deploy package" bin directory and make sure to source dbus-env.bat before doing anything.