From 5465e1174fd043d425a7e22b948561af9952464d Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 9 Jul 2017 21:37:39 +0200 Subject: [PATCH] fixed debug output --- libresapi/src/api/RsControlModule.cpp | 5 +- retroshare-nogui/src/TerminalApiClient.cpp | 89 +++++----------------- retroshare-nogui/src/retroshare.cc | 17 ++--- 3 files changed, 27 insertions(+), 84 deletions(-) diff --git a/libresapi/src/api/RsControlModule.cpp b/libresapi/src/api/RsControlModule.cpp index 1d0cddd65..1e7f19b38 100644 --- a/libresapi/src/api/RsControlModule.cpp +++ b/libresapi/src/api/RsControlModule.cpp @@ -379,11 +379,14 @@ void RsControlModule::handlePassword(Request &req, Response &resp) mPassword = passwd; mWantPassword = false; mStateTokenServer->replaceToken(mStateToken); - +#ifdef DEBUG_CONTROL_MODULE std::cerr << "RsControlModule::handlePassword(): setting mPasswd=\"" << mPassword << "\"" << std::endl; +#endif } +#ifdef DEBUG_CONTROL_MODULE else std::cerr << "RsControlModule::handlePassword(): not setting mPasswd=\"" << mPassword << "\"!!!" << std::endl; +#endif resp.mDataStream << makeKeyValueReference("want_password", mWantPassword) diff --git a/retroshare-nogui/src/TerminalApiClient.cpp b/retroshare-nogui/src/TerminalApiClient.cpp index 81eebe6b4..cc20c2fb3 100644 --- a/retroshare-nogui/src/TerminalApiClient.cpp +++ b/retroshare-nogui/src/TerminalApiClient.cpp @@ -54,7 +54,7 @@ public: // restore terminal settings tcsetattr(STDIN_FILENO, TCSANOW, &mOldTermSettings); #ifdef TERMINALINPUT_DEBUG - std::cerr << "Terminal restored" << std::endl; + std::cerr << "Terminal killed" << std::endl; #endif #endif } @@ -110,6 +110,7 @@ static std::string readStringFromKeyboard(bool passwd_mode) s += c ; } + putchar('\n'); return s ; } @@ -140,16 +141,21 @@ void TerminalApiClient::data_tick() bool ask_for_password = false; std::string key_name; +#ifdef TO_REMOVE TerminalInput term; +#endif while(!shouldStop()) { // assuming sleep_time >> work_time // so we don't have to check the absolute time, just sleep every cycle usleep(MIN_WAIT_TIME * 1000); - last_io_poll += MIN_WAIT_TIME; + last_event_api_poll += MIN_WAIT_TIME; +#ifdef TO_REMOVE + last_io_poll += MIN_WAIT_TIME; + if(last_io_poll >= IO_POLL_PERIOD) { last_io_poll = 0; @@ -181,6 +187,7 @@ void TerminalApiClient::data_tick() //std::cout << "you pressed key " << (char) last_char << " as integer: " << last_char << std::endl; } } +#endif if(last_event_api_poll >= API_EVENT_POLL_PERIOD) { @@ -192,6 +199,15 @@ void TerminalApiClient::data_tick() password_state_token = StateToken(); } + // If the core has started, we leave. Maybe we should not use this in the future if we want to allow to + // log out and then log in again? + + if(runstate == "running_ok") + { + std::cerr << "Terminating terminal thread because the runstate says that the core is running." << std::endl; + shutdown(); + } + bool edge = false; if(runstate_state_token.isNull()) { @@ -251,75 +267,6 @@ void TerminalApiClient::data_tick() sendPassword(passwd) ; sendSelectedAccount(acc_ssl_id) ; } - -#ifdef OLD_CODE - if(!ask_for_password && edge && runstate == "waiting_account_select") - { - readAvailableAccounts(accounts) ; - account_number_size = (int)ceil(log(accounts.size())/log(10.0f)) ; - - for(uint32_t i=0;i= '0' && last_char <= '9') - { - std::cout.flush(); - selected_account_number = 10*selected_account_number + last_char - '0' ; - account_number_typed++ ; - - if(account_number_typed == account_number_size) - { - if(selected_account_number < accounts.size()) - { - std::cout.flush(); - std::cout << std::endl << "Selected account: " << accounts[selected_account_number].name << " (" << accounts[selected_account_number].location << ") SSL id: " << accounts[selected_account_number].ssl_id << std::endl; - - std::string acc_ssl_id = accounts[selected_account_number].ssl_id.toStdString(); - sendSelectedAccount(acc_ssl_id) ; - - inbuf.clear(); - } - else - { - std::cerr << ": invalid account number (should be between " << std::setw(account_number_size) << std::setfill('0') - << 0 << " and " << std::setw(account_number_size) << std::setfill('0') << accounts.size()-1 << ")" << std::endl; - std::cout << std::endl << "Type account number: " ; - std::cout.flush() ; - } - - account_number_typed = 0 ; - selected_account_number = 0 ; - } - } - - if(edge && ask_for_password) - { - std::cout << std::endl; - std::cout << std::endl; - std::cout << "Enter the password for key " << key_name << " : " ; - std::cout.flush() ; - } - - if(ask_for_password && enter_was_pressed && !inbuf.empty()) - { - std::cout << "TerminalApiClient: got a password" << std::endl; - - // Send passwd to api server - sendPassword(inbuf) ; - - usleep(1000*1000) ; - - // clears buffer - inbuf.clear(); - } -#endif } } diff --git a/retroshare-nogui/src/retroshare.cc b/retroshare-nogui/src/retroshare.cc index b0273da51..ef02bb623 100644 --- a/retroshare-nogui/src/retroshare.cc +++ b/retroshare-nogui/src/retroshare.cc @@ -101,23 +101,16 @@ int main(int argc, char **argv) resource_api::TerminalApiClient tac(&api); tac.start(); + bool already = false ; while(ctrl_mod.processShouldExit() == false) { - usleep(200*1000); + usleep(1000*1000); - if(!tac.isRunning()) + if(!tac.isRunning() && !already) { -// if(!RsInit::isLocationRunning()) -// { -// std::cerr << "Terminal API client stopped but location not set ! Relaunching." ; -// tac.start(); -// } -// else if(RsInit::isLocationRunning()) -// { -// std::cerr << "Terminal API client running but location already set ! Stopping it." ; -// tac.shutdown(); -// } + std::cerr << "Terminal API client terminated." << std::endl; + already = true ; } }