void CreateAnswer() { if (mSendAns && GetOffer().IsReceiving()) { mSendAns->AddToAnswer(GetOffer(), &GetAnswer()); } if (mRecvAns && GetOffer().IsSending()) { mRecvAns->AddToAnswer(GetOffer(), &GetAnswer()); } }
void MvScene::btnClicked() { QString text; text = lineEdit->text(); GetAnswer(text); }
int main() { std::string firstString, secondString; std::getline(std::cin, firstString); std::getline(std::cin, secondString); std::cout << GetAnswer(firstString, secondString); return 0; }
void QueryRetrieveHandler::Retrieve(const std::string& target, size_t i) { DicomMap map; GetAnswer(map, i); { ReusableDicomUserConnection::Locker locker(context_.GetReusableDicomUserConnection(), localAet_, modality_); locker.GetConnection().Move(target, map); } }
int main( int argc, char *argv[] ) { int nQs,nAs,verbose; printf(VERSION); /* The following (compile time) calculations of the number of questions * (nQs) and the number of possible answers (nAs) allows the program to * adjust itself automatically to the size of the data set. * Note: the -1 allows for the fact that as a defensive measure the 0th * array elements aren't counted thus allowing the indices into arrays to * be in the range 1 to nQs and 1 to nAs respectively. I.e. we consider * the arrays to have a lower bound of 1 rather than a lower bound of 0. * I.e. this give a more intuitive mapping of the question answers, for * example, where A -> 1, B -> 2, etc. */ nQs = (int)(sizeof(questions)/sizeof(questions[0]))-1; nAs = (int)(sizeof(questions[0].pAnswers)/sizeof(questions[0].pAnswers[0]))-1; #if DEBUG printf("Number of questions is: %d\n",nQs); printf("Number of answers is: %d\n",nAs); #endif printf("%s",questions[0].pQuestion); /* 0th 'question' is the preamble */ GetAnswer("Y"); /* Wait for a response - any, in fact, will do! */ printf("\nThere are %d questions in this test. Good luck!\n\n",nQs); Countdown(3); /* Output some typical Brain Trainer eye candy! */ puts(""); questions[0].aTime = SNAP(); /* Record the start time of the test */ AskQuestions(questions,nQs,nAs); /* Self-explanatory I trust! */ SHOT(); /* Record the end time of the test */ printf("\nThanks for taking Darren's LLP Brain Trainer Test!\n" "You completed the test in %d seconds\n",(int)ELAPSED()); printf("Would you like the verbose version of your results? [Y/N]: "); verbose = (GetAnswer("NY") == 1); /* Wait for a response */ MarkAnswers(questions,nQs,options,verbose); /* Report the test results */ return(0); }
char *GetAllAnswers(const char *DNSBody, char *Buffer, size_t BufferLength) { int AnswerCount; const char *Itr; int UsedCount; DNSRecordType ResourceType; char TempBuffer[1024]; int RecordLength; if( BufferLength < strlen(" And More ...\n") ) { return NULL; } AnswerCount = DNSGetAnswerCount(DNSBody) + DNSGetNameServerCount(DNSBody); if( AnswerCount == 0 ) { strcpy(Buffer, " Nothing.\n"); return Buffer + strlen(" Nothing.\n"); } BufferLength -= strlen(" And More ...\n"); UsedCount = 0; while(UsedCount != AnswerCount){ Itr = DNSGetAnswerRecordPosition(DNSBody, UsedCount + 1); ResourceType = (DNSRecordType)DNSGetRecordType(Itr); RecordLength = GetAnswer(DNSBody, DNSGetResourceDataPos(Itr), DNSGetResourceDataLength(Itr), TempBuffer, ResourceType) - TempBuffer; if( RecordLength < BufferLength ) { strcpy(Buffer, TempBuffer); BufferLength -= RecordLength; Buffer += RecordLength; } else { break; } ++UsedCount; } if( UsedCount < AnswerCount ) { Buffer += sprintf(Buffer, " And %d More ...\n", AnswerCount - UsedCount); } return Buffer; }
void Negotiate() { std::cerr << "Offer SDP: " << std::endl; mOffer->Serialize(std::cerr); std::cerr << "Answer SDP: " << std::endl; mAnswer->Serialize(std::cerr); if (mSendAns && GetAnswer().IsSending()) { mSendAns->Negotiate(GetAnswer(), GetOffer()); } if (mRecvAns && GetAnswer().IsReceiving()) { mRecvAns->Negotiate(GetAnswer(), GetOffer()); } if (mSendOff && GetAnswer().IsReceiving()) { mSendOff->Negotiate(GetAnswer(), GetAnswer()); } if (mRecvOff && GetAnswer().IsSending()) { mRecvOff->Negotiate(GetAnswer(), GetAnswer()); } }
TEST_F(JsepTrackTest, SimulcastOfferer) { Init(SdpMediaSection::kVideo); std::vector<JsepTrack::JsConstraints> constraints; constraints.push_back(MakeConstraints("foo", 40000)); constraints.push_back(MakeConstraints("bar", 10000)); mSendOff->SetJsConstraints(constraints); CreateOffer(); CreateAnswer(); // Add simulcast/rid to answer JsepTrack::AddToMsection(constraints, sdp::kRecv, &GetAnswer()); Negotiate(); ASSERT_TRUE(mSendOff->GetNegotiatedDetails()); ASSERT_EQ(2U, mSendOff->GetNegotiatedDetails()->GetEncodingCount()); ASSERT_EQ("foo", mSendOff->GetNegotiatedDetails()->GetEncoding(0).mRid); ASSERT_EQ(40000U, mSendOff->GetNegotiatedDetails()->GetEncoding(0).mConstraints.maxBr); ASSERT_EQ("bar", mSendOff->GetNegotiatedDetails()->GetEncoding(1).mRid); ASSERT_EQ(10000U, mSendOff->GetNegotiatedDetails()->GetEncoding(1).mConstraints.maxBr); }
// Ожидание прихода данных в течении времени time. Если данные пришли - SUCCESS Status Server_Receive(uint32_t time) { uint32_t len = 0; Timer1_Start(time); while(!Timer1_Status()) { while (GetAnswer(answer)) { Parse_Ans(answer); } if (!connect) return ERROR; // Пропал коннект, ничего не делаем if (qirdi) { do { len = input_len; modem_QIRD(RING_SIZE - input_len); // Чтобы случайно из буфера не выйти } while (len != input_len); if (input_len > 5) break; } } Timer1_Stop(); if (len != input_len) return ERROR; return SUCCESS; }
void AskQuestions(Question_t questions[], /* (pointer to) the questions */ int nQs, /* the number of questions to be asked */ int nAs) /* the number of answers for each question */ { int iQ, /* index of the question */ iA, /* index for the answers */ uAnswer; /* user's answer (index) */ Question_t *pQ; /* This pointer should help keep code short and quick */ for ( iQ = 1 ; /* Notes: Skip the 0th element as it's special. So,... */ iQ <= nQs ; /* ...nQs is also the upper bound of questions[]... */ /* ...iQ++ later on since we may need to repeat a question */ ) { /* Using a pointer to the current question helps keep expressions short */ pQ = &questions[iQ]; printf("\nQ%d) %s",iQ,pQ->pQuestion); /* Output a question followed... */ for ( iA = 1 ; iA <= nAs ; iA++ ) /* ...by the possible options... */ printf("\t%c. %s",options[iA],pQ->pAnswers[iA]); /* ...for an answer */ printf("Answer: "); /* Prompt for the answer... */ switch ( (uAnswer=GetAnswer(options)) ) {/* ...and check answer is AOK */ case SHRIEK: MarkAnswers(questions,--iQ,options,1); /* Quit with attitude */ /* Fall through to the normal QUIT */ case QUIT: printf("Quitting\n"); /* If it's an 'easter egg' to quit... */ exit(0); /* ...then exit without further ado. */ case INERR: case 0: printf("Invalid input - ignored. I'll repeat the question.\n"); continue; /* Invalid: so just continue with same question */ default: pQ->traineeAnswer = uAnswer; /* Note the answer... */ pQ->aTime = time(NULL); /* ...& current time. */ iQ++; /* Valid: so iQ++ here moves onto next question */ break; /* Defensive! Not really needed as default is last */ } } }
int main(int argc, char *argv[]) { int n; int ch; int method='I'; int ConfigRead; char *DaemonName; char ChipInfoStr[CHIP_STR_LEN]; unsigned int VendID; unsigned int ChipID; int LocalOnly; int sock; int sock6; int length; int ipv4_enable=1; struct sockaddr_in server; int msgsock; char buf[1024]; char outbuf[1024]; int rval; int selretval; int syserr; fd_set ready; struct servent *sp; unsigned long port; int psd = -1; struct sockaddr_in paddr; struct hostent *hent; struct itimerval tmo = {{0,0},{0,0}}; struct itimerval tmooff = {{0,0},{0,0}}; sock = 0; sock6 = 0; count = 0; tabout = 0; iter = 1; ConfigRead = 0; ReReadConfigFile = 0; ExitProgram = 0; UseVbat = 0; pushit = 0; quiet = 1; MonitorType = NO_CHIP; if ((sp = getservbyname("healthd", "tcp")) == NULL) { port = 1281; } else { port = ntohs(sp->s_port); } if (strchr(argv[0], '/')) { DaemonName = strrchr(argv[0], '/') + 1; } else { DaemonName=argv[0]; } /* * Set some defaults */ for (n=0; n<MAX_TYPES; n++) { active[n] = 0; fail_count[n] = 0; warn_level[n] = 2; warn_sent[n] = 0; fail_level[n] = 5; fail_sent[n] = 0; doWarn[n] = 0; doFail[n] = 0; } temp_warn[0] = '\0'; temp_fail[0] = '\0'; fan_warn[0] = '\0'; fan_fail[0] = '\0'; volt_warn[0] = '\0'; volt_fail[0] = '\0'; debug = 0; local = 0; LocalOnly = 0; while((ch=getopt(argc, argv, "12BDILSP:Vc:df:t:p:q")) != -1) { switch(ch){ case '1': MonitorType = W83781D; break; case '2': MonitorType = W83782D; break; case 'B': UseVbat = 1; break; case 'D': case 'd': debug = 1; break; case 'I': method='I'; break; case 'L': local = 1; break; case 'P': port = atoi(optarg); break; case 'S': method='S'; break; case 'V': fprintf(stderr, "Version %s\n", hdVERSION); exit(0); break; case 't': tabout = 1; break; case 'p': if ((psd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { (void)fprintf(stderr, "%s: cannot create push socket: %s\n", DaemonName, strerror(errno)); exit(1); } if (!(hent = gethostbyname(optarg))) { herror("Can't resolve hostname"); exit(1); } bzero(&paddr, sizeof(struct sockaddr_in)); paddr.sin_family = AF_INET; bcopy(hent->h_addr_list[0], &paddr.sin_addr.s_addr, sizeof(paddr.sin_addr.s_addr)); paddr.sin_port = htons(PUSH_PORT); if (connect(psd, (struct sockaddr*)&paddr, sizeof(struct sockaddr_in)) < 0) { (void)fprintf(stderr, "%s: connect failed: %s\n", DaemonName, strerror(errno)); exit(1); } pushit = 1; break; case 'c': count = atoi(optarg); if (count < 1) { count = 0; } debug = 1; break; case 'f': { int fd; if ((fd = open(optarg, O_RDONLY, 0)) < 0) { (void)fprintf(stderr, "%s: %s: %s\n", DaemonName, optarg, strerror(errno)); exit(1); } close(fd); strncpy(ConfigFile, optarg, MAXPATHLEN); ReadConfigFile (ConfigFile); ConfigRead = 1; } break; case 'q': quiet = 0; break; default: fprintf(stderr, "Usage: %s -[1|2] -[I|S] [-dLV] [-f configfile] [-c|t count] <seconds for sleep>"\ " (default %d sec)\n", DaemonName, DEFAULT_SEC); exit(1); } } if (ConfigRead == 0) { strncpy(ConfigFile, CONFIG_FILE, MAXPATHLEN); ReadConfigFile (ConfigFile); ConfigRead = 1; } if (argc > optind) { if((n = atoi(argv[optind])) > 0) { tmo.it_value.tv_sec = n; } else { fprintf(stderr, "Usage: %s -[1|2] -[I|S] [-dLV] [-f configfile] [-c|t count] <seconds for sleep>"\ " (default %d sec)\n", DaemonName, DEFAULT_SEC); exit(1); } } else { tmo.it_value.tv_sec = DEFAULT_SEC; } if (InitMBInfo(method) != 0) { perror("InitMBInfo"); exit(1); } if (RstChip() < 0) { perror("RstChip"); exit(1); } if (local || debug) { /* If debug mode or local mode don't open a socket */ LocalOnly = 1; } VendID = GetVendorID(); switch (VendID) { case 0x5CA3: ChipID = GetChipID_winbond(); switch (ChipID) { case 0x10: snprintf(ChipInfoStr, CHIP_STR_LEN, "WinBond Chip: W83781D"); if (MonitorType == NO_CHIP) MonitorType = W83781D; break; case 0x11: snprintf(ChipInfoStr, CHIP_STR_LEN, "Asus: AS97127F"); if (MonitorType == NO_CHIP) MonitorType = W83781D; break; case 0x21: snprintf(ChipInfoStr, CHIP_STR_LEN, "WinBond Chip: W83627HF"); if (MonitorType == NO_CHIP) MonitorType = W83627HF; break; case 0x30: snprintf(ChipInfoStr, CHIP_STR_LEN, "WinBond Chip: W83782D"); if (MonitorType == NO_CHIP) MonitorType = W83782D; break; case 0x40: snprintf(ChipInfoStr, CHIP_STR_LEN, "WinBond Chip: W83783S"); if (MonitorType == NO_CHIP) MonitorType = W83783S; break; default: snprintf(ChipInfoStr, CHIP_STR_LEN, "WinBond Chip: (unknown)"); if (MonitorType == NO_CHIP) MonitorType = W83781D; break; } break; case 0x12C3: snprintf(ChipInfoStr, CHIP_STR_LEN, "Asus: AS99127F"); if (MonitorType == NO_CHIP) MonitorType = AS99127F; break; case 0xFFFF0040: snprintf(ChipInfoStr, CHIP_STR_LEN, "National Semi: LM78"); if (MonitorType == NO_CHIP) MonitorType = LM78; break; case 0xFFFF00C0: snprintf(ChipInfoStr, CHIP_STR_LEN, "National Semi: LM79"); if (MonitorType == NO_CHIP) MonitorType = LM79; break; default: snprintf(ChipInfoStr, CHIP_STR_LEN, "Unknown Vendor: ID = %X", VendID); if (MonitorType == NO_CHIP) MonitorType = W83781D; break; } if (debug) { printf("************************\n"); printf("* Hardware Information *\n"); printf("************************\n"); printf("%s\n", ChipInfoStr); printf("************************\n\n"); } (void) openlog(DaemonName, LOG_CONS|LOG_NDELAY, hdFACILITY); signal(SIGALRM, SIGALRM_handler); if (debug == 0) { /* * Okay so far. Try and make ourself a daemon */ if (daemon(0,0) < 0) { syslog(hdALERT, "daemon libray call failed: %m (aborting)"); exit(2); } syslog(hdNOTICE, "Started"); } if (debug == 0) { /* Don't set the signal handler if we are in debug mode */ /* Since we don't check the ranges */ signal(SIGHUP, SIGHUP_handler); signal(SIGTERM, SIGTERM_handler); siginterrupt(SIGALRM,1); } if (LocalOnly == 0) { /* Create name with wildcards. */ if (ipv4_enable) { /* Create socket from which to read. */ sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { syslog(hdALERT, "opening datagram socket: %m"); syslog(hdALERT, "Aborting"); exit(1); } server.sin_family = AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = htons(port); if (bind(sock, (struct sockaddr *)&server, sizeof(struct sockaddr_in))) { close(sock); syslog(hdALERT, "binding datagram socket: %m"); syslog(hdALERT, "Aborting"); exit(1); } /* Find assigned port value and print it out. */ length = sizeof(server); if (getsockname(sock, (struct sockaddr *)&server, &length)) { close(sock); syslog(hdALERT, "getting socket name: %m"); syslog(hdALERT, "Aborting"); exit(1); } } } ReadCurrentValues(); if (LocalOnly == 0) { /* Start accepting connections */ if (sock != 0) { listen(sock, 32); } } /* Main daemon loop */ while ((iter<count) || (count==0)) { FD_ZERO(&ready); if (LocalOnly == 0) { if (sock != 0) { FD_SET(sock, &ready); } } /* Wait for connection, or timeout */ setitimer(ITIMER_REAL,&tmo,0); selretval = select(getdtablesize(), &ready, 0, 0, 0); syserr = errno; setitimer(ITIMER_REAL,&tmooff,0); if ( ExitProgram ) { break; } switch (selretval) { case -1: if (syserr && syserr != EINTR) { syslog(hdCRITICAL, "OOPS! select returned a weird error, bailing out: %m"); exit(1); } if (ReReadConfigFile) { /* * If we are updating the config file * then we should clear the error counts. */ for (n=0; n<MAX_TYPES; n++) { active[n] = 0; fail_count[n] = 0; warn_level[n] = 2; warn_sent[n] = 0; fail_level[n] = 5; fail_sent[n] = 0; } ReadConfigFile (ConfigFile); ReReadConfigFile = 0; syslog(hdWARNING, "Restarted"); break; } if (count > 0) { iter++; } ReadCurrentValues(); if (pushit) { push_stat(psd); } break; default: if (LocalOnly == 0) { if (FD_ISSET(sock, &ready)) { msgsock = accept(sock, 0, 0); if (msgsock == -1) { /* Add error handling here */ } else { do { bzero(buf, sizeof(buf)); bzero(outbuf, sizeof(outbuf)); if ((rval = read(msgsock, buf, 1024)) > 0) { rval = GetAnswer(buf, outbuf); write(msgsock, outbuf, strlen(outbuf)); } else if (rval < 0) { break; } } while (rval != 0); close(msgsock); } } } break; } if (ExitProgram) { break; } } if (LocalOnly == 0) { close(sock); } if (debug == 0) { signal(SIGHUP, SIG_DFL); signal(SIGTERM, SIG_DFL); } syslog(hdWARNING, "Exiting.."); exit(0); }
static double GetDbl(const char* AskFor) { return GetAnswer(AskFor, 0.0); }
static WORD GetVal(const char* AskFor) { return (WORD) GetAnswer(AskFor, 255.0); }
static WORD Get100(const char* AskFor) { return (WORD) GetAnswer(AskFor, 100.0); }