knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
terminal.cpp File Reference
#include <termios.h>
#include <exception>
#include <iostream>
#include <algorithm>
#include <memory>
#include <list>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <utility>
#include <knowrob/knowrob.h>
#include <knowrob/Logger.h>
#include <knowrob/KnowledgeBase.h>
#include "knowrob/formulas/Predicate.h"
#include "knowrob/queries/QueryParser.h"
#include "knowrob/semweb/PrefixRegistry.h"
#include "knowrob/queries/QueryError.h"
#include "knowrob/queries/QueryTree.h"
#include "knowrob/queries/Answer.h"
#include "knowrob/queries/AnswerYes.h"
#include "knowrob/queries/FormulaQuery.h"
#include "knowrob/integration/InterfaceUtils.h"
Include dependency graph for terminal.cpp:

Go to the source code of this file.

Namespaces

 knowrob
 

Functions

int run (int argc, char **argv)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 652 of file terminal.cpp.

652  {
653  InitKnowRob(argc, argv);
654  int status;
655  try {
656  status = run(argc, argv);
657  }
658  catch (std::exception &e) {
659  KB_ERROR("a '{}' exception occurred in main loop: {}.", typeid(e).name(), e.what());
660  status = EXIT_FAILURE;
661  }
662  ShutdownKnowRob();
663  return status;
664 }
#define KB_ERROR
Definition: Logger.h:28
void InitKnowRob(int argc, char **argv, bool initPython=true)
Definition: knowrob.cpp:96
void ShutdownKnowRob()
Definition: knowrob.cpp:123
int run(int argc, char **argv)
Definition: terminal.cpp:608

◆ run()

int run ( int  argc,
char **  argv 
)

Definition at line 608 of file terminal.cpp.

608  {
609  po::options_description general("General options");
610  general.add_options()
611  ("help", "produce a help message")
612  ("verbose", "print informational messages")
613  ("config-file", po::value<std::string>()->required(), "a configuration file in JSON format")
614  ("version", "output the version number");
615  // Declare an options description instance which will be shown
616  // to the user
617  po::options_description visible("Allowed options");
618  visible.add(general);
619  // parse command line arguments
620  po::variables_map vm;
621  po::store(po::parse_command_line(argc, argv, visible), vm);
622 
623  if (vm.count("help")) {
624  std::cout << visible;
625  return EXIT_SUCCESS;
626  }
627 
628  // read settings
629  boost::property_tree::ptree config;
630  if (vm.count("config-file")) {
631  boost::property_tree::read_json(
632  vm["config-file"].as<std::string>(),
633  config);
634  } else {
635  std::cout << "'config-file' commandline argument is missing" << std::endl;
636  return EXIT_FAILURE;
637  }
638 
639  // configure logging
640  auto log_config = config.get_child_optional("logging");
641  if (log_config) {
642  Logger::loadConfiguration(log_config.value());
643  }
644  // overwrite console logger level (default: prevent messages being printed, only print warnings and errors)
645  Logger::setSinkLevel(Logger::Console,
646  vm.count("verbose") ? spdlog::level::debug : spdlog::level::warn);
647 
648  return KnowRobTerminal(config).run();
649 }