Files
BPI-M2C/source_sync_rls_25c/source/unisoc/perflink/libudbus/Dispatcher.cpp
T

92 lines
2.7 KiB
C++
Raw Normal View History

2026-09-22 09:38:26 +08:00
/*
* 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 <cassert>
#include <Dispatcher.h>
#include <dbus/dbus.h>
#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<Dispatcher * >(data);
DEBUG("OnAddWatch watch:%p ", watch);
dispatcher->AddWatch(reinterpret_cast<Watch::Internal *>(watch));
return true;
}
void Dispatcher::UDBusPrivate::OnRemoveWatch(DBusWatch* watch, void *data)
{
Dispatcher* dispatcher = static_cast<Dispatcher * >(data);
DEBUG("OnRemoveWatch watch:%p ", watch);
dispatcher->RemoveWatch(static_cast<Watch *>(dbus_watch_get_data(watch)));
}
void Dispatcher::UDBusPrivate::OnToggleWatch(DBusWatch* watch, void *data)
{
static_cast<Watch *>(dbus_watch_get_data(watch))->Toggle();
}
dbus_bool_t Dispatcher::UDBusPrivate::OnAddTimeout(DBusTimeout *timeout, void *data)
{
Dispatcher* dispatcher = static_cast<Dispatcher * >(data);
dispatcher->AddTimeout(reinterpret_cast<Timeout::Internal *>(timeout));
return true;
}
void Dispatcher::UDBusPrivate::OnRemTimeout(DBusTimeout *timeout, void *data)
{
Dispatcher* dispatcher = static_cast<Dispatcher * >(data);
dispatcher->RemTimeout(static_cast<Timeout *>(dbus_timeout_get_data(timeout)));
}
void Dispatcher::UDBusPrivate::OnToggleTimeout(DBusTimeout *timeout, void *data)
{
static_cast<Timeout *>(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
}