Browse Source

Implement clish_plugin_add_phook()

Serj Kalichev 11 years ago
parent
commit
2f12a71ce5
3 changed files with 23 additions and 17 deletions
  1. 3 3
      clish/builtin/builtin_init.c
  2. 3 1
      clish/plugin.h
  3. 17 13
      clish/plugin/plugin.c

+ 3 - 3
clish/builtin/builtin_init.c

@@ -12,11 +12,11 @@
 CLISH_PLUGIN_INIT
 {
 	/* Add hooks */
-	clish_plugin_add_hook(plugin, clish_hook_access,
+	clish_plugin_add_phook(plugin, clish_hook_access,
 		"clish_hook_access", CLISH_SYM_TYPE_ACCESS);
-	clish_plugin_add_hook(plugin, clish_hook_config,
+	clish_plugin_add_phook(plugin, clish_hook_config,
 		"clish_hook_config", CLISH_SYM_TYPE_CONFIG);
-	clish_plugin_add_hook(plugin, clish_hook_log,
+	clish_plugin_add_phook(plugin, clish_hook_log,
 		"clish_hook_log", CLISH_SYM_TYPE_LOG);
 
 	/* Add builtin syms */

+ 3 - 1
clish/plugin.h

@@ -82,13 +82,15 @@ void *clish_plugin_load(clish_plugin_t *instance);
 clish_sym_t *clish_plugin_get_sym(clish_plugin_t *instance,
 	const char *name, int type);
 clish_sym_t *clish_plugin_add_generic(clish_plugin_t *instance,
-	void *func, const char *name, int type);
+	void *func, const char *name, int type, bool_t permanent);
 clish_sym_t *clish_plugin_add_sym(clish_plugin_t *instance,
 	clish_hook_action_fn_t *func, const char *name);
 clish_sym_t *clish_plugin_add_psym(clish_plugin_t *instance,
 	clish_hook_action_fn_t *func, const char *name);
 clish_sym_t *clish_plugin_add_hook(clish_plugin_t *instance,
 	void *func, const char *name, int type);
+clish_sym_t *clish_plugin_add_phook(clish_plugin_t *instance,
+	void *func, const char *name, int type);
 void clish_plugin_dump(const clish_plugin_t *instance);
 char *clish_plugin__get_name(const clish_plugin_t *instance);
 char *clish_plugin__get_file(const clish_plugin_t *instance);

+ 17 - 13
clish/plugin/plugin.c

@@ -176,7 +176,7 @@ void clish_plugin_free(clish_plugin_t *this)
 
 /*--------------------------------------------------------- */
 clish_sym_t *clish_plugin_add_generic(clish_plugin_t *this,
-	void *func, const char *name, int type)
+	void *func, const char *name, int type, bool_t permanent)
 {
 	clish_sym_t *sym;
 
@@ -186,6 +186,7 @@ clish_sym_t *clish_plugin_add_generic(clish_plugin_t *this,
 	if (!(sym = clish_sym_new(name, func, type)))
 		return NULL;
 	clish_sym__set_plugin(sym, this);
+	clish_sym__set_permanent(sym, permanent);
 	lub_list_add(this->syms, sym);
 
 	return sym;
@@ -196,7 +197,16 @@ clish_sym_t *clish_plugin_add_sym(clish_plugin_t *this,
 	clish_hook_action_fn_t *func, const char *name)
 {
 	return clish_plugin_add_generic(this, func,
-		name, CLISH_SYM_TYPE_ACTION);
+		name, CLISH_SYM_TYPE_ACTION, BOOL_FALSE);
+}
+
+/*--------------------------------------------------------- */
+/* Add permanent symbol (can't be turned off by dry-run) */
+clish_sym_t *clish_plugin_add_psym(clish_plugin_t *this,
+	clish_hook_action_fn_t *func, const char *name)
+{
+	return clish_plugin_add_generic(this, func,
+		name, CLISH_SYM_TYPE_ACTION, BOOL_TRUE);
 }
 
 /*--------------------------------------------------------- */
@@ -204,21 +214,15 @@ clish_sym_t *clish_plugin_add_hook(clish_plugin_t *this,
 	void *func, const char *name, int type)
 {
 	return clish_plugin_add_generic(this, func,
-		name, type);
+		name, type, BOOL_FALSE);
 }
 
 /*--------------------------------------------------------- */
-/* Add permanent symbol (can't be turned off by dry-run) */
-clish_sym_t *clish_plugin_add_psym(clish_plugin_t *this,
-	clish_hook_action_fn_t *func, const char *name)
+clish_sym_t *clish_plugin_add_phook(clish_plugin_t *this,
+	void *func, const char *name, int type)
 {
-	clish_sym_t *sym;
-
-	if (!(sym = clish_plugin_add_sym(this, func, name)))
-		return NULL;
-	clish_sym__set_permanent(sym, BOOL_TRUE);
-
-	return sym;
+	return clish_plugin_add_generic(this, func,
+		name, type, BOOL_TRUE);
 }
 
 /*--------------------------------------------------------- */