Exemplo n.º 1
0
int main(int argc, char ** argv)
{
  if (argc != 3) {
    fprintf(stderr, "Wrong number of arguments, pass one action type and a namespace\n");
    return 1;
  }
  rclcpp::init(argc, argv);

  auto start = std::chrono::steady_clock::now();

  std::string action = argv[1];
  std::string namespace_ = argv[2];
  auto node = rclcpp::Node::make_shared(std::string("test_action_server_") + action, namespace_);

  rclcpp_action::ServerBase::SharedPtr server;

  if (action == "Fibonacci") {
    server = receive_goals<test_msgs::action::Fibonacci>(
      node, action, generate_expected_fibonacci_goals(node->get_logger()));
  } else if (action == "NestedMessage") {
    server = receive_goals<test_msgs::action::NestedMessage>(
      node, action, generate_expected_nested_message_goals(node->get_logger()));
  } else {
    fprintf(stderr, "Unknown action type '%s'\n", action.c_str());
    return 1;
  }
  rclcpp::spin(node);

  auto end = std::chrono::steady_clock::now();
  std::chrono::duration<float> diff = (end - start);
  printf("replied for %f seconds\n", diff.count());

  return should_fail ? 1 : 0;
}
Exemplo n.º 2
0
	//////////////////////////////////////////////////////////////////////////
	/// Create an instance of a given type.
	/// Used internally to create instances of various settings types.
	///
	/// @param type the type to create
	/// @param context the context to use
	/// @return a new instance of given type.
	///
	/// @author mickem
	settings::instance_raw_ptr NSCSettingsImpl::create_instance(std::wstring key) {
		net::wurl url = net::parse(key);
		if (url.protocol.empty()) {
			url = net::parse(key + _T("://"));
			get_logger()->debug(__FILE__, __LINE__, _T("No driver specified attemtping to fake one: ") + url.to_string());
		}
		get_logger()->debug(__FILE__, __LINE__, _T("Creating instance for: ") + url.to_string());
		if (url.host.empty() && url.path.empty()) 
			key = _T("");
#ifdef WIN32
		if (url.protocol == _T("old")) {
			old_ = true;
			if (key.empty())
				key = DEFAULT_CONF_OLD_LOCATION;
			return settings::instance_raw_ptr(new settings::OLDSettings(this, key));
		}
		if (url.protocol == _T("registry")) {
			if (key.empty())
				key = DEFAULT_CONF_REG_LOCATION;
			return settings::instance_raw_ptr(new settings::REGSettings(this, key));
		}
#endif
		if (url.protocol == _T("ini")) {
			if (key.empty())
				key = DEFAULT_CONF_INI_LOCATION;
			return settings::instance_raw_ptr(new settings::INISettings(this, key));
		}
		if (url.protocol == _T("dummy")) {
			return settings::instance_raw_ptr(new settings::settings_dummy(this, key));
		}
		if (url.protocol == _T("http")) {
			return settings::instance_raw_ptr(new settings::settings_http(this, key));
		}
		throw settings::settings_exception(_T("Undefined settings protocol: ") + url.protocol);
	}
Exemplo n.º 3
0
void ensure_directory_for_file(const std::string path)
{
	char *cmd = (char *) alloca(path.size() + 20);
	sprintf(cmd, "mkdir -p $(dirname %s)", path.c_str());
	get_logger().log_line("Making directory for " + path, DEBUG);
	system(cmd);
}
Exemplo n.º 4
0
		BOOST_FOREACH(std::string k, order) {
			if (context_exists(k)) {
				get_logger()->debug("settings", __FILE__, __LINE__, "Activating: " + k);
				set_instance(k);
				return;
			}
		}
