You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdebluez/src/libtdebluez/adapterImpl.cpp

103 lines
2.7 KiB

/*
*
* Adapter Implementation of bluez5 for libtdebluez
*
* Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com>
*
*
* This file is part of libtdebluez.
*
* libtdebluez is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* libtdebluez is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with kbluetooth; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <linux/rfkill.h>
#include <unistd.h>
#include <tqfile.h>
#include <tqdbusproxy.h>
#include "adapterImpl.h"
namespace TDEBluetooth {
AdapterImpl::AdapterImpl(const TQString& service, const TQString& path,
TQObject* parent, const char* name) :
Adapter1Proxy(service, path, parent, name) /*,properties(service,path,parent,name)*/
{
}
AdapterImpl::~AdapterImpl() {
}
void AdapterImpl::powerOn(bool state) {
// https://www.kernel.org/doc/Documentation/rfkill.txt
// http://jwhsmith.net/2015/02/manipulating-rfkill-using-devices-programmatically/
struct rfkill_event event = {0};
TQFile file("/dev/rfkill");
if (!file.open(IO_ReadWrite)) {
tqDebug("Failed to open %s", file.name().utf8().data());
return;
}
while(read(file.handle(), &event, sizeof(event)) > 0){
if(event.type == RFKILL_TYPE_BLUETOOTH) {
tqDebug("Bluetooth chip switches: soft(%d), hard(%d).\n",
event.soft, event.hard);
break;
}
}
event.op = RFKILL_OP_CHANGE;
if (state)
event.soft = 0;
else
event.soft = 1;
if(write(file.handle(), &event, sizeof(event)) < 0){
tqDebug("Failed to write to %s", file.name().utf8().data());
}
file.close();
}
TQString AdapterImpl::getPath() {
return TQString(m_baseProxy->path());
}
void AdapterImpl::slotSetAlias(const TQString& alias) {
TQT_DBusError error;
setAlias(alias, error);
if (error.isValid())
tqDebug("AdapterImpl::slotSetAlias(%s) failed: %s", alias.utf8().data(),
error.message().utf8().data());
}
void AdapterImpl::slotSetTimeout(int timeout) {
TQT_DBusError error;
setDiscoverableTimeout(timeout, error);
if (error.isValid())
tqDebug("AdapterImpl::slotSetTimeout(%i) failed: %s", timeout,
error.message().utf8().data());
}
} // namespace TDEBluetooth
#include "adapterImpl.moc"
// End of File