void BBPhoneAccount::recheckProcess() { if (NULL == m_sock) { Q_WARN("NULL socket"); return; } m_sock->write("ping"); m_sock->waitForBytesWritten(); if (!m_sock->waitForReadyRead ()) { // Start the process again m_sock->write("quit"); m_sock->waitForBytesWritten(); m_sock->deleteLater(); m_sock = NULL; QFileInfo fi("app/native/qt4srv"); if (!QProcess::startDetached (fi.absoluteFilePath ())) { Q_WARN("Failed to start process"); } else { QTimer::singleShot (1000, this, SLOT(onProcessStarted())); } } else { if (m_sock->readAll().startsWith("pong")) { m_TimerLogMessage.start (); } } }//BBPhoneAccount::recheckProcess
void BBPhoneAccount::onProcessStarted() { Q_DEBUG("Process started!"); m_sock = new QLocalSocket(this); if (NULL == m_sock) { Q_WARN("Failed to allocate local socket"); return; } m_sock->connectToServer ("qgvdial"); if (!m_sock->waitForConnected (1000)) { Q_WARN("Waiting for a second to connect to server"); QTimer::singleShot (1000, this, SLOT(onProcessStarted())); delete m_sock; m_sock = NULL; return; } Q_DEBUG("Socket connected"); if (!pingPong()) { return; } connect(m_sock, SIGNAL(readyRead()), this, SLOT(onGetNumber())); m_sock->write("getNumber"); m_TimerLogMessage.start (); }//BBPhoneAccount::onProcessStarted
BBPhoneAccount::BBPhoneAccount(QObject *parent) : IPhoneAccount(parent) #if USE_PROCESS , m_sock(NULL) #else , m_hBBPhone(NULL) , m_phoneCtx(NULL) #endif { #if USE_PROCESS QFileInfo fi("app/native/qt4srv"); if (!QProcess::startDetached (fi.absoluteFilePath ())) { Q_WARN("Failed to start process"); } else { QTimer::singleShot (1000, this, SLOT(onProcessStarted())); } m_TimerLogMessage.setSingleShot (true); m_TimerLogMessage.setInterval (1000); connect(&m_TimerLogMessage, SIGNAL(timeout()), this, SLOT(onLogMessagesTimer())); #else if (NULL == m_hBBPhone) { QFileInfo fi("app/native/libbbphone.so"); m_hBBPhone = dlopen (fi.absoluteFilePath().toLatin1().constData(), RTLD_NOW); if (NULL == m_hBBPhone) { Q_WARN("Failed to load BB Phone Qt4 library"); return; } } Q_DEBUG("bbphone lib opened"); typedef void *(*CreateCtxFn)(); CreateCtxFn fn = (CreateCtxFn) dlsym(m_hBBPhone, "createPhoneContext"); if (NULL == fn) { Q_WARN("Failed to get createPhoneContext"); return; } Q_DEBUG("Got createPhoneContext"); m_phoneCtx = fn(); if (NULL == m_phoneCtx) { Q_WARN("Get NULL from createPhoneContext"); } #endif }//BBPhoneAccount::BBPhoneAccount
/* * The needed constructor */ ProcessWrapper::ProcessWrapper(QObject *parent) : QObject(parent) { m_process = new QProcess(parent); QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.insert("LANG", "C"); env.insert("LC_MESSAGES", "C"); m_process->setProcessEnvironment(env); m_timerSingleShot = new QTimer(parent); m_timerSingleShot->setSingleShot(true); m_timer = new QTimer(parent); m_timer->setInterval(1000); connect(m_timerSingleShot, SIGNAL(timeout()), this, SLOT(onSingleShot())); connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimer())); connect(m_process, SIGNAL(started()), SLOT(onProcessStarted())); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // Align last toolbar action to the right QWidget *empty = new QWidget(this); empty->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); ui->mainToolBar->insertWidget(ui->actionMonitor, empty); // Align last action to the right in the monitor toolbar QWidget *emptyMonitor = new QWidget(this); emptyMonitor->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); ui->monitorToolBar->insertWidget(ui->actionMonitor, emptyMonitor); // Hide monitor toolbar ui->monitorToolBar->setVisible(false); // Hide graphs widget ui->graphsWidget->setVisible(false); // Set monospaced font in the monitor const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); ui->consoleText->setFont(fixedFont); // Set environment settings = new SettingsStore(CONFIG_INI); setArduinoBoard(); xmlFileName = ""; serial = NULL; // Set zoom scale of the web view float zoomScale = settings->zoomScale(); ui->webView->setZoomFactor(zoomScale); // Hide messages actionCloseMessages(); serialPortClose(); // Load blockly index loadBlockly(); // Set timer to update list of available ports updateSerialPorts(); QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(updateSerialPorts())); timer->start(5000); ui->consoleText->document()->setMaximumBlockCount(100); // Show/hide icon labels in the menu bar iconLabels(); // Set process process = new QProcess(); process->setProcessChannelMode(QProcess::MergedChannels); connect(process, SIGNAL(started()), this, SLOT(onProcessStarted())); connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onProcessOutputUpdated())); connect(process, SIGNAL(finished(int)), this, SLOT(onProcessFinished(int))); // Show opened file name in status bar connect(statusBar(), SIGNAL(messageChanged(QString)), this, SLOT(onStatusMessageChanged(QString))); // Filter events to capture backspace key ui->webView->installEventFilter(this); }