QBBSystemLocaleData::QBBSystemLocaleData() : languageNotifier(0) , regionNotifier(0) , measurementNotifier(0) , hourNotifier(0) { if ((measurementFd = qt_safe_open(ppsUomPath, O_RDONLY)) == -1) qWarning("Failed to open uom pps, errno=%d", errno); if ((regionFd = qt_safe_open(ppsRegionLocalePath, O_RDONLY)) == -1) qWarning("Failed to open region pps, errno=%d", errno); if ((languageFd = qt_safe_open(ppsLanguageLocalePath, O_RDONLY)) == -1) qWarning("Failed to open language pps, errno=%d", errno); if ((hourFd = qt_safe_open(ppsHourFormatPath, O_RDONLY)) == -1) qWarning("Failed to open hour format pps, errno=%d", errno); // we cannot call this directly, because by the time this constructor is // called, the event dispatcher has not yet been created, causing the // subsequent call to QSocketNotifier constructor to fail. QMetaObject::invokeMethod(this, "installSocketNotifiers", Qt::QueuedConnection); readLangageLocale(); readRegionLocale(); readMeasurementSystem(); readHourFormat(); }
QBBSystemLocaleData::QBBSystemLocaleData() : languageNotifier(0) , regionNotifier(0) , measurementNotifier(0) , hourNotifier(0) { // Do not use qWarning to log warnings if qt_safe_open fails to open the pps file // since the user code may install a message handler that invokes QLocale API again // (i.e QDate, QDateTime, ...) which will cause an infinite loop. if ((measurementFd = qt_safe_open(ppsUomPath, O_RDONLY)) == -1) fprintf(stderr, "Failed to open uom pps, errno=%d\n", errno); if ((regionFd = qt_safe_open(ppsRegionLocalePath, O_RDONLY)) == -1) fprintf(stderr, "Failed to open region pps, errno=%d\n", errno); if ((languageFd = qt_safe_open(ppsLanguageLocalePath, O_RDONLY)) == -1) fprintf(stderr, "Failed to open language pps, errno=%d\n", errno); if ((hourFd = qt_safe_open(ppsHourFormatPath, O_RDONLY)) == -1) fprintf(stderr, "Failed to open hour format pps, errno=%d\n", errno); // we cannot call this directly, because by the time this constructor is // called, the event dispatcher has not yet been created, causing the // subsequent call to QSocketNotifier constructor to fail. QMetaObject::invokeMethod(this, "installSocketNotifiers", Qt::QueuedConnection); readLangageLocale(); readRegionLocale(); readMeasurementSystem(); readHourFormat(); }
void QEglFSHooks::platformInit() { framebuffer = qt_safe_open(fbDeviceName(), O_RDONLY); if (framebuffer == -1) qWarning("EGLFS: Failed to open %s", fbDeviceName()); }
QT_BEGIN_NAMESPACE QEvdevMouseHandler *QEvdevMouseHandler::create(const QString &device, const QString &specification) { #ifdef QT_QPA_MOUSE_HANDLER_DEBUG qWarning() << "Try to create mouse handler for" << device << specification; #endif bool compression = true; int jitterLimit = 0; QStringList args = specification.split(QLatin1Char(':')); foreach (const QString &arg, args) { if (arg == QLatin1String("nocompress")) compression = false; else if (arg.startsWith(QLatin1String("dejitter="))) jitterLimit = arg.mid(9).toInt(); } int fd; fd = qt_safe_open(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); if (fd >= 0) { return new QEvdevMouseHandler(device, fd, compression, jitterLimit); } else { qWarning("Cannot open mouse input device '%s': %s", qPrintable(device), strerror(errno)); return 0; } }
QLockFile::LockError QLockFilePrivate::tryLock_sys() { // Assemble data, to write in a single call to write // (otherwise we'd have to check every write call) // Use operator% from the fast builder to avoid multiple memory allocations. QByteArray fileData = QByteArray::number(QCoreApplication::applicationPid()) + '\n' + qAppName().toUtf8() + '\n' + localHostName().toUtf8() + '\n'; const QByteArray lockFileName = QFile::encodeName(fileName); const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY | O_CREAT | O_EXCL, 0644); if (fd < 0) { switch (errno) { case EEXIST: return QLockFile::LockFailedError; case EACCES: case EROFS: return QLockFile::PermissionError; default: return QLockFile::UnknownError; } } // Ensure nobody else can delete the file while we have it if (!setNativeLocks(fd)) qWarning() << "setNativeLocks failed:" << strerror(errno); // We hold the lock, continue. fileHandle = fd; QLockFile::LockError error = QLockFile::NoError; if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) error = QLockFile::UnknownError; // partition full return error; }
void CameraBinV4LImageProcessing::setParameter( ProcessingParameter parameter, const QVariant &value) { QMap<ProcessingParameter, SourceParameterValueInfo>::const_iterator sourceValueInfo = m_parametersInfo.constFind(parameter); if (sourceValueInfo == m_parametersInfo.constEnd()) { qWarning() << "Unable to set the parameter value: the parameter is not supported."; return; } const QString deviceName = m_session->device(); const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_WRONLY); if (fd == -1) { qWarning() << "Unable to open the camera" << deviceName << "for write to set the parameter value:" << qt_error_string(errno); return; } struct v4l2_control control; ::memset(&control, 0, sizeof(control)); control.id = (*sourceValueInfo).cid; switch (parameter) { case QCameraImageProcessingControl::WhiteBalancePreset: { const QCameraImageProcessing::WhiteBalanceMode m = value.value<QCameraImageProcessing::WhiteBalanceMode>(); if (m != QCameraImageProcessing::WhiteBalanceAuto && m != QCameraImageProcessing::WhiteBalanceManual) { qt_safe_close(fd); return; } control.value = (m == QCameraImageProcessing::WhiteBalanceAuto) ? true : false; } break; case QCameraImageProcessingControl::ColorTemperature: control.value = value.toInt(); break; case QCameraImageProcessingControl::ContrastAdjustment: // falling back case QCameraImageProcessingControl::SaturationAdjustment: // falling back case QCameraImageProcessingControl::BrightnessAdjustment: // falling back case QCameraImageProcessingControl::SharpeningAdjustment: control.value = sourceImageProcessingParameterValue( value.toReal(), (*sourceValueInfo)); break; default: qt_safe_close(fd); return; } if (::ioctl(fd, VIDIOC_S_CTRL, &control) != 0) qWarning() << "Unable to set the parameter value:" << qt_error_string(errno); qt_safe_close(fd); }
void QEglFSHooks::platformInit() { QByteArray fbDev = fbDeviceName(); framebuffer = qt_safe_open(fbDev, O_RDONLY); if (framebuffer == -1) qWarning("EGLFS: Failed to open %s", qPrintable(fbDev)); }
bool QLockFilePrivate::removeStaleLock() { const QByteArray lockFileName = QFile::encodeName(fileName); const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY, 0644); if (fd < 0) // gone already? return false; bool success = setNativeLocks(fd) && (::unlink(lockFileName) == 0); close(fd); return success; }
QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus( const QBluetoothAddress &address) const { if (!isValid()) return Unpaired; bool paired = false; bool btle = false; // Bluetooth Low Energy devices QByteArray qnxPath("/pps/services/bluetooth/remote_devices/"); qnxPath.append(address.toString().toUtf8()); int m_rdfd; if ((m_rdfd = qt_safe_open(qnxPath.constData(), O_RDONLY)) == -1) { btle = true; qnxPath.append("-00"); if ((m_rdfd = qt_safe_open(qnxPath.constData(), O_RDONLY)) == -1) { qnxPath.replace((qnxPath.length()-3), 3, "-01"); if ((m_rdfd = qt_safe_open(qnxPath.constData(), O_RDONLY)) == -1) return Unpaired; } } pps_decoder_t ppsDecoder; pps_decoder_initialize(&ppsDecoder, NULL); QBluetoothAddress deviceAddr; QString deviceName; if (!ppsReadRemoteDevice(m_rdfd, &ppsDecoder, &deviceAddr, &deviceName)) return Unpaired; bool known = false; // Paired BTLE devices have only known field set to true. if (btle) pps_decoder_get_bool(&ppsDecoder, "known", &known); pps_decoder_get_bool(&ppsDecoder, "paired", &paired); pps_decoder_cleanup(&ppsDecoder); if (paired) return Paired; else if (btle && known) return Paired; else return Unpaired; }
void QGstreamerVideoInputDeviceControl::update() { m_names.clear(); m_descriptions.clear(); // subdevsrc and the like have a camera-device property that takes an enumeration // identifying a primary or secondary camera, so return identifiers that map to those // instead of a list of actual devices. if (m_source && g_object_class_find_property(G_OBJECT_GET_CLASS(m_source), "camera-device")) { m_names << QLatin1String("primary") << QLatin1String("secondary"); m_descriptions << tr("Main camera") << tr("Front camera"); return; } QDir devDir("/dev"); devDir.setFilter(QDir::System); QFileInfoList entries = devDir.entryInfoList(QStringList() << "video*"); foreach( const QFileInfo &entryInfo, entries ) { //qDebug() << "Try" << entryInfo.filePath(); int fd = qt_safe_open(entryInfo.filePath().toLatin1().constData(), O_RDWR ); if (fd == -1) continue; bool isCamera = false; v4l2_input input; memset(&input, 0, sizeof(input)); for (; ::ioctl(fd, VIDIOC_ENUMINPUT, &input) >= 0; ++input.index) { if(input.type == V4L2_INPUT_TYPE_CAMERA || input.type == 0) { isCamera = ::ioctl(fd, VIDIOC_S_INPUT, input.index) != 0; break; } } if (isCamera) { // find out its driver "name" QString name; struct v4l2_capability vcap; memset(&vcap, 0, sizeof(struct v4l2_capability)); if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) != 0) name = entryInfo.fileName(); else name = QString((const char*)vcap.card); //qDebug() << "found camera: " << name; m_names.append(entryInfo.filePath()); m_descriptions.append(name); } qt_safe_close(fd); }
QVariant CameraBinV4LImageProcessing::parameter( ProcessingParameter parameter) const { QMap<ProcessingParameter, SourceParameterValueInfo>::const_iterator sourceValueInfo = m_parametersInfo.constFind(parameter); if (sourceValueInfo == m_parametersInfo.constEnd()) { qWarning() << "Unable to get the parameter value: the parameter is not supported."; return QVariant(); } const QString deviceName = m_session->device(); const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_RDONLY); if (fd == -1) { qWarning() << "Unable to open the camera" << deviceName << "for read to get the parameter value:" << qt_error_string(errno); return QVariant(); } struct v4l2_control control; ::memset(&control, 0, sizeof(control)); control.id = (*sourceValueInfo).cid; const bool ret = (::ioctl(fd, VIDIOC_G_CTRL, &control) == 0); qt_safe_close(fd); if (!ret) { qWarning() << "Unable to get the parameter value:" << qt_error_string(errno); return QVariant(); } switch (parameter) { case QCameraImageProcessingControl::WhiteBalancePreset: return QVariant::fromValue<QCameraImageProcessing::WhiteBalanceMode>( control.value ? QCameraImageProcessing::WhiteBalanceAuto : QCameraImageProcessing::WhiteBalanceManual); case QCameraImageProcessingControl::ColorTemperature: return QVariant::fromValue<qint32>(control.value); case QCameraImageProcessingControl::ContrastAdjustment: // falling back case QCameraImageProcessingControl::SaturationAdjustment: // falling back case QCameraImageProcessingControl::BrightnessAdjustment: // falling back case QCameraImageProcessingControl::SharpeningAdjustment: { return scaledImageProcessingParameterValue( control.value, (*sourceValueInfo)); } default: return QVariant(); } }
QVariant ppsReadSetting(const char *property) { int settingsFD; char buf[ppsBufferSize]; if ((settingsFD = qt_safe_open(btSettingsFDPath, O_RDONLY)) == -1) { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "failed to open "<< btSettingsFDPath; return QVariant(); } QVariant result; qt_safe_read( settingsFD, &buf, sizeof(buf)); pps_decoder_t decoder; pps_decoder_initialize(&decoder, 0); if (pps_decoder_parse_pps_str(&decoder, buf) == PPS_DECODER_OK) { pps_decoder_push(&decoder, 0); pps_node_type_t nodeType = pps_decoder_type(&decoder, property); if (nodeType == PPS_TYPE_STRING) { const char *dat; if (pps_decoder_get_string(&decoder, property, &dat) == PPS_DECODER_OK) { result = QString::fromUtf8(dat); qCDebug(QT_BT_QNX) << "Read setting" << result; } else { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "could not read"<< property; return QVariant(); } } else if (nodeType == PPS_TYPE_BOOL) { bool dat; if (pps_decoder_get_bool(&decoder, property, &dat) == PPS_DECODER_OK) { result = dat; qCDebug(QT_BT_QNX) << "Read setting" << result; } else { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "could not read"<< property; return QVariant(); } } else if (nodeType == PPS_TYPE_NUMBER) { int dat; if (pps_decoder_get_int(&decoder, property, &dat) == PPS_DECODER_OK) { result = dat; qCDebug(QT_BT_QNX) << "Read setting" << result; } else { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "could not read"<< property; return QVariant(); } } else { qCDebug(QT_BT_QNX) << Q_FUNC_INFO << "unrecognized entry for settings"; } } pps_decoder_cleanup(&decoder); qt_safe_close(settingsFD); return result; }
void ppsRegisterControl() { qBBBluetoothDebug() << "Register for Control"; if (count == 0) { ppsCtrlFD = qt_safe_open(btControlFDPath, O_RDWR | O_NONBLOCK); if (ppsCtrlFD == -1) { qWarning() << Q_FUNC_INFO << "ppsCtrlFD - failed to qt_safe_open" << btControlFDPath; } else { ppsCtrlNotifier = new QSocketNotifier(ppsCtrlFD, QSocketNotifier::Read); QObject::connect(ppsCtrlNotifier, SIGNAL(activated(int)), &bbSocketNotifier, SLOT(distribute())); } }
void QBBLocaleData::readPPSLocale() { errno = 0; ppsFd = qt_safe_open(ppsServicePath, O_RDONLY); if (ppsFd == -1) { qWarning("Failed to open Locale pps, errno=%d", errno); return; } ppsNotifier = new QSocketNotifier(ppsFd, QSocketNotifier::Read, this); updateMesurementSystem(); QObject::connect(ppsNotifier, SIGNAL(activated(int)), this, SLOT(updateMesurementSystem())); }
QPpsMaxSize() { int fd = qt_safe_open("/pps/.all", O_RDONLY); if (fd == -1) { qWarning() << "qppsobject.cpp: qt_safe_open failed"; value = -1; } // This tells us the maximum transfer size across PPS value = ::fpathconf(fd, _PC_REC_MAX_XFER_SIZE); qt_safe_close(fd); }
void QEGLDeviceIntegration::platformInit() { QByteArray fbDev = fbDeviceName(); framebuffer = qt_safe_open(fbDev, O_RDONLY); if (framebuffer == -1) { qWarning("EGLFS: Failed to open %s", fbDev.constData()); qFatal("EGLFS: Can't continue without a display"); } #ifdef FBIOBLANK ioctl(framebuffer, FBIOBLANK, VESA_NO_BLANKING); #endif }
void CameraBinV4LImageProcessing::updateParametersInfo( QCamera::Status cameraStatus) { if (cameraStatus == QCamera::UnloadedStatus) m_parametersInfo.clear(); else if (cameraStatus == QCamera::LoadedStatus) { const QString deviceName = m_session->device(); const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_RDONLY); if (fd == -1) { qWarning() << "Unable to open the camera" << deviceName << "for read to query the parameter info:" << qt_error_string(errno); return; } static const struct SupportedParameterEntry { quint32 cid; QCameraImageProcessingControl::ProcessingParameter parameter; } supportedParametersEntries[] = { { V4L2_CID_AUTO_WHITE_BALANCE, QCameraImageProcessingControl::WhiteBalancePreset }, { V4L2_CID_WHITE_BALANCE_TEMPERATURE, QCameraImageProcessingControl::ColorTemperature }, { V4L2_CID_CONTRAST, QCameraImageProcessingControl::ContrastAdjustment }, { V4L2_CID_SATURATION, QCameraImageProcessingControl::SaturationAdjustment }, { V4L2_CID_BRIGHTNESS, QCameraImageProcessingControl::BrightnessAdjustment }, { V4L2_CID_SHARPNESS, QCameraImageProcessingControl::SharpeningAdjustment } }; for (int i = 0; i < int(sizeof(supportedParametersEntries) / sizeof(SupportedParameterEntry)); ++i) { struct v4l2_queryctrl queryControl; ::memset(&queryControl, 0, sizeof(queryControl)); queryControl.id = supportedParametersEntries[i].cid; if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) != 0) { qWarning() << "Unable to query the parameter info:" << qt_error_string(errno); continue; } SourceParameterValueInfo sourceValueInfo; sourceValueInfo.cid = queryControl.id; sourceValueInfo.defaultValue = queryControl.default_value; sourceValueInfo.maximumValue = queryControl.maximum; sourceValueInfo.minimumValue = queryControl.minimum; m_parametersInfo.insert(supportedParametersEntries[i].parameter, sourceValueInfo); } qt_safe_close(fd); } }
/*! \internal Creates the unix file if needed. returns true if the unix file was created. -1 error 0 already existed 1 created */ int QSharedMemoryPrivate::createUnixKeyFile(const QString &fileName) { if (QFile::exists(fileName)) return 0; int fd = qt_safe_open(QFile::encodeName(fileName).constData(), O_EXCL | O_CREAT | O_RDWR, 0640); if (-1 == fd) { if (errno == EEXIST) return 0; return -1; } else { close(fd); } return 1; }
QLockFile::LockError QLockFilePrivate::tryLock_sys() { // Assemble data, to write in a single call to write // (otherwise we'd have to check every write call) // Use operator% from the fast builder to avoid multiple memory allocations. QByteArray fileData = QByteArray::number(QCoreApplication::applicationPid()) % '\n' % QCoreApplication::applicationName().toUtf8() % '\n' % localHostName() % '\n'; const QByteArray lockFileName = QFile::encodeName(fileName); const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY | O_CREAT | O_EXCL, 0644); if (fd < 0) { switch (errno) { case EEXIST: return QLockFile::LockFailedError; case EACCES: case EROFS: return QLockFile::PermissionError; default: return QLockFile::UnknownError; } } // Ensure nobody else can delete the file while we have it if (!setNativeLocks(fileName, fd)) { const int errnoSaved = errno; qWarning() << "setNativeLocks failed:" << qt_error_string(errnoSaved); } if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) { close(fd); if (!QFile::remove(fileName)) qWarning("QLockFile: Could not remove our own lock file %s.", qPrintable(fileName)); return QLockFile::UnknownError; // partition full } // We hold the lock, continue. fileHandle = fd; // Sync to disk if possible. Ignore errors (e.g. not supported). #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 fdatasync(fileHandle); #else fsync(fileHandle); #endif return QLockFile::NoError; }
QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, const QString &specification, const QString &defaultKeymapFile) { qCDebug(qLcEvdevKey) << "Try to create keyboard handler for" << device << specification; QString keymapFile = defaultKeymapFile; int repeatDelay = 400; int repeatRate = 80; bool disableZap = false; bool enableCompose = false; int grab = 0; QStringList args = specification.split(QLatin1Char(':')); foreach (const QString &arg, args) { if (arg.startsWith(QLatin1String("keymap="))) keymapFile = arg.mid(7); else if (arg == QLatin1String("disable-zap")) disableZap = true; else if (arg == QLatin1String("enable-compose")) enableCompose = true; else if (arg.startsWith(QLatin1String("repeat-delay="))) repeatDelay = arg.mid(13).toInt(); else if (arg.startsWith(QLatin1String("repeat-rate="))) repeatRate = arg.mid(12).toInt(); else if (arg.startsWith(QLatin1String("grab="))) grab = arg.mid(5).toInt(); } qCDebug(qLcEvdevKey) << "Opening keyboard at" << device; int fd; fd = qt_safe_open(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); if (fd >= 0) { ::ioctl(fd, EVIOCGRAB, grab); if (repeatDelay > 0 && repeatRate > 0) { int kbdrep[2] = { repeatDelay, repeatRate }; ::ioctl(fd, EVIOCSREP, kbdrep); } return new QEvdevKeyboardHandler(device, fd, disableZap, enableCompose, keymapFile); } else { qWarning("Cannot open keyboard input device '%s': %s", qPrintable(device), strerror(errno)); return 0; } }
void ppsRegisterControl() { count++; if (count == 1) { if (ppsCtrlFD != -1) { qCDebug(QT_BT_QNX) << "PPS control FD not properly deinitialized"; return; } ppsCtrlFD = qt_safe_open(btControlFDPath, O_RDWR | O_SYNC); if (ppsCtrlFD == -1) { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "ppsCtrlFD - failed to qt_safe_open" << btControlFDPath; } else { ppsCtrlNotifier = new QSocketNotifier(ppsCtrlFD, QSocketNotifier::Read); QObject::connect(ppsCtrlNotifier, SIGNAL(activated(int)), &bbSocketNotifier, SLOT(distribute())); } } }
bool QQnxNavigatorPps::openPpsConnection() { if (m_fd != -1) return true; // open connection to navigator errno = 0; m_fd = qt_safe_open(navigatorControlPath, O_RDWR); if (m_fd == -1) { qWarning("QQNX: failed to open navigator pps, errno=%d", errno); return false; } qNavigatorDebug() << Q_FUNC_INFO << "successfully connected to Navigator. fd=" << m_fd; return true; }
void QQnxButtonEventNotifier::start() { qButtonDebug() << Q_FUNC_INFO << "starting hardware button event processing"; if (m_fd != -1) return; // Open the pps interface errno = 0; m_fd = qt_safe_open(ppsPath, O_RDONLY); if (m_fd == -1) { qWarning("QQNX: failed to open buttons pps, errno=%d", errno); return; } m_readNotifier = new QSocketNotifier(m_fd, QSocketNotifier::Read); QObject::connect(m_readNotifier, SIGNAL(activated(int)), this, SLOT(updateButtonStates())); qButtonDebug() << Q_FUNC_INFO << "successfully connected to Navigator. fd =" << m_fd; }
QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const { QList<QBluetoothAddress> devices; QDir bluetoothDevices(QStringLiteral("/pps/services/bluetooth/remote_devices/")); QStringList allFiles = bluetoothDevices.entryList(QDir::NoDotAndDotDot| QDir::Files); for (int i = 0; i < allFiles.size(); i++) { qCDebug(QT_BT_QNX) << allFiles.at(i); int fileId; const char *filePath = QByteArray("/pps/services/bluetooth/remote_devices/").append(allFiles.at( i).toUtf8().constData()) .constData(); if ((fileId = qt_safe_open(filePath, O_RDONLY)) == -1) { qCWarning(QT_BT_QNX) << "Failed to open remote device file"; } else { pps_decoder_t ppsDecoder; pps_decoder_initialize(&ppsDecoder, 0); QBluetoothAddress deviceAddr; QString deviceName; if (!ppsReadRemoteDevice(fileId, &ppsDecoder, &deviceAddr, &deviceName)) { pps_decoder_cleanup(&ppsDecoder); qDebug() << "Failed to open remote device file"; } bool connectedDevice = false; int a = pps_decoder_get_bool(&ppsDecoder, "acl_connected", &connectedDevice); if (a == PPS_DECODER_OK) { if (connectedDevice) devices.append(deviceAddr); } else if (a == PPS_DECODER_BAD_TYPE) { qCDebug(QT_BT_QNX) << "Type missmatch"; } else { qCDebug(QT_BT_QNX) << "An unknown error occurred while checking connected status."; } pps_decoder_cleanup(&ppsDecoder); } } return devices; }
bool QPpsObject::open(QPpsObject::OpenModes mode) { Q_D(QPpsObject); // reset last error d->error = EOK; // abort if file already open if (isOpen()) { d->error = EBUSY; return false; } // convert pps flags to open flags int oflags = 0; if ((mode & QPpsObject::Publish) && (mode & QPpsObject::Subscribe)) oflags |= O_RDWR; else if (mode & QPpsObject::Publish) oflags |= O_WRONLY; else if (mode & QPpsObject::Subscribe) oflags |= O_RDONLY; if (mode & QPpsObject::Create) oflags |= O_CREAT | O_EXCL; if (mode & QPpsObject::DeleteContents) oflags |= O_TRUNC; // open pps file d->fd = qt_safe_open(d->path.toUtf8().data(), oflags, 0666); if (d->fd == -1) { d->error = errno; return false; } // wire up socket notifier to know when reads are ready d->notifier = new QSocketNotifier(d->fd, QSocketNotifier::Read, this); d->notifier->setEnabled(d->readyReadEnabled); QObject::connect(d->notifier, &QSocketNotifier::activated, this, &QPpsObject::readyRead); return true; }
QVariant ppsRemoteDeviceStatus(const QByteArray &address, const char *property) { int rmFD; char buf[ppsBufferSize]; QByteArray filename = btRemoteDevFDPath; filename.append(address); if ((rmFD = qt_safe_open(filename.constData(), O_RDONLY)) < 0) { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "failed to open "<< btRemoteDevFDPath << address; return false; } QVariant res; qt_safe_read(rmFD, &buf, sizeof(buf)); pps_decoder_t ppsDecoder; pps_decoder_initialize(&ppsDecoder, 0); if (pps_decoder_parse_pps_str(&ppsDecoder, buf) == PPS_DECODER_OK) { pps_decoder_push(&ppsDecoder, 0); //Find out about the node type pps_node_type_t nodeType = pps_decoder_type(&ppsDecoder, property); if (nodeType == PPS_TYPE_STRING) { const char *dat; pps_decoder_get_string(&ppsDecoder,property,&dat); res = QString::fromUtf8(dat); } else if (nodeType == PPS_TYPE_BOOL) { bool dat; pps_decoder_get_bool(&ppsDecoder,property,&dat); res = QVariant(dat); } else { qCDebug(QT_BT_QNX) << "RDStatus: No node type" << property; } } pps_decoder_cleanup(&ppsDecoder); qt_safe_close(rmFD); return res; }
static QNetworkConfiguration::BearerType cellularStatus() { QNetworkConfiguration::BearerType ret = QNetworkConfiguration::BearerUnknown; int cellularStatusFD; if ((cellularStatusFD = qt_safe_open(cellularStatusFile, O_RDONLY)) == -1) { qWarning() << "failed to open" << cellularStatusFile; return ret; } char buf[2048]; if (qt_safe_read(cellularStatusFD, &buf, sizeof(buf)) == -1) { qWarning() << "read from PPS file failed:" << strerror(errno); qt_safe_close(cellularStatusFD); return ret; } pps_decoder_t ppsDecoder; if (pps_decoder_initialize(&ppsDecoder, buf) != PPS_DECODER_OK) { qWarning("failed to initialize PPS decoder"); qt_safe_close(cellularStatusFD); return ret; } pps_decoder_error_t err; if ((err = pps_decoder_push(&ppsDecoder, 0)) != PPS_DECODER_OK) { qWarning() << "pps_decoder_push failed" << err; pps_decoder_cleanup(&ppsDecoder); qt_safe_close(cellularStatusFD); return ret; } if (!pps_decoder_is_integer(&ppsDecoder, "network_technology")) { qWarning("field has not the expected data type"); pps_decoder_cleanup(&ppsDecoder); qt_safe_close(cellularStatusFD); return ret; } int type; if (!pps_decoder_get_int(&ppsDecoder, "network_technology", &type) == PPS_DECODER_OK) { qWarning("could not read bearer type from PPS"); pps_decoder_cleanup(&ppsDecoder); qt_safe_close(cellularStatusFD); return ret; } switch (type) { case 0: // 0 == NONE break; // unhandled case 1: // fallthrough, 1 == GSM case 4: // 4 == CDMA_1X ret = QNetworkConfiguration::Bearer2G; break; case 2: // 2 == UMTS ret = QNetworkConfiguration::BearerWCDMA; break; case 8: // 8 == EVDO ret = QNetworkConfiguration::BearerEVDO; break; case 16: // 16 == LTE ret = QNetworkConfiguration::BearerLTE; break; default: qWarning() << "unhandled bearer type" << type; break; } pps_decoder_cleanup(&ppsDecoder); qt_safe_close(cellularStatusFD); return ret; }
inline QStorageIterator::QStorageIterator() { const int fd = qt_safe_open(pathMounted, O_RDONLY); fp = ::fdopen(fd, "r"); }
bool NativeSerialEnginePrivate::nativeOpen(QIODevice::OpenMode mode) { //here chek locked device or not this->locker.setDeviceName(this->deviceName); bool byCurrPid = false; if (this->locker.locked(&byCurrPid)) { #if defined (NATIVESERIALENGINE_UNIX_DEBUG) qDebug() << "Linux: NativeSerialEnginePrivate::nativeOpen(AbstractSerial::OpenMode mode) \n" " -> can not open the device:" << this->deviceName << "\n, because it was locked. Error! \n"; #endif return false; } int flags = (O_NOCTTY | O_NDELAY); switch (QIODevice::ReadWrite & mode) { case QIODevice::ReadOnly: flags |= (O_RDONLY); break; case QIODevice::WriteOnly: flags |= (O_WRONLY); break; case QIODevice::ReadWrite: flags |= (O_RDWR); break; default:; } //try opened serial device #if defined (NATIVESERIALENGINE_UNIX_DEBUG) qDebug() << "Linux: NativeSerialEnginePrivate::nativeOpen(AbstractSerial::OpenMode mode) \n" " -> trying to open device: " << this->deviceName << " \n"; #endif this->descriptor = qt_safe_open(this->deviceName.toLocal8Bit().constData(), flags); if (-1 == this->descriptor) { #if defined (NATIVESERIALENGINE_UNIX_DEBUG) qDebug() << "Linux: NativeSerialEnginePrivate::nativeOpen(AbstractSerial::OpenMode mode) \n" " -> function: ::open(...) returned: -1," "errno:" << errno << ". Error! \n"; #endif return false; } //here try lock device this->locker.lock(); if (!this->locker.locked(&byCurrPid)) { #if defined (NATIVESERIALENGINE_UNIX_DEBUG) qDebug() << "Linux: NativeSerialEnginePrivate::nativeOpen(AbstractSerial::OpenMode mode) \n" " -> an error occurred when locking the device:" << this->deviceName << ". Error! \n"; #endif return false; } //here try set exclusive mode #if defined (TIOCEXCL) ::ioctl(this->descriptor, TIOCEXCL); #endif if (!this->saveOldSettings()) { #if defined (NATIVESERIALENGINE_UNIX_DEBUG) qDebug() << "Linux: NativeSerialEnginePrivate::nativeOpen(AbstractSerial::OpenMode mode) \n" " -> function: saveOldSettings() returned: false. Error! \n"; #endif return false; } //Prepare other options this->prepareOtherOptions(); this->prepareTimeouts(0); if (!this->updateTermious()) { #if defined (NATIVESERIALENGINE_UNIX_DEBUG) qDebug() << "Linux: NativeSerialEnginePrivate::nativeOpen(AbstractSerial::OpenMode mode) \n" " -> function: ::updateTermious() returned: false. Error! \n"; #endif return false; } // Disable autocalculate total read interval. this->isAutoCalcReadTimeoutConstant = false; if (!this->detectDefaultCurrentSettings()) { #if defined (NATIVESERIALENGINE_UNIX_DEBUG) qDebug() << "Linux: NativeSerialEnginePrivate::nativeOpen(AbstractSerial::OpenMode mode) \n" " -> function: detectDefaultCurrentSettings() returned: false. Error! \n"; #endif return false; } #if defined (NATIVESERIALENGINE_UNIX_DEBUG) qDebug() << "Linux: NativeSerialEnginePrivate::nativeOpen(AbstractSerial::OpenMode mode) \n" " -> opened device: " << this->deviceName << " in mode: " << mode << " succesfully. Ok! \n"; #endif return true; }
QStringList QKqueueFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList *files, QStringList *directories) { QStringList p = paths; { QMutexLocker locker(&mutex); QMutableListIterator<QString> it(p); while (it.hasNext()) { QString path = it.next(); int fd; #if defined(O_EVTONLY) fd = qt_safe_open(QFile::encodeName(path), O_EVTONLY); #else fd = qt_safe_open(QFile::encodeName(path), O_RDONLY); #endif if (fd == -1) { perror("QKqueueFileSystemWatcherEngine::addPaths: open"); continue; } if (fd >= (int)FD_SETSIZE / 2 && fd < (int)FD_SETSIZE) { int fddup = fcntl(fd, F_DUPFD, FD_SETSIZE); if (fddup != -1) { ::close(fd); fd = fddup; } } fcntl(fd, F_SETFD, FD_CLOEXEC); QT_STATBUF st; if (QT_FSTAT(fd, &st) == -1) { perror("QKqueueFileSystemWatcherEngine::addPaths: fstat"); ::close(fd); continue; } int id = (S_ISDIR(st.st_mode)) ? -fd : fd; if (id < 0) { if (directories->contains(path)) { ::close(fd); continue; } } else { if (files->contains(path)) { ::close(fd); continue; } } struct kevent kev; EV_SET(&kev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_RENAME | NOTE_REVOKE, 0, 0); if (kevent(kqfd, &kev, 1, 0, 0, 0) == -1) { perror("QKqueueFileSystemWatcherEngine::addPaths: kevent"); ::close(fd); continue; } it.remove(); if (id < 0) { DEBUG() << "QKqueueFileSystemWatcherEngine: added directory path" << path; directories->append(path); } else { DEBUG() << "QKqueueFileSystemWatcherEngine: added file path" << path; files->append(path); } pathToID.insert(path, id); idToPath.insert(id, path); } } if (!isRunning()) start(); else write(kqpipe[1], "@", 1); return p; }