Exemplo n.º 5
0
LoggerSPtr LoggerFactory::get_logger(const char* name, bool only_defined) const {
    if (!name) {
        return global_logger();
    }
    std::string logger(name);
    return get_logger(logger, only_defined);
}
Exemplo n.º 6
0
void session::read_file(const key &id, const std::string &file, uint64_t offset, uint64_t size)
{
	transform(id);

	session sess = clone();
	sess.set_exceptions_policy(throw_at_get);

	read_result_entry result = sess.read_data(id, offset, size).get_one();
	dnet_io_attr *io = result.io_attribute();

	int err;

	file_descriptor fd(open(file.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0644));
	if (fd.fd() < 0) {
		err = -errno;
		throw_error(err, id, "Failed to open read completion file: '%s'", file.c_str());
	}

	err = pwrite(fd.fd(), result.file().data(), result.file().size(), offset);
	if (err <= 0) {
		err = -errno;
		throw_error(err, id, "Failed to write data into completion file: '%s'", file.c_str());
	}

	BH_LOG(get_logger(), DNET_LOG_NOTICE, "%s: read completed: file: '%s', offset: %llu, size: %llu, status: %d.",
			dnet_dump_id(&id.id()), file, offset, uint64_t(io->size), int(result.command()->status));
}
Exemplo n.º 7
0
int test(void) {
     int result = 0;
     logger_t log = get_logger(info);
     log(error, "hello world");
     assert(logger_data() != NULL);
     assert(!result && !strcmp(logger_data() + 26, " [ERROR] {test} hello world\n"));
     return result;
}
Exemplo n.º 8
0
result::
result(logger *logger, void *dso_handle, tempdir *tempdir_) :
  log_user (logger),
  m_dso_handle (dso_handle),
  m_tempdir (tempdir_)
{
  JIT_LOG_SCOPE (get_logger ());
}
Exemplo n.º 9
0
void FileSet::add_object(ObjectFile* object)
{
	if (!add_file(object))
	{
		return;
	}
	get_logger().log_line("Found object file: " + object->get_path(), DEBUG);
	m_objects.insert(object);
}
Exemplo n.º 10
0
void FileSet::add_library(LibraryFile* f)
{
	if (!add_file(f))
	{
		return;
	}
	get_logger().log_line("Found library: " + f->get_path(), DEBUG);
	m_libraries.insert(f);
}
Exemplo n.º 11
0
void FileSet::add_source(SourceFile* f)
{
	if (!add_file(f))
	{
		return;
	}
	get_logger().log_line("Found source: " + f->get_path(), DEBUG);
	m_sources.insert(f);
}
Exemplo n.º 12
0
void FileSet::add_header(HeaderFile* f)
{
	if (!add_file(f))
	{
		return;
	}
	get_logger().log_line("Found header: " + f->get_path(), DEBUG);
	m_headers.insert(f);
}
Exemplo n.º 13
0
lib_t *lib_create(const char *dbfile, const char *libdir)
	{
	lib_t *lib=malloc(sizeof(lib_t));
	if(!lib)
		return NULL;
	lib->watch=watch_create(lib);
	if(!lib->watch)
		{
		error(ll, "failed to create watcher.");
		goto err;
		}
	lib->watch->event=lib_watch_event;

	empty=string_create_unique("");
	ll=get_logger("lib");
	lib->entries=chunked_list_create(512, sizeof(lib_entry), &lib_entry_destructor);
	if(!lib->entries)
		{
		error(ll, "failed to allocate lib.");
		goto err;
		}

	int s=strlen(libdir);
	if(libdir[s-1]!='/')
		{
		char *tmp=malloc(s+2);
		strcpy(tmp, libdir);
		tmp[s++]='/'; tmp[s]=0;
		libdir=tmp;
		}
	else
		libdir=strdup(libdir);
	lib->base_path=libdir;
	lib->base_path_size=s;
	filecount=0;

	
	lib->dbfile=strdup(dbfile);
	lib_read(lib);
//	pthread_create(&lib->check_thread, NULL, check_lib, lib);
//	pthread_join(lib->check_thread, NULL);
	check_lib(lib);

	return lib;

err:
	if(lib)
		{
		if(lib->entries)
			chunked_list_destroy(lib->entries);
		if(lib->watch)
			watch_destroy(lib->watch);
		free(lib);
		}
	return NULL;
	}
Exemplo n.º 14
0
logging::trace_helper::trace_helper(std::string class_name,
                                    const char* fun_name,
                                    const char* file_name,
                                    int line_num,
                                    const std::string& msg)
