/* * SPDX-License-Identifier: LicenseRef-Unisoc-General-1.0 * Copyright 2016-2023 Unisoc (Shanghai) Technologies Co., Ltd * Licensed under the Unisoc General Software License, version 1.0 (the License); * you may not use this file except in compliance with the License. You may obtain a copy of the License at * https://www.unisoc.com/en_us/license/UNISOC_GENERAL_LICENSE_V1.0-EN_US * Software distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OF ANY KIND, either express or implied. * See the Unisoc General Software License, version 1.0 for more details. */ #include #include #include #include "Debug.h" #include "DispatcherInternal.h" #include "ConnectionInternal.h" Dispatcher *UDBus::gDefaultDispatcher = nullptr; dbus_bool_t Dispatcher::UDBusPrivate::OnAddWatch(DBusWatch* watch, void* data) { Dispatcher* dispatcher = static_cast(data); DEBUG("OnAddWatch watch:%p ", watch); dispatcher->AddWatch(reinterpret_cast(watch)); return true; } void Dispatcher::UDBusPrivate::OnRemoveWatch(DBusWatch* watch, void *data) { Dispatcher* dispatcher = static_cast(data); DEBUG("OnRemoveWatch watch:%p ", watch); dispatcher->RemoveWatch(static_cast(dbus_watch_get_data(watch))); } void Dispatcher::UDBusPrivate::OnToggleWatch(DBusWatch* watch, void *data) { static_cast(dbus_watch_get_data(watch))->Toggle(); } dbus_bool_t Dispatcher::UDBusPrivate::OnAddTimeout(DBusTimeout *timeout, void *data) { Dispatcher* dispatcher = static_cast(data); dispatcher->AddTimeout(reinterpret_cast(timeout)); return true; } void Dispatcher::UDBusPrivate::OnRemTimeout(DBusTimeout *timeout, void *data) { Dispatcher* dispatcher = static_cast(data); dispatcher->RemTimeout(static_cast(dbus_timeout_get_data(timeout))); } void Dispatcher::UDBusPrivate::OnToggleTimeout(DBusTimeout *timeout, void *data) { static_cast(dbus_timeout_get_data(timeout))->Toggle(); } void Dispatcher::QueueConnection(Connection::PrivateSuffix *cp) { DEBUG("current size [%d] new %p", mPendingQueue.size(), cp); mPendingQueue.push_back(cp); } bool Dispatcher::HasSomethingToDispatch() { bool hasSomething = false; for(Connection::PrivatePList::iterator it = mPendingQueue.begin(); it != mPendingQueue.end() && !hasSomething; ++it) { hasSomething = (*it)->HasSomethingToDispatch(); } return hasSomething; } void InitThreading() { #ifdef DBUS_HAS_THREADS_INIT_DEFAULT dbus_threads_init_default(); #else DEBUG("Thread support is not enabled! Your D-Bus version is too old!"); #endif }