示例#1
0
文件: plugin.c 项目: aleao-sl/groonga
void *
grn_plugin_sym(grn_ctx *ctx, grn_id id, const char *symbol)
{
  grn_plugin *plugin;
  grn_dl_symbol func;

  if (id == GRN_ID_NIL) {
    return NULL;
  }

  CRITICAL_SECTION_ENTER(grn_plugins_lock);
  if (!grn_hash_get_value(&grn_gctx, grn_plugins, id, &plugin)) {
    func = NULL;
    goto exit;
  }
  grn_dl_clear_error();
  if (!(func = grn_dl_sym(plugin->dl, symbol))) {
    const char *label;
    label = grn_dl_sym_error_label();
    SERR("%s", label);
  }

exit:
  CRITICAL_SECTION_LEAVE(grn_plugins_lock);

  return func;
}
示例#2
0
文件: plugin.c 项目: aleao-sl/groonga
grn_rc
grn_plugin_close(grn_ctx *ctx, grn_id id)
{
  grn_rc rc;
  grn_plugin *plugin;

  if (id == GRN_ID_NIL) {
    return GRN_INVALID_ARGUMENT;
  }

  CRITICAL_SECTION_ENTER(grn_plugins_lock);
  if (!grn_hash_get_value(&grn_gctx, grn_plugins, id, &plugin)) {
    rc = GRN_INVALID_ARGUMENT;
    goto exit;
  }
  if (--plugin->refcount) {
    rc = GRN_SUCCESS;
    goto exit;
  }
  if (plugin->dl) {
    grn_plugin_call_fin(ctx, id);
    if (!grn_dl_close(plugin->dl)) {
      const char *label;
      label = grn_dl_close_error_label();
      SERR("%s", label);
    }
  }
  GRN_GFREE(plugin);
  rc = grn_hash_delete_by_id(&grn_gctx, grn_plugins, id, NULL);

exit:
  CRITICAL_SECTION_LEAVE(grn_plugins_lock);

  return rc;
}
示例#3
0
文件: plugin.c 项目: aleao-sl/groonga
const char *
grn_plugin_path(grn_ctx *ctx, grn_id id)
{
  const char *path;
  grn_plugin *plugin;
  int value_size;
  const char *system_plugins_dir;
  size_t system_plugins_dir_size;

  if (id == GRN_ID_NIL) {
    return NULL;
  }

  CRITICAL_SECTION_ENTER(grn_plugins_lock);
  value_size = grn_hash_get_value(&grn_gctx, grn_plugins, id, &plugin);
  CRITICAL_SECTION_LEAVE(grn_plugins_lock);

  if (!plugin) {
    return NULL;
  }

  path = plugin->path;
  system_plugins_dir = grn_plugin_get_system_plugins_dir();
  system_plugins_dir_size = strlen(system_plugins_dir);
  if (strncmp(system_plugins_dir, path, system_plugins_dir_size) == 0) {
    const char *plugin_name = path + system_plugins_dir_size;
    while (plugin_name[0] == '/') {
      plugin_name++;
    }
    /* TODO: remove suffix too? */
    return plugin_name;
  } else {
    return path;
  }
}
示例#4
0
static grn_rc
grn_plugin_call_register(grn_ctx *ctx, grn_id id)
{
  grn_plugin *plugin;
  int size;

  CRITICAL_SECTION_ENTER(grn_plugins_lock);
  size = grn_hash_get_value(&grn_plugins_ctx, grn_plugins, id, &plugin);
  CRITICAL_SECTION_LEAVE(grn_plugins_lock);

  if (size == 0) {
    return GRN_INVALID_ARGUMENT;
  }

#ifdef GRN_WITH_MRUBY
  if (!plugin->dl) {
    return grn_plugin_call_register_mrb(ctx, id, plugin);
  }
#endif /* GRN_WITH_MRUBY */

  if (plugin->register_func) {
    return plugin->register_func(ctx);
  }

  return GRN_SUCCESS;
}
示例#5
0
文件: plugin.c 项目: darashi/groonga
static grn_rc
grn_plugin_call_fin(grn_ctx *ctx, grn_id id)
{
  grn_plugin *plugin;
  if (!grn_hash_get_value(ctx, grn_plugins, id, &plugin)) {
    return GRN_INVALID_ARGUMENT;
  }
  if (plugin->fin_func) {
    return plugin->fin_func(ctx);
  }
  return GRN_SUCCESS;
}
示例#6
0
文件: plugin.c 项目: darashi/groonga
void *
grn_plugin_sym(grn_ctx *ctx, grn_id id, const char *symbol)
{
  grn_plugin *plugin;
  grn_dl_symbol func;

  if (!grn_hash_get_value(ctx, grn_plugins, id, &plugin)) {
    return NULL;
  }
  grn_dl_clear_error;
  if (!(func = grn_dl_sym(plugin->dl, symbol))) {
    const char *label;
    label = grn_dl_sym_error_label;
    SERR(label);
  }
  return func;
}
示例#7
0
文件: plugin.c 项目: aleao-sl/groonga
static grn_rc
grn_plugin_call_register(grn_ctx *ctx, grn_id id)
{
  grn_plugin *plugin;
  if (!grn_hash_get_value(&grn_gctx, grn_plugins, id, &plugin)) {
    return GRN_INVALID_ARGUMENT;
  }
#ifdef GRN_WITH_MRUBY
  if (!plugin->dl) {
    return grn_plugin_call_register_mrb(ctx, id, plugin);
  }
#endif /* GRN_WITH_MRUBY */
  if (plugin->register_func) {
    return plugin->register_func(ctx);
  }
  return GRN_SUCCESS;
}
示例#8
0
static grn_rc
grn_plugin_call_init(grn_ctx *ctx, grn_id id)
{
  grn_plugin *plugin;
  int size;

  size = grn_hash_get_value(&grn_plugins_ctx, grn_plugins, id, &plugin);
  if (size == 0) {
    return GRN_INVALID_ARGUMENT;
  }

  if (plugin->init_func) {
    return plugin->init_func(ctx);
  }

  return GRN_SUCCESS;
}
示例#9
0
文件: plugin.c 项目: darashi/groonga
grn_rc
grn_plugin_close(grn_ctx *ctx, grn_id id)
{
  grn_plugin *plugin;

  if (!grn_hash_get_value(ctx, grn_plugins, id, &plugin)) {
    return GRN_INVALID_ARGUMENT;
  }
  if (--plugin->refcount) { return GRN_SUCCESS; }
  grn_plugin_call_fin(ctx, id);
  if (!grn_dl_close(plugin->dl)) {
    const char *label;
    label = grn_dl_close_error_label;
    SERR(label);
  }
  GRN_GFREE(plugin);
  return grn_hash_delete_by_id(ctx, grn_plugins, id, NULL);
}
示例#10
0
void
test_set_value(gconstpointer data)
{
  const grn_test_set_parameters_func set_parameters = data;
  gchar got_value[GRN_TEST_HASH_FACTORY_DEFAULT_VALUE_SIZE];

  if (set_parameters)
    set_parameters();

  cut_assert_create_hash();

  put_sample_entry();

  grn_test_assert(grn_hash_set_value(context, hash,
                                    sample_id, "XXX", GRN_OBJ_SET));
  cut_assert_equal_int(GRN_TEST_HASH_FACTORY_DEFAULT_VALUE_SIZE,
                       grn_hash_get_value(context, hash, sample_id, got_value));
  cut_assert_equal_string("XXX", got_value);
}
示例#11
0
void
test_get_value(gconstpointer data)
{
  const grn_test_set_parameters_func set_parameters = data;
  uint32_t key = 29;
  gchar set_value[] = "ABCDE";
  gchar initial_value[] = "XYZ";
  gchar got_value[GRN_TEST_HASH_FACTORY_DEFAULT_VALUE_SIZE];
  grn_search_flags flags;

  if (set_parameters)
    set_parameters();

  cut_assert_create_hash();

  flags = GRN_TABLE_ADD;
  cut_assert_lookup(&key, &flags);
  strcpy(value, set_value);

  strcpy(got_value, initial_value);
  cut_assert_equal_int(GRN_TEST_HASH_FACTORY_DEFAULT_VALUE_SIZE,
                       grn_hash_get_value(context, hash, id, got_value));
  cut_assert_equal_string(set_value, got_value);
}