Files

64 lines
1.7 KiB
C++
Raw Permalink 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 <string.h>
#include <sys/poll.h>
#include <dbus/dbus.h>
#include <errno.h>
#include "Debug.h"
#include "BusWatch.h"
BusWatch::BusWatch(Watch::Internal *internal)
: Watch(internal)
{
dbus_watch_set_data((DBusWatch *)internal, this, nullptr);
mFd = GetDescriptor();
int flags = GetFlags();
mFlags = POLLHUP | POLLERR;
if (flags & DBUS_WATCH_READABLE)
mFlags |= POLLIN;
if (flags & DBUS_WATCH_WRITABLE)
mFlags |= POLLOUT;
mEnabled = GetEnabled();
}
int BusWatch::GetDescriptor() const
{
return dbus_watch_get_unix_fd((DBusWatch *)mInternal);
}
void BusWatch::Toggle()
{
SetEnabled(!mEnabled);
}
int BusWatch::GetFlags() const
{
return dbus_watch_get_flags((DBusWatch *)mInternal);
}
bool BusWatch::GetEnabled() const
{
return dbus_watch_get_enabled((DBusWatch *)mInternal);
}
bool BusWatch::Handle(int flags)
{
DEBUG("[dbus debug] dbus_watch_handle Watch :%p Handle(%p, %d)", mInternal, this, flags);
return dbus_watch_handle((DBusWatch *)mInternal, flags);
}