Client::Client(UVoipData* voipData, QObject *parent) : QObject(parent) , m_client() , m_voipData(voipData) { connect(&m_client, SIGNAL(connected()), this, SLOT(connected()), Qt::DirectConnection); connect(&m_client, SIGNAL(disconnected()), this, SLOT(disconnected()), Qt::DirectConnection); connect(m_voipData, SIGNAL(requestConnectChanged()), this, SLOT(attemptConnection()), Qt::DirectConnection); connect(m_voipData, SIGNAL(requestDisconnectChanged()), this, SLOT(attemptDisconnection()), Qt::DirectConnection); }
void AMGenericLinuxJoystick::onReadThreadFinished() { delete readThread_; readThread_ = 0; close(fd_); fd_ = -1; QTimer::singleShot(2000, this, SLOT(attemptConnection())); // try to keep re-connecting, if it gets plugged back in. AMErrorMon::alert(this, -1, QString("Disconnected from joystick: '%1' because of a read error. Is it possible the joystick was unplugged?").arg(deviceDescription())); emit connected(false); }
AMGenericLinuxJoystick::AMGenericLinuxJoystick(const QString &deviceIdentifier, QObject *parent) : AMJoystick(deviceIdentifier, parent) { buttonCount_ = -1; axisCount_ = -1; readThread_ = 0; fd_ = -1; qRegisterMetaType<QVector<AMGenericLinuxJoystickEvent> >(); attemptConnection(); }
void AsyncMcClientImpl::processShutdown() { DestructorGuard dg(this); switch (connectionState_) { case ConnectionState::UP: // on error, UP always transitions to ERROR state if (writeScheduled_) { // Cancel loop callback, or otherwise we might attempt to write // something while processing error state. cancelWriterCallback(); } connectionState_ = ConnectionState::ERROR; // We're already in ERROR state, no need to listen for reads. socket_->setReadCB(nullptr); // We can safely close connection, it will stop all writes. socket_->close(); /* fallthrough */ case ConnectionState::ERROR: queue_.failAllSent(isAborting_ ? mc_res_aborted : mc_res_remote_error); if (queue_.getInflightRequestCount() == 0) { // No need to send any of remaining requests if we're aborting. if (isAborting_) { queue_.failAllPending(mc_res_aborted); } // This is a last processShutdown() for this error and it is safe // to go DOWN. if (statusCallbacks_.onDown) { statusCallbacks_.onDown(isAborting_); } connectionState_ = ConnectionState::DOWN; // We don't need it anymore, so let it perform complete cleanup. socket_.reset(); // In case we still have some pending requests, then try reconnecting // immediately. if (getPendingRequestCount() != 0) { attemptConnection(); } } return; case ConnectionState::CONNECTING: // connectError is not a remote error, it's processed in connectError. case ConnectionState::DOWN: // We shouldn't have any errors while not connected. CHECK(false); } }
bool AMGenericLinuxJoystick::attemptConnection() { // Do we have a connection open already? Close the reading thread, and close the file descriptor. if(readThread_) { disconnect(readThread_, SIGNAL(finished()), this, SLOT(onReadThreadFinished())); readThread_->stop(); readThread_->wait(); delete readThread_; readThread_ = 0; close(fd_); fd_ = -1; AMErrorMon::information(this, 0, QString("Disconnected from joystick: '%1' before attempting to reconnect on '%2'").arg(deviceDescription()).arg(deviceIdentifier())); emit connected(false); } // Try opening the joystick device fd_ = open(deviceIdentifier_.toAscii().constData(), O_RDONLY | O_NONBLOCK); if(fd_ == -1) { // Failed to open. Maybe not plugged in yet? Just keep trying. We'll re-attempt in 2 seconds. QTimer::singleShot(2000, this, SLOT(attemptConnection())); return false; } // Get the number of buttons and number of axes, using special ioctl() on the file descriptor. char numAxes; ioctl(fd_, JSIOCGAXES, &numAxes); axisCount_ = numAxes; axisPositions_.resize(axisCount_); char numButtons; ioctl(fd_, JSIOCGBUTTONS, &numButtons); buttonCount_ = numButtons; buttonStates_.resize(buttonCount_); // Get the joystick description char description[256]; if(ioctl(fd_, JSIOCGNAME(sizeof(description)), description) < 0) deviceDescription_ = "Unknown"; else deviceDescription_ = QString(description); // Finally, start up the thread for reading from the joystick. readThread_ = new AMGenericLinuxJoystickThread(fd_, this); connect(readThread_, SIGNAL(finished()), this, SLOT(onReadThreadFinished())); connect(readThread_, SIGNAL(joystickEvents(QVector<AMGenericLinuxJoystickEvent>)), this, SLOT(onJoystickEvents(QVector<AMGenericLinuxJoystickEvent>))); readThread_->start(); AMErrorMon::information(this, 0, QString("Connected to joystick: '%1' on '%2'.").arg(deviceDescription()).arg(deviceIdentifier())); emit connected(true); return true; }
int main(int argc, char **argv) { char *hostname=0x00; char *svc=0x00; time_t t=0, status; if (argc < 3) { usage(argv[0]); exit(0); } hostname = argv[1]; svc=argv[2]; while((status=attemptConnection(hostname, svc)) != RV_SUCCESS) { t=time(NULL); char *err="unknown"; if(status == ERR_ERRNO) { err=strerror(errno); } else if(status == ERR_TIMEOUT) { err="timeout"; } else if(status == ERR_DNS) { err="getaddrinfo error"; } else { /* This is basically a programming error, but it should at least be able to tell us *what* programming error. */ char buf[32]; snprintf(buf, sizeof(buf)-1, "unknown: %d", status); err=buf; } assert(err != NULL); fprintf(stderr, "Failed to connect (%s) at %s", err, ctime(&t)); sleep(1); } t=time(NULL); fprintf(stderr, "Connected at %s", ctime(&t)); return(0); }
void AsyncMcClientImpl::sendCommon(McClientRequestContextBase& req) { switch (req.reqContext.serializationResult()) { case McSerializedRequest::Result::OK: incMsgId(nextMsgId_); queue_.markAsPending(req); scheduleNextWriterLoop(); if (connectionState_ == ConnectionState::DOWN) { // attempConnection may use a lot of stack memory, thus we need to run // it on a main context. folly::fibers::runInMainContext([this] { attemptConnection(); }); } return; case McSerializedRequest::Result::BAD_KEY: req.replyError(mc_res_bad_key); return; case McSerializedRequest::Result::ERROR: req.replyError(mc_res_local_error); return; } }
/* * Constructor for the Facepamphlet class, sets up the ui and starts up loginDialog. */ Facepamphlet::Facepamphlet(QWidget *parent) : QMainWindow(parent) { setupUi(this); // Setup TCPSocket tcpSocket = new QTcpSocket(this); // Connect signals relating to server connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData())); connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError))); connect(tcpSocket, SIGNAL(connected()), this, SIGNAL(socketConnected())); connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(socketError())); // Initialize login dialog loginDialog = new LoginDialog; connect(loginDialog, SIGNAL(close()), this, SLOT(close())); connect(loginDialog, SIGNAL(loginAttempt(QString, quint16)), this, SLOT(attemptConnection(QString, quint16))); connect(loginDialog, SIGNAL(loginAlias(QString)), this, SLOT(loginAlias(QString))); connect(this, SIGNAL(socketConnected()), loginDialog, SLOT(socketConnected())); connect(this, SIGNAL(socketError()), loginDialog, SLOT(socketError())); // Show login dialog loginDialog->show(); }
bool extioManager::updateInitialize(UTIME dt) { if ( !isConnected ) { comPort++; if ( comPort < 10 ) { char port[] = "\\\\.\\COM0"; port[7] = comPort + '0'; attemptConnection(port); connectionState = 1; } else { al_trace("Can't find the IO board on any com port.\r\n"); comPort = -1; connectionState = 0; return false; } powerOnTime = 0; } else { powerOnTime += dt; if ( connectionState == 1 ) { if ( powerOnTime >= ARDUINO_WAIT_TIME ) { WriteData("DMX", PACKET_SIZE); connectionState = 2; } } else if ( connectionState == 2 ) { if ( isPacketReady() ) { ReadData(inputBuffer, PACKET_SIZE); if ( inputBuffer[0] == 'O' && inputBuffer[1] == 'K' && inputBuffer[2] == '!' ) { isTalking = true; connectionState = 3; al_trace("Handshake accepted! Found the IO board on port %d.\r\n", comPort); WriteData("I", 1); // begin the input request loop } else { // abort - try another port powerOnTime = 0; isConnected = false; connectionState = 0; al_trace("The handshake was incorrect on port %d. Checking other ports.\r\n", comPort); } } else if ( powerOnTime >= ARDUINO_TIMEOUT ) { // abort - try another port powerOnTime = 0; isConnected = false; connectionState = 0; al_trace("IO board timeout on port %d. Checking other ports.\r\n", comPort); } } else if ( connectionState == 3 ) { al_trace("Do not call updateInitialize() after success!\r\n"); } } return true; }
bool AMGenericLinuxJoystick::reconnect(const QString &deviceIdentifier) { deviceIdentifier_ = deviceIdentifier; return attemptConnection(); }