Browse Source

Add osym API for builtin funcs

Serj Kalichev 8 years ago
parent
commit
1ee6361ced
3 changed files with 62 additions and 7 deletions
  1. 20 6
      clish/plugin.h
  2. 41 1
      clish/plugin/plugin.c
  3. 1 0
      clish/plugin/private.h

+ 20 - 6
clish/plugin.h

@@ -12,16 +12,22 @@
 
 /* Symbol */
 
-/* Symbol types. Functions with different definition. */
+/* Symbol types. Functions with different purposes. */
 typedef enum {
 	CLISH_SYM_TYPE_NONE = 0, /* None */
-	CLISH_SYM_TYPE_ACTION, /* Common builtin symbol */
-	CLISH_SYM_TYPE_ACCESS,
-	CLISH_SYM_TYPE_CONFIG,
-	CLISH_SYM_TYPE_LOG,
+	CLISH_SYM_TYPE_ACTION, /* Common builtin symbol for ACTION tag */
+	CLISH_SYM_TYPE_ACCESS, /* Callback for "access" field */
+	CLISH_SYM_TYPE_CONFIG, /* Callback for CONFIG tag */
+	CLISH_SYM_TYPE_LOG, /* Callback for logging */
 	CLISH_SYM_TYPE_MAX /* Number of elements */
 } clish_sym_type_e;
 
+/* External functions APIs. */
+typedef enum {
+	CLISH_SYM_API_SIMPLE = 0, /* Simple (may be single) API */
+	CLISH_SYM_API_STDOUT /* Symbol for ACTION tag without "out" argument */
+} clish_sym_api_e;
+
 typedef struct clish_sym_s clish_sym_t;
 typedef struct clish_plugin_s clish_plugin_t;
 
@@ -36,6 +42,7 @@ typedef struct clish_plugin_s clish_plugin_t;
 
 #define CLISH_PLUGIN_FINI(name) int name(void *clish_shell, clish_plugin_t *plugin)
 #define CLISH_PLUGIN_SYM(name) int name(void *clish_context, const char *script, char **out)
+#define CLISH_PLUGIN_OSYM(name) int name(void *clish_context, const char *script)
 #define CLISH_HOOK_ACCESS(name) int name(void *clish_shell, const char *access)
 #define CLISH_HOOK_CONFIG(name) int name(void *clish_context)
 #define CLISH_HOOK_LOG(name) int name(void *clish_context, const char *line, int retcode)
@@ -43,6 +50,7 @@ typedef struct clish_plugin_s clish_plugin_t;
 typedef CLISH_PLUGIN_INIT_FUNC(clish_plugin_init_t);
 typedef CLISH_PLUGIN_FINI(clish_plugin_fini_t);
 typedef CLISH_PLUGIN_SYM(clish_hook_action_fn_t);
+typedef CLISH_PLUGIN_OSYM(clish_hook_oaction_fn_t);
 typedef CLISH_HOOK_ACCESS(clish_hook_access_fn_t);
 typedef CLISH_HOOK_CONFIG(clish_hook_config_fn_t);
 typedef CLISH_HOOK_LOG(clish_hook_log_fn_t);
@@ -72,7 +80,9 @@ bool_t clish_sym__get_permanent(clish_sym_t *instance);
 void clish_sym__set_plugin(clish_sym_t *instance, clish_plugin_t *plugin);
 clish_plugin_t *clish_sym__get_plugin(clish_sym_t *instance);
 void clish_sym__set_type(clish_sym_t *instance, int type);
-int clish_sym__get_type(clish_sym_t *instance);
+int clish_sym__get_type(const clish_sym_t *instance);
+void clish_sym__set_api(clish_sym_t *instance, clish_sym_api_e api);
+clish_sym_api_e clish_sym__get_api(const clish_sym_t *instance);
 int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src);
 
 /* Plugin */
@@ -88,6 +98,10 @@ 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_osym(clish_plugin_t *instance,
+	clish_hook_action_fn_t *func, const char *name);
+clish_sym_t *clish_plugin_add_posym(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,

+ 41 - 1
clish/plugin/plugin.c

@@ -40,6 +40,7 @@ clish_sym_t *clish_sym_new(const char *name, void *func, int type)
 	this->name = lub_string_dup(name);
 	this->func = func;
 	this->type = type;
+	this->api = CLISH_SYM_API_SIMPLE;
 	this->permanent = BOOL_FALSE;
 
 	return this;
@@ -110,11 +111,23 @@ void clish_sym__set_type(clish_sym_t *this, int type)
 }
 
 /*--------------------------------------------------------- */
-int clish_sym__get_type(clish_sym_t *this)
+int clish_sym__get_type(const clish_sym_t *this)
 {
 	return this->type;
 }
 
+/*--------------------------------------------------------- */
+void clish_sym__set_api(clish_sym_t *this, clish_sym_api_e api)
+{
+	this->api = api;
+}
+
+/*--------------------------------------------------------- */
+clish_sym_api_e clish_sym__get_api(const clish_sym_t *this)
+{
+	return this->api;
+}
+
 /*--------------------------------------------------------- */
 int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src)
 {
@@ -223,6 +236,33 @@ clish_sym_t *clish_plugin_add_psym(clish_plugin_t *this,
 		name, CLISH_SYM_TYPE_ACTION, BOOL_TRUE);
 }
 
+/*--------------------------------------------------------- */
+clish_sym_t *clish_plugin_add_osym(clish_plugin_t *this,
+	clish_hook_action_fn_t *func, const char *name)
+{
+	clish_sym_t *s;
+
+	if (!(s = clish_plugin_add_sym(this, func, name)))
+		return s;
+	clish_sym__set_api(s, CLISH_SYM_API_STDOUT);
+
+	return s;
+}
+
+/*--------------------------------------------------------- */
+/* Add permanent symbol (can't be turned off by dry-run) */
+clish_sym_t *clish_plugin_add_posym(clish_plugin_t *this,
+	clish_hook_action_fn_t *func, const char *name)
+{
+	clish_sym_t *s;
+
+	if (!(s = clish_plugin_add_psym(this, func, name)))
+		return s;
+	clish_sym__set_api(s, CLISH_SYM_API_STDOUT);
+
+	return s;
+}
+
 /*--------------------------------------------------------- */
 clish_sym_t *clish_plugin_add_hook(clish_plugin_t *this,
 	void *func, const char *name, int type)

+ 1 - 0
clish/plugin/private.h

@@ -13,6 +13,7 @@ struct clish_sym_s {
 	char *name; /* Symbol name */
 	void *func; /* Function address */
 	int type; /* Function type */
+	clish_sym_api_e api; /* Function API */
 	bool_t permanent; /* If permanent the dry-run can't switch it off */
 	clish_plugin_t *plugin; /* Parent plugin */
 };