int8_t STM32F7USB::notify(ManuvrMsg* active_event) { int8_t return_value = 0; switch (active_event->eventCode()) { case MANUVR_MSG_XPORT_QUEUE_RDY: read_port(); if (_accumulator.count()) { char* working_chunk = _accumulator.position(0); if (write_port((uint8_t*) working_chunk, strlen(working_chunk))) { // TODO: Fail-over timer? Disconnection signal? _accumulator.drop_position(0); } } return_value++; break; case MANUVR_MSG_SYS_BOOTLOADER: case MANUVR_MSG_SYS_REBOOT: case MANUVR_MSG_SYS_SHUTDOWN: connected(false); listening(false); TM_USBD_Stop(TM_USB_FS); // DeInit() The USB device. return_value++; break; default: return_value += ManuvrXport::notify(active_event); break; } if (local_log.length() > 0) Kernel::log(&local_log); return return_value; }
int main(int argc, char *argv[]) { QCoreApplication::addLibraryPath("app/native/plugins"); QApplication app(argc, argv); SimondConnector connector; QMLSimoneView view; QObject::connect(&view, SIGNAL(connectToServer()), &connector, SLOT(connectToServer())); QObject::connect(&view, SIGNAL(disconnectFromServer()), &connector, SLOT(disconnectFromServer())); QObject::connect(&view, SIGNAL(startRecording()), &connector, SLOT(startRecording())); QObject::connect(&view, SIGNAL(commitRecording()), &connector, SLOT(commitRecording())); QObject::connect(&view, SIGNAL(configurationChanged()), &connector, SLOT(configurationChanged())); QObject::connect(&connector, SIGNAL(connectionState(ConnectionState)), &view, SLOT(displayConnectionState(ConnectionState))); QObject::connect(&connector, SIGNAL(status(QString)), &view, SLOT(displayStatus(QString))); QObject::connect(&connector, SIGNAL(error(QString)), &view, SLOT(displayError(QString))); QObject::connect(&connector, SIGNAL(listening()), &view, SLOT(displayListening())); QObject::connect(&connector, SIGNAL(recognizing()), &view, SLOT(displayRecognizing())); QObject::connect(&connector, SIGNAL(microphoneLevel(int,int,int)), &view, SLOT(displayMicrophoneLevel(int,int,int))); QObject::connect(&connector, SIGNAL(recognized(RecognitionResultList)), &view, SLOT(recognized(RecognitionResultList))); view.show(); connector.init(); return app.exec(); }
SimondConnector::SimondConnector(QObject *parent) : QObject(parent), state(Unconnected), socket(new QSslSocket(this)), timeoutTimer(new QTimer(this)), response(new QDataStream(socket)), mic(new SoundInput(SOUND_CHANNELS, SOUND_SAMPLERATE, this)), passThroughSound(false) { connect(this, SIGNAL(connectionState(ConnectionState)), this, SLOT(setCurrentState(ConnectionState))); connect(socket, SIGNAL(readyRead()), this, SLOT(messageReceived())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError())); connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(socketError())); connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); connect(socket, SIGNAL(encrypted()), this, SLOT(connectionEstablished())); connect(socket, SIGNAL(disconnected()), this, SLOT(connectionLost())); connect(mic, SIGNAL(error(QString)), this, SIGNAL(error(QString))); connect(mic, SIGNAL(microphoneLevel(int,int,int)), this, SIGNAL(microphoneLevel(int,int,int))); connect(mic, SIGNAL(listening()), this, SLOT(startRecording())); connect(mic, SIGNAL(complete()), this, SLOT(commitRecording())); connect(mic, SIGNAL(readyRead()), this, SLOT(soundDataAvailable())); connect(timeoutTimer, SIGNAL(timeout()), this, SLOT(timeoutReached())); timeoutTimer->setSingleShot(true); timeoutTimer->setInterval(SOCKET_TIMEOUT); }
void LongPollManager::handleGotLPServer() { auto reply = qobject_cast<QNetworkReply*> (sender ()); reply->deleteLater (); if (reply->error () != QNetworkReply::NoError) { qWarning () << Q_FUNC_INFO << "error getting poll server:" << reply->errorString (); QTimer::singleShot (15000, this, SLOT (start ())); return; } const auto& data = QJson::Parser ().parse (reply); const auto& map = data.toMap () ["response"].toMap (); LPKey_ = map ["key"].toString (); LPServer_ = map ["server"].toString (); LPTS_ = map ["ts"].toULongLong (); LPURLTemplate_ = QUrl ("http://" + LPServer_); LPURLTemplate_.addQueryItem ("act", "a_check"); LPURLTemplate_.addQueryItem ("key", LPKey_); LPURLTemplate_.addQueryItem ("mode", "2"); emit listening (); Poll (); }
void runLoop ( void ) { debug(); while ( listening () ); }
bool Simonoid::connectSignalsAndSlots() { if ( m_dbusinterface == NULL ) m_dbusinterface = new QDBusInterface ( "org.kde.simon", "/SimonSender", "local.SimonSender" ); if ( m_dbusinterface == NULL ) return false; bool success = true; if ( success ) { success = connect ( m_dbusinterface, SIGNAL (listening()), this, SLOT (listeningCalled()) ); kDebug() << "connecting listening:" << ( success?"connected":"disconnected" ) ; } if ( success ) { success = connect ( m_dbusinterface, SIGNAL (processing()), this, SLOT (processingCalled()) ); kDebug() << "connecting processing:" << ( success?"connected":"disconnected" ) ; } if ( success ) { success = connect ( m_dbusinterface, SIGNAL (receivedResults()), this, SLOT (receivedResultsCalled()) ); kDebug() << "connecting receivedResults:" << ( success?"connected":"disconnected" ) ; } if ( success ) { success = connect ( m_dbusinterface, SIGNAL (recordingLevel(double)), this, SLOT (recordingLevelCalled(double)) ); kDebug() << "connecting recordingLevel:" << ( success?"connected":"disconnected" ) ; } if ( success ) { m_isconnected = true; } else { disconnectSignalsAndSlots(); } return success; }
teTCPError TCPServerConnection::disconnect( void ) { if (!listening()) return setError(eTCPSocketNFG); std::map<TCPsocket,TCPServerConnectedPeer>::iterator itr = peers.begin(); while ( itr != peers.end() ) { for ( unsigned int i = 0; i < dataPendingList.size(); i++ ) dataPendingList[i]->disconnect(this,&itr->second,true); net_TCP_Close(itr->first); net_DelSocket(socketSet,(net_GenericSocket)itr->first); } peers.clear(); net_TCP_Close(socket); net_DelSocket(socketSet,(net_GenericSocket)socket); net_FreeSocketSet(socketSet); socketSet = NULL; socket = NULL; return setError(eTCPNoError); }
/** * @brief Get the RWD identifier string * e.g. “a IDE RWD H2 (SECx V1.xx) DD/MM/YY” * * @returns True if commands could be sent to device */ bool RWDH2::getIdentifier(uint8_t* identifier) { if (listening()) { write(RWDH2_CMD_MESSAGE); return (read(identifier)); } else { return false; } }
/** * @brief Write an array of commands to the RWD and check the return is expected using a bit mask * * @param cmd Array of commands to be sent * @param mask Bit mask for the return to allow comparison with RWD_OKAY to indicate success * @param size Size of command array * @returns True if commands executed successfully */ bool RWDH2::write(uint8_t* cmd, uint8_t mask, size_t size) { if (listening()) { for (uint8_t i = 0; i < size; i++) { write(cmd[i]); } return (available() ? (((_last_ack = read()) & mask) == (RWDH2_OKAY & mask)) : false); } }
int main(int argc, char **argv) { get_options(argc, argv); int sock = listening(); daemonize(); start_workers(sock); return EXIT_SUCCESS; }
// TODO: Perhaps reset the terminal? int8_t STM32F7USB::reset() { //#if defined(__MANUVR_DEBUG) // if (getVerbosity() > 3) local_log.concatf("STM32F7USB initialized.\n"); //#endif initialized(true); listening(true); connected(true); //if (local_log.length() > 0) Kernel::log(&local_log); return 0; }
void SimondConnector::startRecording() { qDebug() << "Starting recording"; emit listening(); QByteArray body; QDataStream bodyStream(&body, QIODevice::WriteOnly|QIODevice::Unbuffered); bodyStream << (qint8) 1 /* mic id */ << mic->channels() << mic->sampleRate(); sendRequest(Simond::RecognitionStartSample, body); passThroughSound = true; }
/** * @brief Program the RWD's EEPROM with multiple bytes of data * * @param start_address Starting EEPROM memory location 0-255 * @param data An array of data to be written * @param size Size of the data array to be written * @returns True if commands could be sent to device */ bool RWDH2::writeEEPROM(uint8_t start_address, uint8_t* data, size_t size) { if (listening()) { for (uint8_t i = 0; i < size; i++) { uint8_t c[] = { RWDH2_CMD_PROGEEPROM, start_address + i, data[i] }; if (!write(c, RWDH2_PROGEEPROM_MASK, sizeof(c))) return false; } return true; } else { return false; } }
SimonSender::SimonSender() : m_state(SimonSender::Idle) { new SimonSenderAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.registerObject("/SimonSender", this); dbus.registerService("org.simon-listens.SimonSender"); connect(this, SIGNAL(processing()), this, SLOT(slotProcessing())); connect(this, SIGNAL(listening()), this, SLOT(slotListening())); connect(this, SIGNAL(receivedResults()), this, SLOT(slotReceivedResults())); connect(&loudnessTimer, SIGNAL(timeout()), this, SLOT(relayLoudness())); loudnessTimer.start(500); }
int main(int argc, char *argv[]) { QCoreApplication::addLibraryPath("app/native/plugins"); QApplication app(argc, argv); bool voiceControlled = true; SimondConnector *connector; if (voiceControlled) connector = new SimondConnector; else connector = 0; Recomment recomment; QMLRecommentView view(&recomment, voiceControlled); if (voiceControlled) { QObject::connect(&view, SIGNAL(connectToServer()), connector, SLOT(connectToServer())); QObject::connect(&view, SIGNAL(disconnectFromServer()), connector, SLOT(disconnectFromServer())); QObject::connect(&view, SIGNAL(startRecording()), connector, SLOT(startRecording())); QObject::connect(&view, SIGNAL(commitRecording()), connector, SLOT(commitRecording())); QObject::connect(&view, SIGNAL(configurationChanged()), connector, SLOT(configurationChanged())); QObject::connect(connector, SIGNAL(connectionState(ConnectionState)), &view, SLOT(displayConnectionState(ConnectionState))); QObject::connect(connector, SIGNAL(status(QString)), &view, SLOT(displayStatus(QString))); QObject::connect(connector, SIGNAL(error(QString)), &view, SLOT(displayError(QString))); QObject::connect(connector, SIGNAL(listening()), &view, SLOT(displayListening())); QObject::connect(connector, SIGNAL(recognizing()), &view, SLOT(displayRecognizing())); QObject::connect(connector, SIGNAL(microphoneLevel(int,int,int)), &view, SLOT(displayMicrophoneLevel(int,int,int))); //QObject::connect(connector, SIGNAL(recognized(QString)), &view, SLOT(displayExecutedAction(QString))); QObject::connect(connector, SIGNAL(recognized(QString)), &recomment, SLOT(critique(QString))); } QObject::connect(&recomment, SIGNAL(recommend(const Offer*, QString)), &view, SLOT(displayRecommendation(const Offer*, QString))); QObject::connect(&recomment, SIGNAL(noMatchFor(QString)), &view, SLOT(displayNoMatch(QString))); view.show(); if (voiceControlled) connector->init(); if (!recomment.init()) { qWarning() << "Failed to initialize Recomment; Aborting"; return -1; } int ret = app.exec(); delete connector; return ret; }
//Setups timer configurations and listens for keyboard in signals intervals int startTimer(Ship *ship, FILE *sketch, iArgs input, int * c) { struct sigaction handler; tship = ship; inp = input; sket = sketch; move(7,10); // handle_timeout is function to call when signal is sent handler.sa_handler = handle_timeout; sigemptyset( &handler.sa_mask ); handler.sa_flags = 0; // use signal handler defined in handler to handle SIGALRM signals if( sigaction( SIGALRM, &handler, NULL ) < 0 ) { exit( EXIT_FAILURE ); } // set up timer (sends SIGLARM) struct itimerval timer; // value for time until first SIGALRM timer.it_value.tv_sec = 0; // 0 in the example lander program timer.it_value.tv_usec = 50000; // 50000 in the example lander program // interval between subsequent alarms timer.it_interval.tv_sec = 0; // 0 in the example lander program timer.it_interval.tv_usec = 50000; // 50000 in the example lander program // will execute repeatedly, sending SIGALRM every timer.it_interval // seconds/microseconds, with an inital delay of timer.it_value. if( setitimer( ITIMER_REAL, &timer, NULL ) < 0 ) { exit( EXIT_FAILURE ); } // loop until we're done while( !g_finished ) { g_finished = listening(ship, sketch, input, c); } return( EXIT_SUCCESS ); }
void FileTransferServer::startListening() { m_server = new QTcpServer(); connect(m_server, SIGNAL(newConnection()), this, SLOT(addNewClient())); for (quint16 i = MIN_PORT; i<MAX_PORT; ++i) { if (m_server->listen(QHostAddress::Any, i)) { qDebug() << i; m_state = LISTENING; m_port = i; m_file = new QFile(m_fileName); emit listening(); return; } else qDebug() << "Cannot bind port " << i; } exit(1); }
NetworkControl::NetworkControl() { client = new Client(); QObject::connect(client, SIGNAL(connected()), this, SLOT(onConnected())); QObject::connect(client, SIGNAL(hostFound()), this, SLOT(onHostFound())); QObject::connect(client, SIGNAL(loggingIn()), this, SLOT(onLoggingIn())); QObject::connect(client, SIGNAL(successfullJoin()), this, SLOT(onConnectionAccepted())); QObject::connect(client, SIGNAL(disconnected()), this, SLOT(onDisconnected())); QObject::connect(client, SIGNAL(presentationReceived(QString, QList<QImage>)), this, SLOT(onPresentationReceived(QString, QList<QImage>))); server = new Server(); QObject::connect(server, SIGNAL(listening()), this, SLOT(onStarted())); QObject::connect(server, SIGNAL(connectionAccepted()), this, SLOT(onClientConnected())); QObject::connect(server, SIGNAL(clientVerified()), this, SLOT(onClientVerified())); QObject::connect(server, SIGNAL(clientLeft()), this, SLOT(onClientLeft())); QObject::connect(server, SIGNAL(closing()), this, SLOT(onClosed())); }
void KeyboardNode::inputsUpdated( qint64 pTimeStamp ) { Q_UNUSED( pTimeStamp ) fugio::KeyboardInterface *Keyboard = input<fugio::KeyboardInterface *>( mPinKeyboard ); if( !Keyboard ) { return; } for( fugio::KeyboardEvent KeyEvt : Keyboard->keyboardEvents() ) { const QString S = KeyEvt.mText; const QString K = S.isEmpty() || KeyEvt.mCode == Qt::Key_Space ? keyToString( KeyEvt.mCode ) : S.toUpper(); QSharedPointer<fugio::PinInterface> P = mNode->findOutputPinByName( K ); if( P && P->hasControl() ) { fugio::VariantInterface *V = qobject_cast<fugio::VariantInterface *>( P->control()->qobject() ); if( V ) { V->setVariant( KeyEvt.mType == fugio::KeyboardEvent::PRESS ); pinUpdated( P ); } } else if( mListening ) { QSharedPointer<fugio::PinInterface> NewPin; mNode->createPin( K, PIN_OUTPUT, QUuid::createUuid(), NewPin, PID_BOOL ); mListening = false; emit listening( false ); } } }
void Server::run(int port) throw (SocketException) { listening(port); std::cout << "server awaiting connections..." << std::endl; while (true) { SOCKET client = accept(listen, NULL, NULL); std::cout << "accepted client" << std::endl; SocketStream stream(client); // read the dynaTrace tag (if present) and set it unsigned char length = stream.getByte(); // if length != 0, the message contains a dynaTrace tag if (length != 0) { unsigned char tag[256]; stream.get(tag, length); DYNATRACE_SET_TAG(tag); } // reading "payload" long long a = stream.getInt64(); long long b = stream.getInt64(); // no dynaTrace tag was sent => we assume that the data itself were used as "custom tag" if (length == 0) { unsigned char customTag[CTAG_SIZE]; MultiAppNative::getCustomTagFromData(customTag, a, b); DYNATRACE_SET_CUSTOMTAG(customTag, sizeof(customTag)); } // start server-side PurePath DYNATRACE_START_SERVER_PUREPATH(); long long r = multiply(a, b); std::cout << a << "*" << b << "=" << r << std::endl; stream.putInt64(r); // end server-side PurePath DYNATRACE_END_SERVER_PUREPATH(); } }
// Function responsible of listening on a socket. inline bool TCPSocket::listen() { bool return_value = false; lock_ref().enter(); if ( socket_ref() != NULL && bound() ) { if ( ::listen(socket_ref(),_queue_size) == 0 ) { listening(true); return_value = true; } } lock_ref().leave(); return return_value; };
int listener::listen() { if (listening()) { return e_busy; } ll_sys_failed_return(_fd = ::socket(AF_INET, SOCK_STREAM, 0)); auto guard = make_guard([this](){ _fd.close(); }); int n = 1; ll_sys_failed_return(::setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(int))); ll_sys_failed_return(::bind(_fd, _addr, _addr.length())); ll_sys_failed_return(::listen(_fd, _backlog)); ll_failed_return(_reactor->open(_fd, reactor::poll_in | reactor::poll_err, &listener::accept_handler, this)); guard.dismiss(); if (ll_failed(do_emit(_fd, reactor::poll_open, _addr))) { close(); return fail; } return ok; }
void feed(struct info* inf, std::ifstream &f, std::ofstream& of){ std::string ligne; //int type, ref ,idp, rw, add, id, node, node_d; int end_epoc; struct msg req; inf->cpt_end_epoc=0; while(end_epoc != 2){ f >> req.type >> req.ref >> req.idp >> req.rw >> req.add >> req.id >> req.node >> req.node_d >> end_epoc; if(req.rw == 0){ req.rw = R; } else if(req.rw == 1){ req.rw = W; } else{ req.rw = RW; } if(req.type == 1){//end_child req inf->cpt_end_epoc++; req.type = END_CHILD; inf->cn.handle_endChild2(&req); } else if(req.type == 0){ req.type = REQUEST; inf->cn.add(&req); } else{return;} if(end_epoc == 1){ listening(inf, of); inf->cpt_end_epoc=0; continue; } } }
NetworkControl::NetworkControl(PresentationControl* p) { pc = p; QObject::connect(pc, SIGNAL(presentationChanged()), this, SLOT(onPresentationChanged())); QThread* networkThread = new QThread(); client = new Client(); QObject::connect(client, SIGNAL(currentPageReceived(qint64)), pc, SLOT(onCurrenPageChanged(qint64))); QObject::connect(client, SIGNAL(connected()), this, SLOT(onConnected())); QObject::connect(client, SIGNAL(hostFound()), this, SLOT(onHostFound())); QObject::connect(client, SIGNAL(loggingIn()), this, SLOT(onLoggingIn())); QObject::connect(client, SIGNAL(successfullJoin()), this, SLOT(onConnectionAccepted())); QObject::connect(client, SIGNAL(disconnected()), this, SLOT(onDisconnected())); QObject::connect(client, SIGNAL(presentationReceived(QString, QList<QImage>)), this, SLOT(onPresentationReceived(QString, QList<QImage>))); server = new Server(); server->setPresentation(p->getPresentation()); QObject::connect(server, SIGNAL(listening()), this, SLOT(onStarted())); QObject::connect(server, SIGNAL(connectionAccepted()), this, SLOT(onClientConnected())); QObject::connect(server, SIGNAL(clientVerified()), this, SLOT(onClientVerified())); QObject::connect(server, SIGNAL(clientLeft()), this, SLOT(onClientLeft())); QObject::connect(server, SIGNAL(closing()), this, SLOT(onClosed())); }
void SimonSender::startSampleToRecognize(qint8 id, qint8 channels, qint32 sampleRate) { emit listening(); startSampleToRecognizePrivate(id, channels, sampleRate); }
void LongPollManager::handlePollFinished () { auto reply = qobject_cast<QNetworkReply*> (sender ()); reply->deleteLater (); if (reply->error () != QNetworkReply::NoError) { ++PollErrorCount_; qWarning () << Q_FUNC_INFO << "network error:" << reply->error () << reply->errorString () << "; error count:" << PollErrorCount_; switch (reply->error ()) { case QNetworkReply::RemoteHostClosedError: { const auto diff = LastPollDT_.secsTo (QDateTime::currentDateTime ()); const auto newTimeout = std::max ((diff + WaitTimeout_) / 2 - 1, 5); qWarning () << Q_FUNC_INFO << "got timeout with" << WaitTimeout_ << diff << "; new timeout:" << newTimeout; WaitTimeout_ = newTimeout; break; } default: if (PollErrorCount_ == 4) emit pollError (); break; } Poll (); return; } else if (PollErrorCount_) { qDebug () << Q_FUNC_INFO << "finally successful network reply after" << PollErrorCount_ << "errors"; PollErrorCount_ = 0; emit listening (); } const auto& data = QJson::Parser ().parse (reply); const auto& rootMap = data.toMap (); if (rootMap.contains ("failed")) { ForceServerRequery (); start (); return; } emit gotPollData (rootMap); LPTS_ = rootMap ["ts"].toULongLong (); if (!ShouldStop_) { if (!LPServer_.isEmpty ()) Poll (); else start (); } else emit stopped (); }
int main(void) { conn *Conn; Conn = listening(); process_pkts(Conn); return EXIT_SUCCESS; }
int8_t STM32F7USB::listen() { // STM32F7USB, if instantiated, is ALWAYS listening. listening(true); return 0; }
int8_t StandardIO::listen() { // StandardIO, if instantiated, is ALWAYS listening. listening(true); return 0; }
int main() { ILog("Info"); vixMntIPC_InitMmap(0x100, 0); const char msg[12] = "mmap test 1"; size_t msg_len = strlen(msg); char *buf = new char[msg_len]; /* * test same process whether mmap is works vixMntIPC_WriteMmap(msg,0,msg_len); vixMntIPC_ReadMmap(buf,0,msg_len); vixMntIPC_CleanMmap(); ILog("buf len %d -- (%s)",msg_len,buf); printf("%s\n",buf); */ /* * test mmap between two processes */ sem_t *semaphore = sem_open("/sema", O_CREAT, 0777, 0); pid_t pid = fork(); if (!pid) { vixMntIPC_WriteMmap(msg, 10, msg_len); sem_post(semaphore); sem_close(semaphore); exit(0); } sem_wait(semaphore); vixMntIPC_ReadMmap(buf, 10, msg_len); sem_close(semaphore); sem_unlink("/sema"); vixMntIPC_CleanMmap(); ILog("buf len %d -- (%s)", msg_len, buf); delete[] buf; pthread_t pid_t = listening(); pthread_t pid_t2 = listening(); VixMntMsgQue *msgque = VixMntMsgQue::getMsgQueInstance(); ILog("size of msgque instance %u", sizeof(*msgque)); VixMntMsgQue *msgque2 = new VixMntMsgQue("/test2"); VixMntMsgQue *msgque3 = new VixMntMsgQue("/test3"); ILog("size of msgque instance %u", sizeof(VixMntMsgQue)); delete msgque3; delete msgque2; if (!pid_t) { ELog("error goto clean"); goto clean; } /* * TODO : * will received ERROR when send HALT */ msgque->sendMsgOp(VixMntOp(MntInit)); msgque->sendMsgOp(VixMntOp(MntWrite)); msgque->sendMsgOp(VixMntOp(MntReadDone)); msgque->sendMsgOp(VixMntOp(MntRead)); msgque->sendMsgOp(VixMntOp(HALT)); msgque->sendMsgOp(VixMntOp(HALT)); // sleep(4); pthread_join(pid_t, NULL); pthread_join(pid_t2, NULL); msgque->unlink(); VixMntMsgQue::releaseMsgQueInstance(); clean: ILog("end all"); return 0; }