bool handleUserInput() { static std::string inputBuffer; char c = _getch(); if (c == '\r') { std::cout << std::endl; std::string command; const size_t len = inputBuffer.length(); command.reserve(len); // Convert the input to lower case first for (size_t i=0; i < len; i++) { command.append(1, tolower(inputBuffer.at(i))); } inputBuffer.clear(); bool success = parseCommand(command, std::cout); promptUser(); return success; } else if (c == '~'){ if(paused == false){ std::cout << "UNPAUSED" << std::endl; paused = true; } else if(paused == true){ std::cout << "PAUSED press ~ to unpause" << std::endl; paused = false; } promptUser(); return true; } else { if (c == '\b') { // Backspace key if (inputBuffer.length()) { putchar(c); putchar(' '); putchar(c); inputBuffer.erase(inputBuffer.end()-1); } } else { inputBuffer.append(1,c); std::cout << c; } } return true; }
int recvList(struct text_list * list) { int numChannels = ((int)list -> txt_nchannels); if((buffPosition - inBuffer) > 0) { printf("\n"); } printf("Existing Channels: \n"); int i; for(i = 0; i < numChannels; i++) { printf(" %s\n", list-> txt_channels[i].ch_channel); } promptUser(); if((buffPosition - inBuffer) > 0) { char *cPtr; for(cPtr = inBuffer; cPtr < buffPosition; ++cPtr) { printf("%c", *cPtr); } } fflush(stdout); return true; }
int recvError(struct text_error * error) { printError(error->txt_error); printf("\n"); promptUser(); return true; }
int main(){ FILE *F = fopen("./american-english-no-accents", "r"); Trie *T = initTrie(); createTrie(T, F); fclose(F); promptUser(T); }
int recvWho(struct text_who * whoUsers) { int numUsers = ((int)whoUsers -> txt_nusernames); if((buffPosition - inBuffer) > 0) { printf("\n"); } printf("Users in channel %s:\n", whoUsers->txt_channel); int i; for(i = 0; i < numUsers; i++) { printf(" %s\n", whoUsers -> txt_users[i].us_username); } promptUser(); if((buffPosition - inBuffer) > 0) { char * cPtr; for(cPtr = inBuffer; cPtr < buffPosition; ++cPtr) { printf("%c", *cPtr); } } fflush(stdout); return true; }
int main(void) { srand(time(0)); int SIZE = 10; char* rooms[] = {"blue", "red", "ONE", "TWO", "Big", "Small", "best", "worst", "CARPET", "WOOD"}; int CHOSEN_ROOMS_SIZE = 7; char * chosenRooms[] = { "", "", "", "", "", "", "" }; char *directory_name; // initialize some variables and set up room files setDirectory( &directory_name ); makeRooms( rooms, SIZE, directory_name, chosenRooms, CHOSEN_ROOMS_SIZE ); // the first chosen room is always START_ROOM // (the last chosen room is always END_ROOM) char* curr_loc = chosenRooms[0]; struct Moves* moves = (struct Moves*) malloc( sizeof( struct Moves ) ); moves->room = curr_loc; moves->next = NULL; int moves_count = 0; int* moves_count_p = &moves_count; int isEnd = 0; while ( ! isEnd ) { presentCurrentLocation( curr_loc ); listLocations( curr_loc, directory_name ); promptUser( &curr_loc, directory_name, moves, moves_count_p ); // Check if user is in END_ROOM if ( ! strcmp( curr_loc, chosenRooms[CHOSEN_ROOMS_SIZE - 1] ) ) { printEndingMessage( moves, moves_count ); // break out of while loop isEnd = 1; } } //clean up free( directory_name ); free( curr_loc ); int i; for ( i = 0; i < CHOSEN_ROOMS_SIZE; ++i ) { free( chosenRooms[i] ); } while( moves->next != NULL ) { struct Moves* temp = moves->next; free( moves ); moves = temp; } free( moves ); exit(0); }
bool handleUserInput() { static std::string inputBuffer; char c = _getch(); #if __linux__ if (c == '\n') { #else if (c == '\r') { #endif std::cout << std::endl; std::string command; const size_t len = inputBuffer.length(); command.reserve(len); // Convert the input to lower case first for (size_t i=0; i < len; i++) { command.append(1, tolower(inputBuffer.at(i))); } inputBuffer.clear(); bool success = parseCommand(command, std::cout); promptUser(); return success; } else { if (c == '\b') { // Backspace key if (inputBuffer.length()) { putchar(c); putchar(' '); putchar(c); inputBuffer.erase(inputBuffer.end()-1); } } else { inputBuffer.append(1,c); std::cout << c; } } return true; } void promptUser() { std::cout << "FacialExpressionDemo> "; }
static bool downloadResource (const KUrl& srcUrl, const QString& suggestedName = QString(), QWidget* parent = 0, const KIO::MetaData& metaData = KIO::MetaData()) { const KUrl& destUrl = promptUser(parent, srcUrl, suggestedName); if (!destUrl.isValid()) return false; KIO::Job *job = KIO::file_copy(srcUrl, destUrl); if (!metaData.isEmpty()) job->setMetaData(metaData); job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. job->ui()->setWindow((parent ? parent->window() : 0)); job->ui()->setAutoErrorHandlingEnabled(true); return true; }
int recvSay(struct text_say* say) { if((buffPosition - inBuffer) > 0) { printf("\n"); } printf("[%s][%s]%s\n", say->txt_channel, say->txt_username, say->txt_text); promptUser(); if((buffPosition - inBuffer) > 0) { char * cPtr; for(cPtr = inBuffer; cPtr < buffPosition; ++cPtr) { printf("%c", *cPtr); } } fflush(stdout); return true; }
void XTelepathyPasswordAuthOperation::onSASLStatusChanged(uint status, const QString &reason, const QVariantMap &details) { if (status == Tp::SASLStatusNotStarted) { qDebug() << "Requesting password"; // if we have non-null id AND if the last attempt didn't fail, // proceed with the credentials receieved from the SSO; // otherwise prompt the user if (!m_lastLoginFailedConfig.hasKey(m_account->objectPath())) { GetCredentialsJob *credentialsJob = new GetCredentialsJob(m_accountStorageId, QStringLiteral("password"), QStringLiteral("password"), this); connect(credentialsJob, &GetCredentialsJob::finished, [this](KJob *job){ if (job->error()) { qWarning() << "Credentials job error:" << job->errorText(); qDebug() << "Prompting for password"; promptUser(); } else { m_canFinish = true; QByteArray secret = qobject_cast<GetCredentialsJob*>(job)->credentialsData().value("Secret").toByteArray(); m_saslIface->StartMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"), secret); } }); credentialsJob->start(); } else { promptUser(); } } else if (status == Tp::SASLStatusServerSucceeded) { qDebug() << "Authentication handshake"; m_saslIface->AcceptSASL(); } else if (status == Tp::SASLStatusSucceeded) { qDebug() << "Authentication succeeded"; if (m_lastLoginFailedConfig.hasKey(m_account->objectPath())) { m_lastLoginFailedConfig.deleteEntry(m_account->objectPath()); } if (m_canFinish) { // if the credentials storage has finished, just finish setFinished(); } else { // ...otherwise set this to true and it will finish // when credentials are finished m_canFinish = true; } } else if (status == Tp::SASLStatusInProgress) { qDebug() << "Authenticating..."; } else if (status == Tp::SASLStatusServerFailed) { qDebug() << "Error authenticating - reason:" << reason << "- details:" << details; if (m_canTryAgain) { qDebug() << "Retrying..."; promptUser(); } else { qWarning() << "Authentication failed and cannot try again"; m_lastLoginFailedConfig.writeEntry(m_account->objectPath(), "1"); // We cannot try again, but we can request again to set the account // online. A new channel will be created, but since we set the // lastLoginFailed entry, next time we will prompt for password // and the user won't see any difference except for an // authentication error notification Tp::Presence requestedPresence = m_account->requestedPresence(); m_account->setRequestedPresence(requestedPresence); QString errorMessage = details[QLatin1String("server-message")].toString(); setFinishedWithError(reason, errorMessage.isEmpty() ? i18n("Authentication error") : errorMessage); } } }
int main(int argc, char** argv) { comPort=openPort(portS);//***PUT YOUR COM PORT NUMBER HERE!*** // location of the machine running the 3D motion cube std::string receiverHost = "localhost"; if (argc > 2) { std::cout << "Usage: " << argv[0] << " <hostname>" << std::endl; std::cout << "The arguments specify the host of the motion cube (Default: localhost)" << std::endl; return 1; } if (argc > 1) { receiverHost = std::string(argv[1]); } EmoEngineEventHandle eEvent = EE_EmoEngineEventCreate(); EmoStateHandle eState = EE_EmoStateCreate(); unsigned int userID = 0; try { // if (EE_EngineConnect() != EDK_OK) { if (EE_EngineRemoteConnect("127.0.0.1", 3008) != EDK_OK) { throw std::exception("Emotiv Engine start up failed."); } else { std::cout << "Emotiv Engine started!" << std::endl; neutral();//send all servos to their neutral positions } int startSendPort = 6868; std::map<unsigned int, SocketClient> socketMap; promptUser(); while (true) { // Handle the user input if (_kbhit()) { if (!handleUserInput()) { break; } } if(paused == true){ int state = EE_EngineGetNextEvent(eEvent); // New event needs to be handled if (state == EDK_OK) { EE_Event_t eventType = EE_EmoEngineEventGetType(eEvent); EE_EmoEngineEventGetUserId(eEvent, &userID); switch (eventType) { // New headset connected, create a new socket to send the animation case EE_UserAdded: { std::cout << std::endl << "New user " << userID << " added, sending Cognitiv animation to "; std::cout << receiverHost << ":" << startSendPort << "..." << std::endl; promptUser(); socketMap.insert(std::pair<unsigned int, SocketClient>( userID, SocketClient(receiverHost, startSendPort, UDP))); startSendPort++; break; } // Headset disconnected, remove the existing socket case EE_UserRemoved: { std::cout << std::endl << "User " << userID << " has been removed." << std::endl; promptUser(); std::map<unsigned int, SocketClient>::iterator iter; iter = socketMap.find(userID); if (iter != socketMap.end()) { socketMap.erase(iter); } break; } // Send the Cognitiv animation if EmoState has been updated case EE_EmoStateUpdated: { //std::cout << "New EmoState from user " << userID << "..." << std::endl; EE_EmoEngineEventGetEmoState(eEvent, eState); std::map<unsigned int, SocketClient>::iterator iter; iter = socketMap.find(userID); if (iter != socketMap.end()) { sendCognitiv(eState); } break; } // Handle Cognitiv training related event case EE_CognitivEvent: { handleCognitivEvent(std::cout, eEvent); break; } default: break; } } else if (state != EDK_NO_EVENT) { std::cout << "Internal error in Emotiv Engine!" << std::endl; break; } } Sleep(1); } } catch (const std::exception& e) { std::cerr << e.what() << std::endl; std::cout << "Press any keys to exit..." << std::endl; getchar(); } EE_EngineDisconnect(); EE_EmoStateFree(eState); EE_EmoEngineEventFree(eEvent); return 0; }
int main(int argc, char **argv) { // location of the machine running the "BlueGirl" head model std::string receiverHost = "localhost"; if (argc > 2) { std::cout << "Usage: " << argv[0] << " <hostname>" << std::endl; std::cout << "The arguments specify the host of the head model " "(Default: localhost)" << std::endl; return 1; } if (argc > 1) { receiverHost = std::string(argv[1]); } EmoEngineEventHandle eEvent = IEE_EmoEngineEventCreate(); EmoStateHandle eState = IEE_EmoStateCreate(); unsigned int userID = 0; const int CONTROL_PANEL_PORT = 3008; try { // Connect to EmoEngine if (IEE_EngineConnect() != EDK_OK) { throw std::runtime_error("EmoEngine start up failed."); } else { std::cout << "EmoEngine started!" << std::endl; } int startSendPort = 30000; std::map<unsigned int, SocketClient> socketMap; std::cout << "Type \"exit\" to quit, \"help\" to list available commands..." << std::endl; promptUser(); while (true) { // Handle the user input if (_kbhit()) { if (!handleUserInput()) { break; } } int state = IEE_EngineGetNextEvent(eEvent); // New event needs to be handled if (state == EDK_OK) { IEE_Event_t eventType = IEE_EmoEngineEventGetType(eEvent); IEE_EmoEngineEventGetUserId(eEvent, &userID); switch (eventType) { // New headset connected // Create a new socket to send the animation case IEE_UserAdded: { std::cout << std::endl << "New user " << userID << " added, sending FacialExpression animation to "; std::cout << receiverHost << ":" << startSendPort << "..." << std::endl; promptUser(); socketMap.insert(std::pair<unsigned int, SocketClient>( userID, SocketClient(receiverHost, startSendPort, UDP))); startSendPort++; break; } // Headset disconnected, remove the existing socket case IEE_UserRemoved: { std::cout << std::endl << "User " << userID << " has been removed." << std::endl; promptUser(); std::map<unsigned int, SocketClient>::iterator iter; iter = socketMap.find(userID); if (iter != socketMap.end()) { socketMap.erase(iter); } break; } // Send the FacialExpression animation // if EmoState has been updated case IEE_EmoStateUpdated: { IEE_EmoEngineEventGetEmoState(eEvent, eState); std::map<unsigned int, SocketClient>::iterator iter; iter = socketMap.find(userID); if (iter != socketMap.end()) { sendFacialExpressionAnimation(iter->second, eState); } break; } // Handle FacialExpression training event case IEE_FacialExpressionEvent: { handleFacialExpressionEvent(std::cout, eEvent); } default: break; } } else if (state != EDK_NO_EVENT) { std::cout << std::endl << "Internal error in Emotiv Engine!" << std::endl; break; } #ifdef _WIN32 Sleep(15); #endif #ifdef __linux__ sleep(1); #endif } } catch (const std::runtime_error& e) { std::cerr << e.what() << std::endl; std::cout << "Press 'Enter' to exit..." << std::endl; getchar(); } // Clean up IEE_EngineDisconnect(); IEE_EmoStateFree(eState); IEE_EmoEngineEventFree(eEvent); return 0; }
void handleFacialExpressionEvent(std::ostream& os, EmoEngineEventHandle expressivEvent) { unsigned int userID = 0; IEE_EmoEngineEventGetUserId(expressivEvent, &userID); IEE_FacialExpressionEvent_t eventType = IEE_FacialExpressionEventGetType(expressivEvent); switch (eventType) { case IEE_FacialExpressionTrainingStarted: { os << std::endl << "FacialExpression training for user " << userID << " STARTED!" << std::endl; break; } case IEE_FacialExpressionTrainingSucceeded: { os << std::endl << "FacialExpression training for user " << userID << " SUCCIEEDED!" << std::endl; break; } case IEE_FacialExpressionTrainingFailed: { os << std::endl << "FacialExpression training for user " << userID << " FAILED!" << std::endl; break; } case IEE_FacialExpressionTrainingCompleted: { os << std::endl << "FacialExpression training for user " << userID << " COMPLETED!" << std::endl; break; } case IEE_FacialExpressionTrainingDataErased: { os << std::endl << "FacialExpression training data for user " << userID << " ERASED!" << std::endl; break; } case IEE_FacialExpressionTrainingRejected: { os << std::endl << "FacialExpression training for user " << userID << " REJECTED!" << std::endl; break; } case IEE_FacialExpressionTrainingReset: { os << std::endl << "FacialExpression training for user " << userID << " RESET!" << std::endl; break; } case IEE_FacialExpressionNoEvent: default: //@@ unhandled case assert(0); return; } promptUser(); }
bool Transition::operator==(const Transition& b) const { return valid==b.valid && program()==b.program() && transitFrom()==b.transitFrom() && transitTo()==b.transitTo() && promptUser()==b.promptUser() && notifyUser()==b.notifyUser(); }
void handleCognitivEvent(std::ostream& os, EmoEngineEventHandle cognitivEvent) { unsigned int userID = 0; EE_EmoEngineEventGetUserId(cognitivEvent, &userID); EE_CognitivEvent_t eventType = EE_CognitivEventGetType(cognitivEvent); switch (eventType) { case EE_CognitivTrainingStarted: { os << std::endl << "Cognitiv training for user " << userID << " STARTED!" << std::endl; break; } case EE_CognitivTrainingSucceeded: { os << std::endl << "Cognitiv training for user " << userID << " SUCCEEDED!" << std::endl; break; } case EE_CognitivTrainingFailed: { os << std::endl << "Cognitiv training for user " << userID << " FAILED!" << std::endl; break; } case EE_CognitivTrainingCompleted: { os << std::endl << "Cognitiv training for user " << userID << " COMPLETED!" << std::endl; break; } case EE_CognitivTrainingDataErased: { os << std::endl << "Cognitiv training data for user " << userID << " ERASED!" << std::endl; break; } case EE_CognitivTrainingRejected: { os << std::endl << "Cognitiv training for user " << userID << " REJECTED!" << std::endl; break; } case EE_CognitivTrainingReset: { os << std::endl << "Cognitiv training for user " << userID << " RESET!" << std::endl; break; } case EE_CognitivAutoSamplingNeutralCompleted: { os << std::endl << "Cognitiv auto sampling neutral for user " << userID << " COMPLETED!" << std::endl; break; } case EE_CognitivSignatureUpdated: { os << std::endl << "Cognitiv signature for user " << userID << " UPDATED!" << std::endl; break; } case EE_CognitivNoEvent: break; default: //@@ unhandled case assert(0); break; } promptUser(); }
int main(int argc, char *argv[]) { /* handle arguments */ if(argc != 4) { printf("Incorrect arguments, please use:\n./client server port username\n"); return 1; } raw_mode(); memset(liveChannel, '\0', CHANNEL_MAX); char * address = argv[1]; char * port = argv[2]; char * username = argv[3]; /* Build Socket we pass the function the address and port */ if(buildSocket(address, port) != true) { cooked_mode(); return 1; } /* Handle Login */ if(login(username) != true) { cooked_mode(); return 1; } int parseStatus = true; char * input; fd_set readfds; promptUser(); do { FD_ZERO(&readfds); FD_SET(0, &readfds); FD_SET(socketfd, &readfds); select(socketfd+1, &readfds, NULL, NULL, NULL); if(FD_ISSET(0, &readfds)) { input = inputString(); if(input != NULL) { /* Parse Input */ parseStatus = parseInput(input); if(parseStatus != -1) { promptUser(); } } } else if (FD_ISSET(socketfd, &readfds)) { struct text * text = (struct text *) malloc(sizeof(struct text) + 1024); int bytes = 0; if((bytes = recvfrom(socketfd, text, 1024, 0,servinfo->ai_addr, &servinfo->ai_addrlen)) > 0) { clearPrompt(); switchResp(text); free(text); } } } while(parseStatus != -1); freeaddrinfo(servinfo); cooked_mode(); return 0; }
// Anthony int main(int argc, char** argv) { initialize(); promptUser(); return 0; }