### Install Example Scripts Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Installs the specified example scripts to the documentation directory. ```cmake install(FILES ${EXAMPLES_SCRIPTS} DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/dbus/examples) ``` -------------------------------- ### Define Example Scripts Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Lists the example scripts to be installed. ```cmake set(EXAMPLES_SCRIPTS GetAllMatchRules.py ) ``` -------------------------------- ### Basic KApplication Setup Source: https://github.com/dbus/dbus/blob/main/doc/dcop-howto.txt Minimal boilerplate for a KDE application used for performance testing. ```cpp #include int main(int argc, char **argv) { KApplication *app; app = new KApplication(argc, argv, "testit"); return app->exec(); } ``` -------------------------------- ### Install DBus Library and Headers Source: https://github.com/dbus/dbus/blob/main/dbus/CMakeLists.txt Installs the 'dbus-1' target, along with its public and architecture-specific headers, to the appropriate installation directories. ```cmake install(TARGETS dbus-1 ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${dbusinclude_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dbus-1.0/dbus) install(FILES ${dbusinclude_ARCH_HEADERS} DESTINATION ${CMAKE_INSTALL_LIBDIR}/dbus-1.0/include/dbus) ``` -------------------------------- ### Create dbus-launch Executable Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Creates the dbus-launch executable, links it with DBUS_LIBRARIES and optionally X11_LIBRARIES, and installs it by default. ```cmake add_executable(dbus-launch ${dbus_launch_SOURCES}) target_link_libraries(dbus-launch ${DBUS_LIBRARIES}) if(DBUS_BUILD_X11) target_link_libraries(dbus-launch ${X11_LIBRARIES} ) endif() install(TARGETS dbus-launch ${INSTALL_TARGETS_DEFAULT_ARGS}) ``` -------------------------------- ### Enable DBus service installer (Windows) Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Configures an option for enabling the DBus service installer on Windows. Defaults to OFF. This support is not complete. ```cmake if(WIN32) # win32 dbus service support - this support is not complete option(DBUS_SERVICE "enable dbus service installer" OFF) endif() ``` -------------------------------- ### Launch Service by Calling a Method Source: https://github.com/dbus/dbus/blob/main/doc/system-activation.txt Example of launching a service and executing a method on it using `dbus-send`. The service activation is transparent to the caller. ```bash dbus-send --system --print-reply\ --dest=org.freedesktop.Hal\ /org/freedesktop/Hal/Manager\ org.freedesktop.Hal.Manager.DeviceExists\ string:/org/freedesktop/Hal/devices/computer ``` -------------------------------- ### Create dbus-monitor Executable Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Creates the dbus-monitor executable and links it with DBUS_LIBRARIES. It is also installed by default. ```cmake add_executable(dbus-monitor ${dbus_monitor_SOURCES}) target_link_libraries(dbus-monitor ${DBUS_LIBRARIES}) install(TARGETS dbus-monitor ${INSTALL_TARGETS_DEFAULT_ARGS}) ``` -------------------------------- ### Create dbus-update-activation-environment Executable Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Creates the dbus-update-activation-environment executable and links it with DBUS_LIBRARIES. It is also installed by default. ```cmake add_executable(dbus-update-activation-environment ${dbus_update_activation_environment_SOURCES}) target_link_libraries(dbus-update-activation-environment ${DBUS_LIBRARIES}) install(TARGETS dbus-update-activation-environment ${INSTALL_TARGETS_DEFAULT_ARGS}) ``` -------------------------------- ### Example D-BUS Service File Source: https://github.com/dbus/dbus/blob/main/doc/system-activation.txt A typical service file for D-BUS activation. It specifies the service name, the executable path, and the user to run the service as. ```ini [D-BUS Service] Name=org.me.test Exec=/usr/sbin/dbus-test-server.py User=ftp ``` -------------------------------- ### Install Directory for dbus-uuidgen Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Installs the /var/lib/dbus directory, which is used by dbus-uuidgen. ```cmake install(DIRECTORY DESTINATION ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/dbus) ``` -------------------------------- ### Create dbus-test-tool Executable Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Creates the dbus-test-tool executable and links it with DBUS_LIBRARIES. It is also installed by default. ```cmake add_executable(dbus-test-tool ${dbus_test_tool_SOURCES}) target_link_libraries(dbus-test-tool ${DBUS_LIBRARIES}) install(TARGETS dbus-test-tool ${INSTALL_TARGETS_DEFAULT_ARGS}) ``` -------------------------------- ### Activate Service Without Calling a Method Source: https://github.com/dbus/dbus/blob/main/doc/system-activation.txt Example of activating a service using the `StartServiceByName` D-BUS method without calling a specific method on the service. ```bash dbus-send --system --print-reply\ --dest=org.freedesktop.DBus\ /org/freedesktop/DBus\ org.freedesktop.DBus.StartServiceByName\ string:org.freedesktop.Hal uint32:0 ``` -------------------------------- ### Create dbus-send Executable Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Creates the dbus-send executable and links it with DBUS_LIBRARIES. It is also installed by default. ```cmake add_executable(dbus-send ${dbus_send_SOURCES}) target_link_libraries(dbus-send ${DBUS_LIBRARIES}) install(TARGETS dbus-send ${INSTALL_TARGETS_DEFAULT_ARGS}) ``` -------------------------------- ### Create dbus-run-session Executable Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Creates the dbus-run-session executable and links it with DBUS_INTERNAL_LIBRARIES. It is also installed by default. ```cmake add_executable(dbus-run-session ${dbus_run_session_SOURCES}) target_link_libraries(dbus-run-session ${DBUS_INTERNAL_LIBRARIES}) install(TARGETS dbus-run-session ${INSTALL_TARGETS_DEFAULT_ARGS}) ``` -------------------------------- ### Create dbus-cleanup-sockets Executable (Non-Windows) Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Creates the dbus-cleanup-sockets executable and links it with DBUS_LIBRARIES, intended for non-Windows systems. It is also installed by default. ```cmake if(NOT WIN32) add_executable(dbus-cleanup-sockets ${dbus_cleanup_sockets_SOURCES}) target_link_libraries(dbus-cleanup-sockets ${DBUS_LIBRARIES}) install(TARGETS dbus-cleanup-sockets ${INSTALL_TARGETS_DEFAULT_ARGS}) endif() ``` -------------------------------- ### Execute Inter-user DCOP Command Source: https://github.com/dbus/dbus/blob/main/doc/dcop-howto.txt Example command to run a process as root while connecting to a user's DCOP server. ```bash ICEAUTHORITY=~user/.ICEauthority kdesu root -c kcmroot -dcopserver `cat ~user/.DCOPserver` ``` -------------------------------- ### Define DCOP Interface Header Source: https://github.com/dbus/dbus/blob/main/doc/dcop-howto.txt Example of a header file structure for use with the dcopidl compiler. ```cpp #ifndef MY_INTERFACE_H #define MY_INTERFACE_H ``` -------------------------------- ### Configure HTML Index File Source: https://github.com/dbus/dbus/blob/main/doc/CMakeLists.txt This snippet configures an index.html file from a template, potentially including a link to API documentation if Doxygen docs are enabled. The generated file is installed. ```cmake if(DBUS_ENABLE_DOXYGEN_DOCS) set(DBUS_APIDOC_LINK "libdbus API Documentation") else() set(DBUS_APIDOC_LINK "") endif() configure_file(index.html.in ${CMAKE_CURRENT_BINARY_DIR}/index.html) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/index.html DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/dbus) ``` -------------------------------- ### Create dbus-uuidgen Executable (Non-Windows) Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Creates the dbus-uuidgen executable and links it with DBUS_LIBRARIES, intended for non-Windows systems. It is also installed by default. ```cmake if(NOT WIN32) add_executable(dbus-uuidgen ${dbus_uuidgen_SOURCES}) target_link_libraries(dbus-uuidgen ${DBUS_LIBRARIES}) install(TARGETS dbus-uuidgen ${INSTALL_TARGETS_DEFAULT_ARGS}) endif() ``` -------------------------------- ### Enable X11 autolaunch support Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Configures an option to build with X11 autolaunch support if X11 is found. Defaults to ON. ```cmake if(X11_FOUND) option(DBUS_BUILD_X11 "Build with X11 autolaunch support " ON) endif() ``` -------------------------------- ### Upload documentation Source: https://github.com/dbus/dbus/blob/main/maint/release-checklist.md Updates the online documentation using the build directory. ```bash ninja -C ${builddir} maintainer-upload-docs ``` -------------------------------- ### Create and Manage a D-Bus Server in C Source: https://context7.com/dbus/dbus/llms.txt Initializes a server on a Unix socket, registers a connection callback, and processes messages in a loop. ```c #include #include #include static DBusConnection *client_conn = NULL; /* Called when client sends a message */ DBusHandlerResult message_handler(DBusConnection *conn, DBusMessage *msg, void *user_data) { printf("Received message: interface=%s, member=%s\n", dbus_message_get_interface(msg), dbus_message_get_member(msg)); /* Handle method calls */ if (dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_CALL) { if (dbus_message_is_method_call(msg, "org.example.Server", "Echo")) { DBusMessage *reply; DBusMessageIter iter; const char *input = NULL; /* Get input argument */ if (dbus_message_iter_init(msg, &iter) && dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) { dbus_message_iter_get_basic(&iter, &input); } /* Create reply */ reply = dbus_message_new_method_return(msg); if (reply) { char response[256]; snprintf(response, sizeof(response), "Echo: %s", input ? input : ""); const char *resp_ptr = response; dbus_message_append_args(reply, DBUS_TYPE_STRING, &resp_ptr, DBUS_TYPE_INVALID); dbus_connection_send(conn, reply, NULL); dbus_message_unref(reply); } return DBUS_HANDLER_RESULT_HANDLED; } } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Called when a new client connects */ void new_connection_callback(DBusServer *server, DBusConnection *new_conn, void *data) { printf("New client connected!\n"); /* Reference and store the connection */ dbus_connection_ref(new_conn); client_conn = new_conn; /* Set up message handling */ dbus_connection_add_filter(new_conn, message_handler, NULL, NULL); /* Allow anonymous connections */ dbus_connection_set_allow_anonymous(new_conn, TRUE); } int main(void) { DBusError error; DBusServer *server; char *address; dbus_error_init(&error); /* Create server listening on a Unix socket */ server = dbus_server_listen("unix:path=/tmp/dbus-example-server", &error); if (dbus_error_is_set(&error)) { fprintf(stderr, "Server creation failed: %s\n", error.message); dbus_error_free(&error); return 1; } if (server == NULL) { fprintf(stderr, "Server is NULL\n"); return 1; } /* Get the actual address the server is listening on */ address = dbus_server_get_address(server); printf("Server listening on: %s\n", address); dbus_free(address); /* Set callback for new connections */ dbus_server_set_new_connection_function(server, new_connection_callback, NULL, NULL); printf("Server running... (Ctrl+C to exit)\n"); /* Simple event loop */ while (dbus_server_get_is_connected(server)) { /* Process client connection if we have one */ if (client_conn && dbus_connection_get_is_connected(client_conn)) { dbus_connection_read_write_dispatch(client_conn, 100); } else { usleep(100000); /* 100ms */ } } /* Cleanup */ if (client_conn) { dbus_connection_unref(client_conn); } dbus_server_disconnect(server); dbus_server_unref(server); return 0; } ``` -------------------------------- ### Configure D-Bus Test Utilities Build Source: https://github.com/dbus/dbus/blob/main/test/CMakeLists.txt Sets up the static library for test utilities and defines source files for various test executables. ```cmake add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS}) include_directories(.) set(DBUS_SESSION_BUS_LISTEN_ADDRESS ${TEST_LISTEN}) add_library(dbus-testutils STATIC disable-crash-handling.c disable-crash-handling.h test-utils.h test-utils.c ) target_link_libraries(dbus-testutils ${DBUS_INTERNAL_LIBRARIES}) if(DBUS_ENABLE_INTRUSIVE_TESTS) add_subdirectory( name-test ) endif() set(manual-dir-iter_SOURCES manual-dir-iter.c ) set(test-service_SOURCES test-service.c ) set(test-names_SOURCES test-names.c ) set(break_loader_SOURCES break-loader.c ) set(test-shell-service_SOURCES test-shell-service.c ) set(test-shell_SOURCES shell-test.c ) set(test-atomic_SOURCES internals/atomic.c ) set(test-spawn_SOURCES spawn-test.c ) set(test-exit_SOURCES test-exit.c ) # We have to compile a separate copy of disable-crash-handling.c for # test-segfault rather than using the libdbus-testutils library, because # otherwise it would fail to link when using the AddressSanitizer. set(test-segfault_SOURCES disable-crash-handling.c disable-crash-handling.h test-segfault.c ) set(test-sleep-forever_SOURCES test-sleep-forever.c ) set(manual-tcp_SOURCES manual-tcp.c ) set(manual-paths_SOURCES manual-paths.c ) add_helper_executable(manual-dir-iter ${manual-dir-iter_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) add_helper_executable(test-service ${test-service_SOURCES} dbus-testutils) add_helper_executable(test-names ${test-names_SOURCES} dbus-testutils) add_test_executable(test-shell ${test-shell_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) add_test_executable(test-string internals/strings.c dbus-testutils) add_test_executable(test-printf internals/printf.c dbus-testutils) add_helper_executable(test-privserver test-privserver.c dbus-testutils) add_helper_executable(test-shell-service ${test-shell-service_SOURCES} dbus-testutils) if(NOT WINCE AND ENABLE_TRADITIONAL_ACTIVATION) add_test_executable(test-spawn-oom internals/spawn-oom.c dbus-testutils) endif() if(ENABLE_TRADITIONAL_ACTIVATION) add_helper_executable(test-spawn ${test-spawn_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) endif() add_helper_executable(test-exit ${test-exit_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) # the second argument of add_helper_executable() is a whitespace-separated # list of source files and the third and subsequent arguments are libraries ``` -------------------------------- ### Enable kqueue support (BSD) Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Builds with kqueue support for BSD systems. Requires sys/event.h. Defaults to ON. ```cmake elseif("${CMAKE_SYSTEM_NAME}" MATCHES ".*BSD") option(DBUS_BUS_ENABLE_KQUEUE "build with kqueue support (FreeBSD only)" ON) if(DBUS_BUS_ENABLE_KQUEUE) if(NOT HAVE_SYS_EVENT_H) message(FATAL_ERROR "sys/event.h not found!") endif() endif() endif() ``` -------------------------------- ### dbus_message_new_method_call Source: https://context7.com/dbus/dbus/llms.txt Creates a new D-Bus message to invoke a method on a remote object. Includes an example of appending arguments and handling the reply. ```APIDOC ## POST /api/method_call ### Description Creates a new D-Bus message to invoke a method on a remote object. ### Method POST ### Endpoint /api/method_call ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **bus_name** (string) - Required - The D-Bus bus name of the destination service. - **object_path** (string) - Required - The object path on the destination service. - **interface** (string) - Required - The interface containing the method. - **method_name** (string) - Required - The name of the method to call. - **arguments** (array) - Optional - An array of arguments to pass to the method. ### Request Example ```json { "bus_name": "org.example.Service", "object_path": "/org/example/Object", "interface": "org.example.Interface", "method_name": "Echo", "arguments": [{"type": "string", "value": "Hello, D-Bus!"}] } ``` ### Response #### Success Response (200) - **reply** (string) - The reply from the method call. #### Response Example ```json { "reply": "Hello, D-Bus!" } ``` ``` -------------------------------- ### Compile Performance Test Source: https://github.com/dbus/dbus/blob/main/doc/dcop-howto.txt Command to compile the test application with KDE and Qt libraries. ```bash g++ -O2 -o testit testit.cpp -I$QTDIR/include -L$QTDIR/lib -lkdecore ``` -------------------------------- ### Define Build Output Directories Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Configures output paths for binaries, libraries, and archives based on the operating system. ```cmake set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) if(WIN32 OR CYGWIN) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) else() set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) endif() set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) # for including config.h and for includes like include_directories(. ${PROJECT_BINARY_DIR} ${CMAKE_INCLUDE_PATH}) ``` -------------------------------- ### Generate Configuration Files Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Generates the config.h file and platform-specific environment scripts. ```cmake configure_file(cmake/config.h.cmake ${PROJECT_BINARY_DIR}/config.h) if(WIN32) configure_file(cmake/dbus-env.bat.cmake ${PROJECT_BINARY_DIR}/bin/dbus-env.bat) install(FILES ${PROJECT_BINARY_DIR}/bin/dbus-env.bat DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() ``` -------------------------------- ### Configure Platform-Specific Bus Settings Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Sets bus addresses, configuration files, and user credentials based on the target operating system. ```cmake if(WIN32) set(DBUS_SESSION_BUS_LISTEN_ADDRESS "autolaunch:" CACHE STRING "session bus default listening address") set(DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients") set(DBUS_SYSTEM_CONFIG_FILE "share/dbus-1/system.conf") set(DBUS_SESSION_CONFIG_FILE "share/dbus-1/session.conf") # bus-test expects a non empty string set(DBUS_USER "Administrator") set(DBUS_TEST_USER "guest") set(DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "") else(WIN32) set(DBUS_SESSION_BUS_LISTEN_ADDRESS "unix:tmpdir=${DBUS_SESSION_SOCKET_DIR}" CACHE STRING "session bus default listening address") set(DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients") set(DBUS_SYSTEM_CONFIG_FILE ${DBUS_DATADIR}/dbus-1/system.conf) set(DBUS_SESSION_CONFIG_FILE ${DBUS_DATADIR}/dbus-1/session.conf) set(DBUS_USER "messagebus") set(DBUS_TEST_USER "nobody") # For best security, assume that all non-Windows platforms can do # credentials-passing. set(DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "EXTERNAL") endif() ``` -------------------------------- ### Visual Studio build configuration messages Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Provides specific build configuration messages for Visual Studio, guiding users on test program execution based on the build type (Debug/Release). ```cmake if(MSVC_IDE) if(CMAKE_BUILD_TYPE MATCHES Debug) set(IDE_BIN /Debug ) message(STATUS) message(STATUS "Visual Studio: test programs will only work with 'Debug' configuration!") message(STATUS "To run tests with 'Release' configuration use -DCMAKE_BUILD_TYPE=Release") message(STATUS "Add '..\\..\\test\\data' to the command line option of the test programs") message(STATUS) else(CMAKE_BUILD_TYPE MATCHES Debug) set(IDE_BIN /Release) message(STATUS) message(STATUS "Visual Studio: test programs will only work with 'Release' configuration!") message(STATUS "To run tests with 'Debug' configuration use -DCMAKE_BUILD_TYPE=Debug") message(STATUS "Add '..\\..\\test\\data' to the command line option of the test programs") message(STATUS) endif() set(TEST_PATH_FORCE FORCE) file(REMOVE ${PROJECT_BINARY_DIR}/data/dbus-1/services) endif() ``` -------------------------------- ### Find System Libraries Source: https://github.com/dbus/dbus/blob/main/dbus/CMakeLists.txt Locates necessary system libraries such as 'rt' for clock functions on Linux and 'socket' for socket functions on QNX. ```cmake # for clock_getres() on e.g. GNU/Linux (but not Android) find_library(LIBRT rt) # for socket() on QNX find_library(LIBSOCKET socket) ``` -------------------------------- ### Add Privserver and Thread Init Tests with Traditional Activation Source: https://github.com/dbus/dbus/blob/main/test/name-test/CMakeLists.txt Conditionally defines test executables for the private server client and thread initialization when traditional activation is enabled. These link against DBus test utilities and internal libraries respectively. ```cmake add_session_test_executable(test-privserver-client test-privserver-client.c dbus-testutils) ``` ```cmake add_session_test_executable(test-thread-init test-threads-init.c ${DBUS_INTERNAL_LIBRARIES}) ``` -------------------------------- ### Set linker and include directories Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Configures directories for linking libraries and including header files. Uses CMake variables for dynamic path resolution. ```cmake link_directories(${DBUS_LIB_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ) include_directories( ${CMAKE_LIBRARY_PATH} ) ``` -------------------------------- ### Main Function with Custom Error Test Source: https://context7.com/dbus/dbus/llms.txt The main function initializes a DBusError using the static initializer and demonstrates setting and checking a custom error before calling the main error handling demonstration function. ```c int main(void) { DBusError error = DBUS_ERROR_INIT; /* Test custom error */ set_custom_error(&error, "invalid configuration"); if (dbus_error_is_set(&error)) { printf("Custom error: %s - %s\n", error.name, error.message); dbus_error_free(&error); } demonstrate_error_handling(); return 0; } ``` -------------------------------- ### Set dbus-update-activation-environment Source Files Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Specifies the source files for the dbus-update-activation-environment executable. ```cmake set(dbus_update_activation_environment_SOURCES dbus-update-activation-environment.c tool-common.c tool-common.h ) ``` -------------------------------- ### Enable inotify support (Linux) Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Builds with inotify support for Linux systems. Requires sys/inotify.h. Defaults to ON. ```cmake if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") option(DBUS_BUS_ENABLE_INOTIFY "build with inotify support (linux only)" ON) if(DBUS_BUS_ENABLE_INOTIFY) if(NOT HAVE_SYS_INOTIFY_H) message(FATAL_ERROR "sys/inotify.h not found!") endif() endif() endif() ``` -------------------------------- ### Enable Testing Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Enables the testing framework for the project. ```cmake enable_testing() ``` -------------------------------- ### Manage stable branches Source: https://github.com/dbus/dbus/blob/main/maint/release-checklist.md Commands for creating, pushing, and checking out stable release branches. ```bash git branch dbus-X.Y ``` ```bash git push origin dbus-X.Y ``` ```bash git checkout dbus-X.Y ``` -------------------------------- ### Configure Windows CE Build Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Checks for Windows CE platform and displays build information. ```cmake if(WINCE) message("Building for WinCE (${CMAKE_SYSTEM_VERSION})") endif() ``` -------------------------------- ### Interface Definitions and Compile Options Source: https://github.com/dbus/dbus/blob/main/dbus/CMakeLists.txt Sets interface include directories and compile definitions for the 'dbus-1' target, making them available to consumers. ```cmake # target definitions passed to the clients target_include_directories(dbus-1 INTERFACE $;$) target_compile_definitions(dbus-1 INTERFACE "") ``` -------------------------------- ### Add X11 Support to dbus-launch Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Conditionally adds dbus-launch-x11.c to the source files and includes X11 directories if DBUS_BUILD_X11 is enabled. ```cmake if(DBUS_BUILD_X11) set(dbus_launch_SOURCES ${dbus_launch_SOURCES} dbus-launch-x11.c ) include_directories(${X11_INCLUDE_DIR}) endif() ``` -------------------------------- ### Add Version Info for dbus-launch (Windows) Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Adds version information to the dbus-launch executable specifically for Windows builds. ```cmake if(WIN32) add_executable_version_info(dbus_launch_SOURCES "dbus-launch") endif() ``` -------------------------------- ### Add Version Info for dbus-update-activation-environment (Windows) Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Adds version information to the dbus-update-activation-environment executable specifically for Windows builds. ```cmake if(WIN32) add_executable_version_info(dbus_update_activation_environment_SOURCES "dbus-update-activation-environment") endif() ``` -------------------------------- ### Platform-Specific Settings for DBus Source: https://github.com/dbus/dbus/blob/main/dbus/CMakeLists.txt Configures source and header files based on the operating system (Windows/Unix). Includes conditional settings for WINCE and ENABLE_TRADITIONAL_ACTIVATION. ```cmake if(WIN32) set(DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES} dbus-backtrace-win.c dbus-file-win.c dbus-init-win.cpp dbus-sysdeps-win.c dbus-pipe-win.c dbus-sysdeps-thread-win.c ) set(DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS} dbus-init-win.h dbus-sockets-win.h dbus-sysdeps-win.h ) set(DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES} dbus-spawn-win.c dbus-sysdeps-util-win.c ) if(WINCE) set(DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES} dbus-sysdeps-wince-glue.c ) set(DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS} dbus-sysdeps-wince-glue.h ) endif() else(WIN32) set(DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES} dbus-file-unix.c dbus-pipe-unix.c dbus-sysdeps-unix.c dbus-sysdeps-pthread.c dbus-userdb.c ) set(DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS} dbus-transport-unix.h dbus-sysdeps-unix.h dbus-userdb.h ) set(DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES} dbus-userdb-util.c dbus-sysdeps-util-unix.c ) if(ENABLE_TRADITIONAL_ACTIVATION) set(DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES} dbus-spawn-unix.c ) endif() endif() if(DBUS_HAVE_LINUX_EPOLL) set(DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES} dbus-pollable-set-epoll.c ) endif() ``` -------------------------------- ### Enable coverage profiling Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Configures the build with coverage profiling instrumentation using GCC flags. Defaults to OFF. Optimization flags are commented out. ```cmake if(NOT MSVC) option(DBUS_GCOV_ENABLED "compile with coverage profiling instrumentation (gcc only)" OFF) if(DBUS_GCOV_ENABLED) add_definitions(-fprofile-arcs -ftest-coverage) # FIXME!!!! ## remove optimization # CFLAGS=`echo "$CFLAGS" | sed -e 's/-O[0-9]*//g'` endif() endif() ``` -------------------------------- ### Implement a DCOP Interface in a Class Source: https://github.com/dbus/dbus/blob/main/doc/dcop-howto.txt Inherit from the interface and implement the virtual methods. Ensure QObject is the first inherited class if applicable. ```cpp class MyClass: public QObject, virtual public MyInterface { Q_OBJECT public: MyClass(); ~MyClass(); ASYNC myAsynchronousMethod(QString someParameter); QRect mySynchronousMethod(); }; ``` -------------------------------- ### Initialize and Handle DBus Errors Source: https://context7.com/dbus/dbus/llms.txt Demonstrates initializing DBusError, checking for errors after operations like bus connection, printing error details, and handling specific error types. Errors must be initialized before use and freed after handling. ```c #include #include void demonstrate_error_handling(void) { DBusError error; DBusConnection *conn; DBusMessage *msg, *reply; /* Always initialize errors before use */ dbus_error_init(&error); /* Or use static initializer: DBusError error = DBUS_ERROR_INIT; */ /* Attempt a connection */ conn = dbus_bus_get(DBUS_BUS_SESSION, &error); /* Check if error occurred */ if (dbus_error_is_set(&error)) { /* Print error details */ fprintf(stderr, "Error name: %s\n", error.name); fprintf(stderr, "Error message: %s\n", error.message); /* Check for specific error types */ if (dbus_error_has_name(&error, DBUS_ERROR_NO_SERVER)) { fprintf(stderr, "No D-Bus daemon running!\n"); } else if (dbus_error_has_name(&error, DBUS_ERROR_NO_MEMORY)) { fprintf(stderr, "Out of memory!\n"); } /* Free error resources */ dbus_error_free(&error); return; } /* Create and send a message that will fail */ msg = dbus_message_new_method_call( "org.nonexistent.Service", "/org/nonexistent/Object", "org.nonexistent.Interface", "NonexistentMethod" ); /* Re-initialize error for reuse */ dbus_error_init(&error); reply = dbus_connection_send_with_reply_and_block(conn, msg, 1000, &error); dbus_message_unref(msg); if (dbus_error_is_set(&error)) { /* Common error names from dbus-protocol.h: * DBUS_ERROR_SERVICE_UNKNOWN - Service doesn't exist * DBUS_ERROR_NAME_HAS_NO_OWNER - Bus name not owned * DBUS_ERROR_NO_REPLY - Timeout waiting for reply * DBUS_ERROR_ACCESS_DENIED - Permission denied * DBUS_ERROR_UNKNOWN_METHOD - Method doesn't exist * DBUS_ERROR_INVALID_ARGS - Wrong argument types */ if (dbus_error_has_name(&error, DBUS_ERROR_SERVICE_UNKNOWN)) { printf("Service not found on the bus\n"); } else if (dbus_error_has_name(&error, DBUS_ERROR_NO_REPLY)) { printf("Service did not respond in time\n"); } else { printf("Method call failed: %s\n", error.message); } dbus_error_free(&error); } else if (reply) { /* Check if reply is an error message */ if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { /* Extract error from message */ dbus_set_error_from_message(&error, reply); printf("Remote error: %s - %s\n", error.name, error.message); dbus_error_free(&error); } dbus_message_unref(reply); } dbus_connection_unref(conn); } ``` -------------------------------- ### Set dbus-launch Source Files (Windows) Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Specifies the source files for the dbus-launch executable on Windows. ```cmake if(WIN32) set(dbus_launch_SOURCES dbus-launch-win.c ) else(WIN32) set(dbus_launch_SOURCES dbus-launch.c tool-common.c tool-common.h ) endif() ``` -------------------------------- ### Implement DCOP Interface Methods Source: https://github.com/dbus/dbus/blob/main/doc/dcop-howto.txt Standard method implementation for DCOP-exposed functions. ```cpp void MyClass::myAsynchronousMethod(QString someParameter) { qDebug("myAsyncMethod called with param `" + someParameter + "'"); } ``` -------------------------------- ### Windows Specific Library Linking and Versioning Source: https://github.com/dbus/dbus/blob/main/dbus/CMakeLists.txt Handles library versioning, suffixing, and linking for Windows, including specific libraries like ws2, advapi32, etc. Also creates a non-versioned copy for legacy applications. ```cmake if(WIN32) if(DEFINED DBUS_LIBRARY_REVISION) set_target_properties(dbus-1 PROPERTIES SUFFIX "-${DBUS_LIBRARY_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}") add_custom_command(TARGET dbus-1 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "$" "$/${CMAKE_SHARED_LIBRARY_PREFIX}dbus-1${CMAKE_SHARED_LIBRARY_SUFFIX}" COMMENT "Create non versioned dbus-1 library for legacy applications" ) install(FILES ${LEGACY_FILE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() if(WINCE) target_link_libraries(dbus-1 ws2) else(WINCE) target_link_libraries(dbus-1 ws2_32 advapi32 netapi32 iphlpapi dbghelp) endif() endif() ``` -------------------------------- ### Create release distribution Source: https://github.com/dbus/dbus/blob/main/maint/release-checklist.md Generates the distribution tarball equivalent to make distcheck. ```bash meson dist -C ${builddir) ``` -------------------------------- ### Emit and Connect DCOP Signals Source: https://github.com/dbus/dbus/blob/main/doc/dcop-howto.txt Demonstrates emitting a signal from a DCOP client and establishing a non-volatile, anonymous connection to receive it. ```cpp QByteArray params; QDataStream stream(params, IO_WriteOnly); stream << pid; kapp->dcopClient()->emitDCOPSignal("clientDied(pid_t)", params); ``` ```cpp connectDCOPSignal(0, 0, "clientDied(pid_t)", "clientDied(pid_t)", false); ``` -------------------------------- ### Add Version Info for dbus-send (Windows) Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Adds version information to the dbus-send executable specifically for Windows builds. ```cmake if(WIN32) add_executable_version_info(dbus_send_SOURCES "dbus-send") endif() ``` -------------------------------- ### Add Version Info for dbus-run-session (Windows) Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Adds version information to the dbus-run-session executable specifically for Windows builds. ```cmake if(WIN32) add_executable_version_info(dbus_run_session_SOURCES "dbus-run-session") endif() ``` -------------------------------- ### Set dbus-cleanup-sockets Source Files Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Specifies the source files for the dbus-cleanup-sockets executable. ```cmake set(dbus_cleanup_sockets_SOURCES dbus-cleanup-sockets.c ) ``` -------------------------------- ### Define Internal Client Definitions Source: https://github.com/dbus/dbus/blob/main/test/name-test/CMakeLists.txt Adds predefined macros for internal DBus client configurations. This is typically used at the beginning of a build script. ```cmake add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS}) ``` -------------------------------- ### Add Compiler Definitions Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Adds necessary compiler flags for building D-Bus. ```cmake add_definitions(-DHAVE_CONFIG_H) add_definitions(${DBUS_BUS_CFLAGS}) ``` -------------------------------- ### Enable console owner file (Solaris) Source: https://github.com/dbus/dbus/blob/main/CMakeLists.txt Enables checking for a console owner file on Solaris systems. Defaults to ON. ```cmake string(TOUPPER ${CMAKE_SYSTEM_NAME} sysname) if("${sysname}" MATCHES ".*SOLARIS.*") option(HAVE_CONSOLE_OWNER_FILE "enable console owner file(solaris only)" ON) if(HAVE_CONSOLE_OWNER_FILE) set(DBUS_CONSOLE_OWNER_FILE "/dev/console" CACHE STRING "Directory to check for console ownerhip") endif() endif() ``` -------------------------------- ### Set dbus-run-session Source Files Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Specifies the source files for the dbus-run-session executable. ```cmake set(dbus_run_session_SOURCES dbus-run-session.c tool-common.c tool-common.h ) ``` -------------------------------- ### Registering a DCOP Client Source: https://github.com/dbus/dbus/blob/main/doc/dcop-howto.txt Registers the application with the DCOP server using the application name. ```cpp /* * returns the appId that is actually registered, which _may_ be * different from what you passed */ appId = client->registerAs(kApp->name()); ``` -------------------------------- ### Add UAC Manifest for dbus-update-activation-environment (Windows) Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Adds a User Account Control (UAC) manifest to the dbus-update-activation-environment executable for Windows builds, excluding MSVC compiler. ```cmake if(WIN32 AND NOT MSVC) add_uac_manifest(dbus_update_activation_environment_SOURCES) endif() ``` -------------------------------- ### Set dbus-monitor Source Files Source: https://github.com/dbus/dbus/blob/main/tools/CMakeLists.txt Specifies the source files for the dbus-monitor executable. ```cmake set(dbus_monitor_SOURCES dbus-monitor.c dbus-print-message.c dbus-print-message.h tool-common.c tool-common.h ) ``` -------------------------------- ### dbus_bus_get Source: https://context7.com/dbus/dbus/llms.txt Establishes a connection to a well-known system or session bus. ```APIDOC ## C dbus_bus_get ### Description The dbus_bus_get() function establishes a connection to either the system bus or session bus. It returns a shared connection that should not be closed by the application, and automatically handles registration with the bus daemon. ### Parameters #### Path Parameters - **type** (DBusBusType) - Required - The bus type to connect to (DBUS_BUS_SESSION, DBUS_BUS_SYSTEM, or DBUS_BUS_STARTER). - **error** (DBusError*) - Required - Pointer to an error structure to store connection errors. ### Response #### Success Response (200) - **connection** (DBusConnection*) - A pointer to the shared bus connection. ``` -------------------------------- ### Tag release Source: https://github.com/dbus/dbus/blob/main/maint/release-checklist.md Creates an annotated tag for the release. Use -s for signed tags or -a for unsigned. ```bash git tag -s -m 'Released X.Y.Z' dbus-X.Y.Z ``` ```bash git tag -a -m 'Released X.Y.Z' dbus-X.Y.Z ``` -------------------------------- ### Perform Asynchronous Method Calls in C Source: https://context7.com/dbus/dbus/llms.txt Uses dbus_connection_send_with_reply to initiate a non-blocking request and a callback function to handle the response. ```c #include #include /* Callback invoked when reply arrives */ void pending_call_notify(DBusPendingCall *pending, void *user_data) { DBusMessage *reply; DBusError error; const char *result = NULL; printf("Reply received! (user_data: %s)\n", (char *)user_data); /* Get the reply message */ reply = dbus_pending_call_steal_reply(pending); if (reply == NULL) { fprintf(stderr, "Reply is NULL\n"); return; } dbus_error_init(&error); /* Check message type */ if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { dbus_set_error_from_message(&error, reply); fprintf(stderr, "Error reply: %s\n", error.message); dbus_error_free(&error); } else if (dbus_message_get_args(reply, &error, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID)) { printf("Result: %s\n", result); } else { fprintf(stderr, "Failed to parse reply: %s\n", error.message); dbus_error_free(&error); } dbus_message_unref(reply); } int main(void) { DBusError error; DBusConnection *conn; DBusMessage *msg; DBusPendingCall *pending = NULL; const char *param = "async test"; dbus_error_init(&error); conn = dbus_bus_get(DBUS_BUS_SESSION, &error); if (dbus_error_is_set(&error)) { fprintf(stderr, "Connection Error: %s\n", error.message); dbus_error_free(&error); return 1; } /* Create method call message */ msg = dbus_message_new_method_call( "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "GetNameOwner" ); /* Add argument */ dbus_message_append_args(msg, DBUS_TYPE_STRING, ¶m, DBUS_TYPE_INVALID); /* Send message and get pending call object * Timeout: DBUS_TIMEOUT_USE_DEFAULT or milliseconds */ if (!dbus_connection_send_with_reply(conn, msg, &pending, DBUS_TIMEOUT_USE_DEFAULT)) { fprintf(stderr, "Send with reply failed\n"); dbus_message_unref(msg); return 1; } dbus_message_unref(msg); if (pending == NULL) { fprintf(stderr, "Pending call is NULL\n"); return 1; } /* Set up notification callback */ if (!dbus_pending_call_set_notify(pending, pending_call_notify, "callback context", NULL)) { fprintf(stderr, "Failed to set notify\n"); dbus_pending_call_unref(pending); return 1; } printf("Method call sent, waiting for reply...\n"); /* Process messages until reply arrives */ while (!dbus_pending_call_get_completed(pending)) { dbus_connection_read_write_dispatch(conn, 100); } /* Alternative: block waiting for reply */ /* dbus_pending_call_block(pending); */ /* Alternative: cancel pending call */ /* dbus_pending_call_cancel(pending); */ dbus_pending_call_unref(pending); dbus_connection_unref(conn); return 0; } ``` -------------------------------- ### Add Docbook Documentation Source: https://github.com/dbus/dbus/blob/main/doc/CMakeLists.txt This macro generates documentation from DocBook XML sources. It supports HTML and man page formats and can use templates for generated files. Ensure XSLTPROC_EXECUTABLE and DOCBOOKXSL_DIR are set. ```cmake macro(add_docbook _target) set(options) set(oneValueArgs SOURCE TEMPLATE MAN_CATEGORY) set(multiValueArgs FORMATS) cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) foreach(_format ${ARGS_FORMATS}) if(ARGS_TEMPLATE) set(_xmlfile "${CMAKE_CURRENT_BINARY_DIR}/${_target}-${_format}.xml") get_filename_component(_infile ${ARGS_TEMPLATE} ABSOLUTE) configure_file(${_infile} ${_xmlfile}) else() get_filename_component(_infile ${ARGS_SOURCE} ABSOLUTE) set(_xmlfile ${_infile}) endif() if(${_format} STREQUAL "man") set(_outname "${_target}.${ARGS_MAN_CATEGORY}") set(STYLESHEET "${DOCBOOKXSL_DIR}/manpages/docbook.xsl") set(INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/man/man${ARGS_MAN_CATEGORY}) else() if (NOT ARGS_MAN_CATEGORY) set(_outname "${_target}.html") else() set(_outname "${_target}.${ARGS_MAN_CATEGORY}.html") endif() set(STYLESHEET "${DOCBOOKXSL_DIR}/html/docbook.xsl") set(INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/doc/dbus) endif() set(_outfile ${CMAKE_CURRENT_BINARY_DIR}/${_outname}) add_custom_command( OUTPUT ${_outfile} COMMAND ${XSLTPROC_EXECUTABLE} --output ${_outfile} --nonet --xinclude --param passivetex.extensions '1' --param generate.consistent.ids '1' ${STYLESHEET} ${_xmlfile} DEPENDS ${XSLTPROC_EXECUTABLE} ${_xmlfile} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) add_custom_target(xmldoc-${_outname} DEPENDS ${_outfile}) add_dependencies(xmldoc xmldoc-${_outname}) install(FILES ${_outfile} DESTINATION ${INSTALL_DIR}) endforeach() endmacro() ```