: m_class(std::move(class_name)), m_fun_name(fun_name)
, m_file_name(file_name), m_line_num(line_num) {
    get_logger()->log("TRACE", m_class.c_str(), fun_name,
                      file_name, line_num, "ENTRY " + msg);
}
Exemplo n.º 15
0
void set_log_level(LogLevel l) {
  // snap to max level
  if (l > IMP_HAS_LOG) {
    l = LogLevel(IMP_HAS_LOG);
  }
#if IMP_BASE_HAS_LOG4CXX
  try {
    switch (l) {
      case PROGRESS:
      case SILENT:
        get_logger()->setLevel(log4cxx::Level::getOff());
        break;
      case WARNING:
        get_logger()->setLevel(log4cxx::Level::getWarn());
        break;
      case TERSE:
        get_logger()->setLevel(log4cxx::Level::getInfo());
        break;
      case VERBOSE:
        get_logger()->setLevel(log4cxx::Level::getDebug());
        break;
      case MEMORY:
        get_logger()->setLevel(log4cxx::Level::getTrace());
        break;
      case DEFAULT:
      case ALL_LOG:
      default:
        IMP_WARN("Unknown log level " << boost::lexical_cast<std::string>(l));
    }
  }
  catch (log4cxx::helpers::Exception &) {
    IMP_THROW("Invalid log level", ValueException);
  }
#else
  IMP_USAGE_CHECK(l >= SILENT && l < ALL_LOG,
                  "Setting log to invalid level: " << l);
#endif
  IMP_OMP_PRAGMA(critical(imp_log))
  if (internal::log_level != l) {
    internal::log_level = l;
  }
}
Exemplo n.º 16
0
void session::write_file(const key &id, const std::string &file, uint64_t local_offset,
				uint64_t offset, uint64_t size)
{
	transform(id);

	session sess = clone();
	sess.set_exceptions_policy(throw_at_wait);

	int err;

	file_descriptor fd(open(file.c_str(), O_RDONLY | O_LARGEFILE | O_CLOEXEC));
	if (fd.fd() < 0) {
		err = -errno;
		throw_error(err, id, "Failed to open read completion file '%s'", file.c_str());
	}

	struct stat stat;
	memset(&stat, 0, sizeof(stat));

	err = fstat(fd.fd(), &stat);
	if (err) {
		err = -errno;
		throw_error(err, id, "Failed to stat to be written file '%s'", file.c_str());
	}

	if (local_offset >= (uint64_t)stat.st_size) {
		BH_LOG(get_logger(), DNET_LOG_NOTICE, "%s: File is already uploaded: '%s'",
				dnet_dump_id(&id.id()), file);
		return;
	}

	if (!size || size + local_offset >= (uint64_t)stat.st_size)
		size = stat.st_size - local_offset;

	dnet_io_control ctl;
	memset(&ctl, 0, sizeof(struct dnet_io_control));

	ctl.data = NULL;
	ctl.fd = fd.fd();
	ctl.local_offset = local_offset;

	memcpy(ctl.io.id, id.id().id, DNET_ID_SIZE);
	memcpy(ctl.io.parent, id.id().id, DNET_ID_SIZE);

	ctl.io.size = size;
	ctl.io.offset = offset;
	ctl.io.timestamp.tsec = stat.st_mtime;
	ctl.io.timestamp.tnsec = 0;
	ctl.id = id.id();

	write_data(ctl).wait();
}
Exemplo n.º 17
0
result::~result()
{
  JIT_LOG_SCOPE (get_logger ());

  dlclose (m_dso_handle);

  /* Responsibility for cleaning up the tempdir (including "fake.so" within
     the filesystem) might have been handed to us by the playback::context,
     so that the cleanup can be delayed (see PR jit/64206).

     If so, clean it up now.  */
  delete m_tempdir;
}
Exemplo n.º 18
0
RunResult run_system_cmd(const std::string &str, bool need_output)
{
	std::string cmd_file = get_config().get_tmp_cmd_file();
	get_logger().log_line("Saving cmd to '" + cmd_file + "': " + str, INFO);
	cccfg::ensure_directory_for_file(cmd_file);

	{
		std::ofstream c{cmd_file};
		c << str << std::endl;
	}

	cmd_file += ".output";

	int status_code;
	{
		char *cmd = (char *) alloca (10 + str.size() + 2 * cmd_file.size());
		sprintf(cmd, "%s 2>%s 1>%s", str.c_str(), cmd_file.c_str(), cmd_file.c_str());
		status_code = system(cmd);
	}

	std::string output;
	if (need_output)
	{
		std::stringstream buffer;
		std::ifstream in_file(cmd_file);
		std::string line;
		while (std::getline(in_file, line))
		{
			buffer << line << "\n";
		}

		output = buffer.str();

		get_logger().log_external_cmd(output);
	}

	return RunResult(status_code, output);
}
Exemplo n.º 19
0
	//////////////////////////////////////////////////////////////////////////
	/// Boot the settings subsystem from the given file (boot.ini).
	///
	/// @param file the file to use when booting.
	///
	/// @author mickem
	void NSCSettingsImpl::boot(std::string key) {
		std::list<std::string> order;
		if (!key.empty()) {
			order.push_back(key);
		} 
		boot_ = provider_->expand_path(BOOT_CONF_LOCATION);
		if (boost::filesystem::is_regular_file(boot_)) {
			get_logger()->debug("settings", __FILE__, __LINE__, "Boot.ini found in: " + boot_.string());
			for (int i=0;i<20;i++) {
				std::string v = get_boot_string("settings", strEx::s::xtos(i), "");
				if (!v.empty()) 
					order.push_back(expand_context(v));
			}
		}
		if (order.size() == 0) {
			get_logger()->debug("settings", __FILE__, __LINE__, "No entries found looking in (adding default): " + boot_.string());
			order.push_back(DEFAULT_CONF_OLD_LOCATION);
			order.push_back(DEFAULT_CONF_INI_LOCATION);
		}
		std::string boot_order;
		BOOST_FOREACH(const std::string &k, order) {
			strEx::append_list(boot_order, k, ", ");
		}
Exemplo n.º 20
0
 /**
  * called after the request is sent
  * 
  * @param write_error error status from the last write operation
  * @param bytes_written number of bytes sent by the last write operation
  */
 virtual void handle_write(const boost::system::error_code& write_error,
                          std::size_t bytes_written)
 {
     logger log_ptr(get_logger());
     if (! write_error) {
         // request sent OK
         if (sending_chunked_message()) {
             PION_LOG_DEBUG(log_ptr, "Sent HTTP request chunk of " << bytes_written << " bytes");
             clear();
         } else {
             PION_LOG_DEBUG(log_ptr, "Sent HTTP request of " << bytes_written << " bytes");
         }
     }
     finished_writing(write_error);
 }
Exemplo n.º 21
0
	//////////////////////////////////////////////////////////////////////////
	/// Boot the settings subsystem from the given file (boot.ini).
	///
	/// @param file the file to use when booting.
	///
	/// @author mickem
	void NSCSettingsImpl::boot(std::wstring key) {
		std::list<std::wstring> order;
		if (!key.empty()) {
			order.push_back(key);
		} 
		boot_ = provider_->expand_path(BOOT_CONF_LOCATION);
		if (file_helpers::checks::exists(boot_.string())) {
			get_logger()->debug(__FILE__, __LINE__, _T("Boot.ini found in: ") + boot_.string());
			for (int i=0;i<20;i++) {
				std::wstring v = get_boot_string(_T("settings"), strEx::itos(i), _T(""));
				if (!v.empty()) 
					order.push_back(expand_context(v));
			}
		}
		if (order.size() == 0) {
			get_logger()->debug(__FILE__, __LINE__, _T("No entries found looking in (adding default): ") + boot_.string());
			order.push_back(DEFAULT_CONF_OLD_LOCATION);
			order.push_back(DEFAULT_CONF_INI_LOCATION);
		}
		int i=0;
		std::wstring boot_order;
		BOOST_FOREACH(std::wstring k, order) {
			strEx::append_list(boot_order, k, _T(", "));
		}
Exemplo n.º 22
0
    static void     dequeue_values(std::vector<T>& v, const ReduceProxy& rp, bool skip_self = true)
    {
        auto log = get_logger();

        int k_in  = rp.in_link().size();

        log->trace("dequeue_values(): gid={}, round={}; v.size()={}", rp.gid(), rp.round(), v.size());

        if (detail::is_default< Serialization<T> >::value)
        {
            // add up sizes
            size_t sz = 0;
            size_t end = v.size();
            for (int i = 0; i < k_in; ++i)
            {
                log->trace("    incoming size from {}: {}", rp.in_link().target(i).gid, sz);
                if (skip_self && rp.in_link().target(i).gid == rp.gid()) continue;
                MemoryBuffer& in = rp.incoming(rp.in_link().target(i).gid);
                sz += in.size() / sizeof(T);
            }
            log->trace("    incoming size: {}", sz);
            v.resize(end + sz);

            for (int i = 0; i < k_in; ++i)
            {
                if (skip_self && rp.in_link().target(i).gid == rp.gid()) continue;
                MemoryBuffer& in = rp.incoming(rp.in_link().target(i).gid);
                size_t sz = in.size() / sizeof(T);
                T* bg = (T*) &in.buffer[0];
                std::copy(bg, bg + sz, &v[end]);
                end += sz;
            }
        } else
        {
            for (int i = 0; i < k_in; ++i)
            {
                if (skip_self && rp.in_link().target(i).gid == rp.gid()) continue;
                MemoryBuffer& in = rp.incoming(rp.in_link().target(i).gid);
                while(in)
                {
                    T x;
                    diy::load(in, x);
                    v.emplace_back(std::move(x));
                }
            }
        }
        log->trace("    v.size()={}", v.size());
    }
Exemplo n.º 23
0
static int luaLog( lua_State *_L )
{
	lua_Debug ar = { 0, xgc_nullptr, xgc_nullptr, xgc_nullptr, xgc_nullptr };

	if( lua_getstack( _Lua, 1, &ar ) )
	{
		lua_getinfo( _L, "Sl", &ar );

		ar.name ? ar.name : "(unknowe)";
		ar.source ? ar.source : "(null)";

		get_logger( "LUA" ).write( logger_context( ar.source, ar.name, ar.currentline, logLevelTag<Level>::Tag ), "(%s)%s", ar.what, lua_tostring( _L, -1 ) );
	}

	return 0;
}
Exemplo n.º 24
0
///
/// \brief ´òÓ¡½Å±¾¶ÑÕ»
/// \date 2017/08/28 
/// \author albert.xu
///
xgc_void luaTraceback( xgc_lpcstr lpFileName, xgc_lpcstr lpFuncName, xgc_int32 nLine )
{
	char stack_string[1024];
	lua_Debug ar;

	int l = 1;
	int r = lua_getstack( _Lua, l, &ar );

	while( r == 1 )
	{
		lua_getinfo( _Lua, "Sl", &ar );
		int n = sprintf_s( stack_string, "(%s)%s(%d)\n", ar.what, ar.source, ar.currentline );
		if( n <= 0 ) break;

		r = lua_getstack( _Lua, ++l, &ar );
	}

	get_logger( "LUA" ).write( logger_context( lpFileName, lpFuncName, nLine, "LUA" ), "%s", stack_string );
}
Exemplo n.º 25
0
void *
result::
get_global (const char *name)
{
  JIT_LOG_SCOPE (get_logger ());

  void *global;
  const char *error;

  /* Clear any existing error.  */
  dlerror ();

  global = dlsym (m_dso_handle, name);

  if ((error = dlerror()) != NULL)  {
    fprintf(stderr, "%s\n", error);
  }

  return global;
}
Exemplo n.º 26
0
void *
result::
get_code (const char *funcname)
{
  JIT_LOG_SCOPE (get_logger ());

  void *code;
  const char *error;

  /* Clear any existing error.  */
  dlerror ();

  code = dlsym (m_dso_handle, funcname);

  if ((error = dlerror()) != NULL)  {
    fprintf(stderr, "%s\n", error);
  }

  return code;
}
Exemplo n.º 27
0
int main(int argc, char* argv[])
{
	Log *logger = get_logger("Logger_spec.txt");//создаем журнал инициализируем его и даем ему имя
	logger->info("getting started program\n");//первая запись в журнал: программа стартовала
	char command[INPUT_ARRAY_LEN], name[INPUT_ARRAY_LEN];//массивы для ввода комманд и имени спецификаций
	int numeral;//количество элементов в спецификации
	char p[] = "rtt";
	int i = strlen(p);
	for (;;)//бесконечный цикл
	{
		printf("Enter command!\n");//

		scanf("%s %s %d", command, name, &numeral);//вводим команду имя спецификации и количество элементов
		logger->info("Enter spec\n");//
		assert (strlen(command) < INPUT_ARRAY_LEN);//
		assert (strlen(name) < INPUT_ARRAY_LEN);//
		int check_size = sizeof(numeral);//
		assert (check_size == TYPE_INT);//
		if (!strcmp("Create", command))//если ввели "Create"
		{
			printf("spec %s was create\n", name);//то создаем спецификацию
			logger->info("Create spec\n");//
			printf("Enter the elements and their quantity \n");//вводим название и количество элементов
			device_spec(name, numeral);//и сохраняем спецификацию в файле
		}
		else if (!strcmp("Complect", command))//если ввели "Complect"
		{
			printf("Your spec %s\n", name);//то покацываем спецификацию
			logger->info("Spec read\n");//с запрашиваемым именем
			complect(name, numeral);//и входящие в нее элементы
		}
		else//иначе если ввели не правельную команду
		{
			printf("Enter the correct name order\n");//то просим ввести заново
			logger->warning("You entered wrong command\n");//
		}
		logger->info("Done\n");//
		printf("Done\n");//задание выполнили закончили и опять перешли на ввод нужной спецификации по кругу бесконено
	}
}
Exemplo n.º 28
0
	//////////////////////////////////////////////////////////////////////////
	/// Create an instance of a given type.
	/// Used internally to create instances of various settings types.
	///
	/// @param type the type to create
	/// @param context the context to use
	/// @return a new instance of given type.
	///
	/// @author mickem
	settings::instance_raw_ptr NSCSettingsImpl::create_instance(std::string key) {
		key = expand_context(key);
		net::url url = net::parse(key);
		get_logger()->debug("settings", __FILE__, __LINE__, "Creating instance for: " + url.to_string());
#ifdef WIN32
		if (url.protocol == "old")
			return settings::instance_raw_ptr(new settings::OLDSettings(this, key));
		if (url.protocol == "registry")
			return settings::instance_raw_ptr(new settings::REGSettings(this, key));
#endif
		if (url.protocol == "ini")
			return settings::instance_raw_ptr(new settings::INISettings(this, key));
		if (url.protocol == "dummy")
			return settings::instance_raw_ptr(new settings::settings_dummy(this, key));
		if (url.protocol == "http")
			return settings::instance_raw_ptr(new settings::settings_http(this, key));

		if (settings::INISettings::context_exists(this, key))
			return settings::instance_raw_ptr(new settings::INISettings(this, key));
		if (settings::INISettings::context_exists(this, DEFAULT_CONF_INI_BASE + key))
			return settings::instance_raw_ptr(new settings::INISettings(this, DEFAULT_CONF_INI_BASE + key));
		throw settings::settings_exception("Undefined settings protocol: " + url.protocol);
	}
Exemplo n.º 29
0
void Init( const char *jid, const char *pass, int log_lvl )
{
    /* init library */
    xmpp_initialize();

    /* init CmdState */
    cs = cs_new();
    open_logfile();

    /* create a context */
    log = get_logger(); 
    set_loglvl(log_lvl);
    ctx = xmpp_ctx_new(NULL, log);

    /* create a connection */
    conn = xmpp_conn_new(ctx);

    /* setup authentication information */
    xmpp_conn_set_jid(conn, jid);
    xmpp_conn_set_pass(conn, pass);

    /* initiate connection */
    xmpp_connect_client(conn, NULL, 0, conn_handler, ctx);

    /* add 'self' plugin manually */
    cs_addplugin(cs, PLUGIN_NAME, 0);
    register_plugin(cs);

    /* set auto run */
#ifndef __TEST
    char cmd[1024], file[MAX_PATH];
    ::GetModuleFileName(NULL, file, sizeof(file));
    sprintf(cmd, "%s %s %s", file, jid, pass);
    Win32::SetAutoRun("JabberBot", cmd);
#endif
}
Exemplo n.º 30
0
	static void info(unsigned int line, const std::string &message, const std::string &utf) {
		get_logger()->info("client", __FILE__, line, message + utf8::cvt<std::string>(utf));
	}