21#include <QSocketNotifier>
29 RFKILL_TYPE_BLUETOOTH,
35enum rfkill_operation {
53 , d(new RfkillPrivate)
61 if (d->m_readFd != -1) {
65 if (d->m_writeFd != -1) {
66 ::close(d->m_writeFd);
71Rfkill::State Rfkill::state()
const
78 if (d->m_state == SoftBlocked || d->m_state == HardBlocked) {
87 if (d->m_state == Unblocked) {
94void Rfkill::devReadyRead()
96 State oldState = d->m_state;
98 updateRfkillDevices();
100 if (d->m_state != oldState) {
101 Q_EMIT stateChanged(d->m_state);
108 d->m_readFd = ::open(
"/dev/rfkill", O_RDONLY | O_CLOEXEC);
110 if (d->m_readFd == -1) {
111 qCWarning(BLUEZQT) <<
"Cannot open /dev/rfkill for reading!";
115 if (::fcntl(d->m_readFd, F_SETFL, O_NONBLOCK) < 0) {
116 ::close(d->m_readFd);
121 updateRfkillDevices();
128bool Rfkill::openForWriting()
133 if (d->m_writeFd != -1) {
137 d->m_writeFd = ::open(
"/dev/rfkill", O_WRONLY | O_CLOEXEC);
139 if (d->m_writeFd == -1) {
140 qCWarning(BLUEZQT) <<
"Cannot open /dev/rfkill for writing!";
144 if (::fcntl(d->m_writeFd, F_SETFL, O_NONBLOCK) < 0) {
145 ::close(d->m_writeFd);
155static Rfkill::State getState(
const rfkill_event &event)
158 return Rfkill::HardBlocked;
159 }
else if (
event.soft) {
160 return Rfkill::SoftBlocked;
162 return Rfkill::Unblocked;
166void Rfkill::updateRfkillDevices()
169 if (d->m_readFd == -1) {
174 while (::read(d->m_readFd, &event,
sizeof(event)) ==
sizeof(event)) {
175 if (
event.type != RFKILL_TYPE_BLUETOOTH) {
181 case RFKILL_OP_CHANGE:
182 d->m_devices[
event.idx] = getState(event);
186 d->m_devices.remove(
event.idx);
189 case RFKILL_OP_CHANGE_ALL:
190 for (
auto it = d->m_devices.begin(); it != d->m_devices.end(); ++it) {
191 it.value() = getState(event);
203 for (
State state : std::as_const(d->m_devices)) {
204 Q_ASSERT(state != Unknown);
206 if (d->m_state == Unknown) {
208 }
else if (state > d->m_state) {
213 qCDebug(BLUEZQT) <<
"Rfkill global state changed:" << d->m_state;
217bool Rfkill::setSoftBlock(quint8 soft)
223 if (!openForWriting()) {
228 ::memset(&event, 0,
sizeof(event));
229 event.op = RFKILL_OP_CHANGE_ALL;
230 event.type = RFKILL_TYPE_BLUETOOTH;
233 bool ret = ::write(d->m_writeFd, &event,
sizeof(event)) ==
sizeof(
event);
234 qCDebug(BLUEZQT) <<
"Setting Rfkill soft block succeeded:" << ret;
241#include "moc_rfkill.cpp"
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
PHONON_EXPORT Notifier * notifier()
void activated(QSocketDescriptor socket, QSocketNotifier::Type type)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)