void HVSTGFX::CAnimationTrigger::update(CAnimation * frames) { //check animationEnd if (frames->frameCount == frames->getNumofFrames()) signalHandler(_events[0]); else if (frames->frameCount == 0) signalHandler(_events[1]); }
SourcePortItem::SourcePortItem(QString itemName, bool isInApp, bool editOnStart, Application *app, BuilderItem *parent) : BuilderItem(parent) { itemType = SourcePortItemType; this->itemName = itemName; portAvailable = false; errorState = false; sigHandler = new ItemSignalHandler((QGraphicsItem*)this,SourcePortItemType,nullptr); pressed = false; moved = false; this->nestedInApp = isInApp; this->parent = parent; this->app = app; QFontMetrics fontMetric(font); int textWidth = fontMetric.width(itemName); prepareGeometryChange(); mainRect = QRectF(-((2*PORT_TEXT_WIDTH) + textWidth)/2,-16,(2*PORT_TEXT_WIDTH) + textWidth,32); boundingR = QRectF(mainRect); setToolTip(itemName); setFlag(ItemIsMovable,!isInApp); setFlag(ItemIsSelectable,true); setFlag(ItemSendsGeometryChanges,true); if(!isInApp){ QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(); effect->setColor(QColor(80,80,80,80)); effect->setBlurRadius(5); setGraphicsEffect(effect); } allowInputs = false; allowOutputs = true; lineEditWidget = new QGraphicsProxyWidget(this); QLineEdit *lineEdit = new QLineEdit(); QObject::connect(lineEdit,SIGNAL(editingFinished()),signalHandler(),SLOT(onEditingFinished())); QObject::connect(lineEdit,SIGNAL(returnPressed()),signalHandler(),SLOT(onEditingFinished())); lineEdit->setText(itemName); lineEditWidget->setWidget(lineEdit); if(editOnStart){ lineEditWidget->setVisible(true); }else{ lineEditWidget->setVisible(false); } QRectF geo = lineEditWidget->geometry(); geo.setWidth(textWidth); lineEditWidget->setGeometry(geo); lineEditWidget->setPos(-textWidth/2,-lineEditWidget->geometry().height()/2); }
int main( int i_argc, char **ppch_argv ) { /* Return value */ signed char c_retValue; long l_argc; opt_t str_args; l_argc = i_argc; /* if sizeof(int) != sizeof(long) */ c_retValue = 0; /* Parse args using getopt to fill a struct (args), return < 0 if problem encountered */ if ( argumentManagement( l_argc, ppch_argv, &str_args ) > 0 ) { /* We turn on the signal handler */ signalHandler(); /* perform RARP requests as wanted by user (using args struct) */ c_retValue = performRequests(&str_args); } else { /* If any problem occured, explain the user how to build his command line */ usage(); /* and exit < 0 */ c_retValue = -1; } /* Simple exit point */ return c_retValue; }
void onData( ndn::Face &face, const ndn::Interest& interest, ndn::Data& data, int globalReference, int localReference, int patternId, boost::posix_time::ptime sentTime ) { double roundTripTime; int receivedContentLength; std::string receivedContent; std::string logLine; logLine = ""; logLine += "Data Received - PatternType="+toString(patternId+1); logLine += ", GlobalID="+toString(globalReference); logLine += ", LocalID="+toString(localReference); logLine += ", Name="+interest.getName().toUri(); boost::posix_time::time_duration roundTripDuration; totalInterestReceived_++; trafficPattern_[patternId].totalInterestReceived++; if (trafficPattern_[patternId].expectedContent != "") { receivedContent = (char*)(data.getContent().value()); receivedContentLength = data.getContent().value_size(); receivedContent = receivedContent.substr(0, receivedContentLength); if (receivedContent != trafficPattern_[patternId].expectedContent) { contentInconsistencies_++; trafficPattern_[patternId].contentInconsistencies++; logLine += ", IsConsistent=No"; } else logLine += ", IsConsistent=Yes"; } else logLine += ", IsConsistent=NotChecked"; m_logger.log(logLine, true, false); roundTripDuration = boost::posix_time::microsec_clock::local_time() - sentTime; roundTripTime = roundTripDuration.total_microseconds()/1000.0; if (minimumInterestRoundTripTime_ > roundTripTime) minimumInterestRoundTripTime_ = roundTripTime; if (maximumInterestRoundTripTime_ < roundTripTime) maximumInterestRoundTripTime_ = roundTripTime; if (trafficPattern_[patternId].minimumInterestRoundTripTime > roundTripTime) trafficPattern_[patternId].minimumInterestRoundTripTime = roundTripTime; if (trafficPattern_[patternId].maximumInterestRoundTripTime < roundTripTime) trafficPattern_[patternId].maximumInterestRoundTripTime = roundTripTime; totalInterestRoundTripTime_ += roundTripTime; trafficPattern_[patternId].totalInterestRoundTripTime += roundTripTime; if (totalInterestSent_ == interestCount_) signalHandler(); }
void CTimerTrigger::update() { if (_timerRef->getStarted() && !_timerRef->getPaused()) { _timerRef->tick(); if (_timerRef->getCurrentTick() >= _timerRef->getTicks()) { signalHandler(_events[0]); delete _timerRef; } } }
void onTimeout( ndn::Face &face, const ndn::Interest& interest, int globalReference, int localReference, int patternId) { std::string logLine; logLine = ""; logLine += "Interest Timed Out - PatternType="+toString(patternId+1); logLine += ", GlobalID="+toString(globalReference); logLine += ", LocalID="+toString(localReference); logLine += ", Name="+interest.getName().toUri(); m_logger.log(logLine, true, false); if (totalInterestSent_ == interestCount_) signalHandler(); }
void SourcePortItem::editingFinished() { QString text = ((QLineEdit*)lineEditWidget->widget())->text(); for (int i=0;i<scene()->items().count();i++){ QGraphicsItem *it = scene()->items().at(i); if((it->type() == QGraphicsItem::UserType + DestinationPortItemType || it->type() == QGraphicsItem::UserType + SourcePortItemType) && (it != this)){ if(((SourcePortItem*)it)->getItemName() == text){ ((QLineEdit*)lineEditWidget->widget())->setStyleSheet("QLineEdit { background-color: red;}"); ((QLineEdit*)lineEditWidget->widget())->setToolTip(tr("Duplicate Entry")); allowOutputs = false; errorState = true; return; } } } errorState = false; allowOutputs = true; ((QLineEdit*)lineEditWidget->widget())->setStyleSheet("QLineEdit {background-color: white;}"); ((QLineEdit*)lineEditWidget->widget())->setToolTip(""); this->itemName = text; lineEditWidget->setVisible(false); QFontMetrics fontMetric(font); int textWidth = fontMetric.width(itemName); prepareGeometryChange(); mainRect = QRectF(-((2*PORT_TEXT_WIDTH) + textWidth)/2,-15,(2*PORT_TEXT_WIDTH) + textWidth,30); boundingR = QRectF(mainRect); setToolTip(itemName); QRectF geo = lineEditWidget->geometry(); geo.setWidth(textWidth); lineEditWidget->setGeometry(geo); lineEditWidget->setPos(-textWidth/2,-lineEditWidget->geometry().height()/2); emit signalHandler()->modified(); update(); updateConnections(); updateConnectionsFrom(this->itemName); }
void run() { std::cout << "\n=== File Sender " << m_prefix <<" ===\n" << std::endl; boost::asio::signal_set signalSet(m_ioService, SIGINT, SIGTERM); signalSet.async_wait(bind([this]() { signalHandler(); })); m_name = m_prefix; m_face.setInterestFilter(m_name, bind(&NdnTlvFileSender::onInterest, this, _2), bind(&NdnTlvFileSender::onRegisterFailed, this, _1,_2)); try { m_face.processEvents(); } catch (std::exception& e) { std::cerr << "ERROR: " << e.what() << std::endl; m_hasError = true; m_ioService.stop(); } }
int test1_signals() { // Shortcut typedefs typedef boost::signals2::signal<void()> registration_manager; typedef registration_manager::slot_type registration_request; // Define the signal handler registration_manager signalHandler; // Connect the above methods to this handler signalHandler.connect( &no_arguments ); signalHandler.connect( &no_arguments_2 ); // Call the handlers signalHandler(); // Output should be: // No arguments // No arguments 2 return 0; }
int main() { // Shortcut typedefs typedef boost::signals2::signal<void(double)> registration_manager; typedef registration_manager::slot_type registration_request; // Define the signal handler registration_manager signalHandler; // Connect the above methods to this handler signalHandler.connect( &argument ); // Defined above signalHandler.connect( &argument_2 ); // Defined above // Call the handlers signalHandler( 3.14 ); // Output should be: // Arguments 3.14 // Half argument 1.57 return 0; }
int main(int argc, const char **argv){ signalHandler(0); for(int i = 0; i<4; i++) signalReceived[i] = 0; if(argc < 5){ usage(argv[0]); return 0; } Uint32 noOfConnections = 0; const char * progName = argv[0]; const char * type = argv[1]; const NodeId localNodeId = atoi(argv[2]); const char * localHostName = argv[3]; const char * remoteHost1 = argv[4]; const char * remoteHost2 = NULL; if(argc == 5) noOfConnections = 1; else { noOfConnections = 2; remoteHost2 = argv[5]; } if(localNodeId < 1 || localNodeId > 3){ ndbout << "localNodeId = " << localNodeId << endl << endl; usage(progName); return 0; } ndbout << "-----------------" << endl; ndbout << "localNodeId: " << localNodeId << endl; ndbout << "localHostName: " << localHostName << endl; ndbout << "remoteHost1 (node " << (localNodeId == 1?2:1) << "): " << remoteHost1 << endl; if(noOfConnections == 2){ ndbout << "remoteHost2 (node " << (localNodeId == 3?2:3) << "): " << remoteHost2 << endl; } ndbout << "-----------------" << endl; void * confTemplate = 0; CreateTransporterFunc func = 0; if(strcasecmp(type, "tcp") == 0){ func = createTCPTransporter; confTemplate = &tcpTemplate; } else if(strcasecmp(type, "sci") == 0){ func = createSCITransporter; confTemplate = &sciTemplate; } else if(strcasecmp(type, "shm") == 0){ func = createSHMTransporter; confTemplate = &shmTemplate; } else { ndbout << "Unsupported transporter type" << endl; return 0; } ndbout << "Creating transporter registry" << endl; tReg = new TransporterRegistry; tReg->init(localNodeId); switch(localNodeId){ case 1: (* func)(confTemplate, 1, 2, localHostName, remoteHost1); if(noOfConnections == 2) (* func)(confTemplate, 1, 3, localHostName, remoteHost2); break; case 2: (* func)(confTemplate, 2, 1, localHostName, remoteHost1); if(noOfConnections == 2) (* func)(confTemplate, 2, 3, localHostName, remoteHost2); break; case 3: (* func)(confTemplate, 3, 1, localHostName, remoteHost1); if(noOfConnections == 2) (* func)(confTemplate, 3, 2, localHostName, remoteHost2); break; } ndbout << "Doing startSending/startReceiving" << endl; tReg->startSending(); tReg->startReceiving(); ndbout << "Connecting" << endl; tReg->setPerformState(PerformConnect); tReg->checkConnections(); unsigned sum = 0; do { sum = 0; for(int i = 0; i<4; i++) sum += signalReceived[i]; tReg->checkConnections(); tReg->external_IO(500); NdbSleep_MilliSleep(500); ndbout << "In main loop" << endl; } while(sum != 2*noOfConnections); ndbout << "Doing setPerformState(Disconnect)" << endl; tReg->setPerformState(PerformDisconnect); ndbout << "Doing checkConnections()" << endl; tReg->checkConnections(); ndbout << "Sleeping 3 secs" << endl; NdbSleep_SecSleep(3); ndbout << "Deleting transporter registry" << endl; delete tReg; tReg = 0; return 0; }
int main(int argc, const char **argv){ const char * progName = argv[0]; loopCount = 100; sendBufSz = -1; recvBufSz = -1; isClient = false; isConnected = false; isStarted = false; currentPhase = 0; signalHandler(0); if(argc < 5){ usage(progName); return 0; } const char * type = argv[1]; const NodeId localNodeId = atoi(argv[2]); const char * localHostName = argv[3]; const char * remoteHost1 = argv[4]; if(argc >= 6) loopCount = atoi(argv[5]); if(argc >= 7) sendBufSz = atoi(argv[6]); if(argc >= 8) recvBufSz = atoi(argv[7]); if(localNodeId < 1 || localNodeId > 2){ ndbout << "localNodeId = " << localNodeId << endl << endl; usage(progName); return 0; } if(localNodeId == 1) ndbout << "-- ECHO CLIENT --" << endl; else ndbout << "-- ECHO SERVER --" << endl; ndbout << "localNodeId: " << localNodeId << endl; ndbout << "localHostName: " << localHostName << endl; ndbout << "remoteHost1 (node " << (localNodeId == 1?2:1) << "): " << remoteHost1 << endl; ndbout << "Loop count: " << loopCount << endl; ndbout << "-----------------" << endl; void * confTemplate = 0; CreateTransporterFunc func = 0; if(strcasecmp(type, "tcp") == 0){ func = createTCPTransporter; confTemplate = &tcpTemplate; } else if(strcasecmp(type, "sci") == 0){ func = createSCITransporter; confTemplate = &sciTemplate; } else if(strcasecmp(type, "shm") == 0){ func = createSHMTransporter; confTemplate = &shmTemplate; } else { ndbout << "Unsupported transporter type" << endl; return 0; } ndbout << "Creating transporter registry" << endl; tReg = new TransporterRegistry; tReg->init(localNodeId); switch(localNodeId){ case 1: (* func)(confTemplate, 1, 2, localHostName, remoteHost1, sendBufSz, recvBufSz); break; case 2: (* func)(confTemplate, 2, 1, localHostName, remoteHost1, sendBufSz, recvBufSz); break; } ndbout << "Doing startSending/startReceiving" << endl; tReg->startSending(); tReg->startReceiving(); ndbout << "Connecting" << endl; tReg->setPerformState(PerformConnect); tReg->checkConnections(); if(localNodeId == 1) client(2); else server(); isStarted = false; ndbout << "Sleep 3 secs" << endl; NdbSleep_SecSleep(3); ndbout << "Doing setPerformState(Disconnect)" << endl; tReg->setPerformState(PerformDisconnect); ndbout << "Doing checkConnections()" << endl; tReg->checkConnections(); ndbout << "Deleting transporter registry" << endl; delete tReg; tReg = 0; return 0; }
static void* command_thread(void* unused) { lList words; lInit(&words, NULL); (void)unused; INIT_INPUT; while(1) { char* command; void* remember; char* newline; INPUT_DECLARE; lDestroy(&words, free); if(READ_INPUT("Enter a command: ") == NULL) break; if((newline = strchr(input, '\n')) != NULL) *newline = '\0'; getWords(&words, input); command = (char*)lGet(&words, FIRST, &remember); //LOG_DEBUG("Command: %s\n", command); if(!strcmp(command, ".") || !strcmp(command, "quit") || !strcmp(command, "q") || !strcmp(command, "exit")) { //LOG("\n"); break; } /* * Command: send (client) (filename) */ else if(!strcmp(command, "send") || !strcmp(command, "snd")) /* Send a file directly to a client */ { ERROR_ENOUGH_ARGUMENTS(3); char* who = NEXT_WORD; char* filename = NEXT_WORD; nlServerSendFile(who, filename); WARN_TOO_MUCH_ARGUMENTS(3); } else if(!strcmp(command, "wget")) /* Tell a client to download a file at the given URL */ { ERROR_ENOUGH_ARGUMENTS(4); /* Example: */ char* who = NEXT_WORD; /* who: Client */ char* address = NEXT_WORD; /* address: http://some_site.org/some_file.tar.gz */ char* where = NEXT_WORD; /* where: pouet.tgz */ nlServerSendMessage(who, "W %s$%s", address, where); WARN_TOO_MUCH_ARGUMENTS(4); } else if(!strcmp(command, "ip")) /* Get our ip */ { LOG("LAN IP: %s on port %d.", UPnPgetLanAddr(), getServerPort()); // LOG("External IP: %s.", UPnPgetExternalAddress()); } else if(!strcmp(command, "list") || !strcmp(command, "ls")) /* List all connected clients */ { nlServerList(); } else if(!strcmp(command, "register")) /* Register on the main server. */ { if(!nlServerStartRegister()) LOG("Unable to reach the register."); else LOG("Registered."); } else if(!strcmp(command, "h") || !strcmp(command, "help")) { LOG("Non exaustive list of commands:\n" "\tls:\tList connected players.\n" "\tip:\tPrint local IP address with bound port.\n" "\tsend:\tSend to the given client the given file.\n" "\tquit:\tExit program."); } else LOG("Sorry, unimplemented command: %s.", cmd); AFTER_INPUT; } lFree(&words); signalHandler(0); UNINIT_INPUT; #ifndef DISABLE_PHYSICS thread_exit(); #else quit(); return NULL; #endif }