Ejemplo n.º 1
0
/**
 * Reads a command from the terminal thread, and processes it appropriately.
 */
void Cli::command()
{
    std::stringstream reader(terminal_.get_line());
    std::string command;
    reader >> command;

    if (command == "")                  ;
    else if (command == "exit")         cmd_exit();
    else if (command == "help")         cmd_help();
    else if (command == "connect")      cmd_connect(reader);
    else if (command == "disconnect")   cmd_disconnect(reader);
    else if (command == "height")       cmd_height();
    else if (command == "watch")        cmd_watch(reader);
    else if (command == "txheight")     cmd_tx_height(reader);
    else if (command == "txdump")       cmd_tx_dump(reader);
    else if (command == "txsend")       cmd_tx_send(reader);
    else if (command == "utxos")        cmd_utxos(reader);
    else if (command == "save")         cmd_save(reader);
    else if (command == "load")         cmd_load(reader);
    else if (command == "dump")         cmd_dump(reader);
    else
        std::cout << "unknown command " << command << std::endl;

    // Display another prompt, if needed:
    if (!done_)
        terminal_.show_prompt();
}
Ejemplo n.º 2
0
/**
 * The main loop for the example application. This loop can be woken up
 * by either events from the network or by input from the terminal.
 */
int Cli::run()
{
    std::cout << "type \"help\" for instructions" << std::endl;
    terminal_.show_prompt();

    while (!done_)
    {
        std::vector<zmq_pollitem_t> items;
        items.push_back(terminal_.pollitem());
        auto updaterItems = updater_.pollitems();
        items.insert(items.end(), updaterItems.begin(), updaterItems.end());

        auto nextWakeup = updater_.wakeup();
        int delay = nextWakeup.count() ? nextWakeup.count() : -1;

        zmq::poll(items.data(), items.size(), delay);

        if (items[0].revents)
            command();
    }
    return 0;
}