Debian Codegraph @

doc/source/reference/api/plugin.rst

raw
1 .. -*- rst -*-
2
3 Plugin
4 ======
5
6 Summary
7 -------
8
9 Groonga supports plugin. You can create a new plugin with the
10 following API.
11
12 TOOD: Describe about how to create the minimum plugin here or create a
13 tutorial about it.
14
15 Reference
16 ---------
17
18 .. c:function:: grn_rc GRN_PLUGIN_INIT(grn_ctx *ctx)
19
20 .. c:function:: grn_rc GRN_PLUGIN_REGISTER(grn_ctx *ctx)
21
22 .. c:function:: grn_rc GRN_PLUGIN_FIN(grn_ctx *ctx)
23
24 .. c:macro:: GRN_PLUGIN_MALLOC(ctx, size)
25
26 GRN_PLUGIN_MALLOC() allocates `size` bytes and returns a pointer to the
27 allocated memory space. Note that the memory space is associated with `ctx`.
28
29 .. c:macro:: GRN_PLUGIN_REALLOC(ctx, ptr, size)
30
31 GRN_PLUGIN_REALLOC() resizes the memory space pointed to by `ptr` or
32 allocates a new memory space of `size` bytes. GRN_PLUGIN_REALLOC() returns
33 a pointer to the memory space. The contents is unchanged or copied from the
34 old memory space to the new memory space.
35
36 .. c:macro:: GRN_PLUGIN_FREE(ctx, ptr)
37
38 GRN_PLUGIN_FREE() frees a memory space allocated by GRN_PLUGIN_MALLOC() or
39 GRN_PLUGIN_REALLOC(). This means that `ptr` must be a pointer returned by
40 GRN_PLUGIN_MALLOC() or GRN_PLUGIN_REALLOC().
41
42 .. c:macro:: GRN_PLUGIN_LOG(ctx, level, ...)
43
44 GRN_PLUGIN_LOG() reports a log of `level`. Its error message is generated
45 from the varying number of arguments, in which the first one is the format
46 string and the rest are its arguments. See grn_log_level in "groonga.h" for
47 more details of `level`.
48
49 .. c:macro:: GRN_PLUGIN_ERROR(ctx, error_code, ...)
50
51 GRN_PLUGIN_ERROR() reports an error of `error_code`. Its error message is
52 generated from the varying number of arguments, in which the first one is the
53 format string and the rest are its arguments. See grn_rc in "groonga.h" for
54 more details of `error_code`.
55
56 .. c:type:: grn_plugin_mutex
57
58 grn_plugin_mutex is available to make a critical section. See the
59 following functions.
60
61 .. c:function:: void grn_plugin_mutex_close(grn_ctx *ctx, grn_plugin_mutex *mutex)
62
63 grn_plugin_mutex_close() finalizes an object of grn_plugin_mutex and then
64 frees memory allocated for that object.
65
66 .. c:function:: void grn_plugin_mutex_lock(grn_ctx *ctx, grn_plugin_mutex *mutex)
67
68 grn_plugin_mutex_lock() locks a mutex object. If the object is already
69 locked, the calling thread waits until the object will be unlocked.
70
71 .. c:function:: void grn_plugin_mutex_unlock(grn_ctx *ctx, grn_plugin_mutex *mutex)
72
73 grn_plugin_mutex_unlock() unlocks a mutex object. grn_plugin_mutex_unlock()
74 should not be called for an unlocked object.
75
76 .. c:function:: grn_obj *grn_plugin_proc_alloc(grn_ctx *ctx, grn_user_data *user_data, grn_id domain, grn_obj_flags flags)
77
78 grn_plugin_proc_alloc() allocates a `grn_obj` object.
79 You can use it in function that is registered as GRN_PROC_FUNCTION.
80
81 .. c:function:: grn_obj grn_plugin_proc_get_var(grn_ctx *ctx, grn_user_data *user_data, const char *name, int name_size)
82
83 It gets a variable value from `grn_user_data` by specifying the variable name.
84
85 :param name: The variable name.
86 :param name_size: The number of bytes of name. If `name_size` is negative, `name` must be NUL-terminated. `name_size` is computed by `strlen(name)` for the case.
87 :return: A variable value on success, NULL otherwise.
88
89 .. c:function:: grn_obj *grn_plugin_proc_get_var_by_offset(grn_ctx *ctx, grn_user_data *user_data, unsigned int offset)
90
91 It gets a variable value from `grn_user_data` by specifying the offset position of the variable.
92
93 :param offset: The offset position of the variable.
94 :return: A variable value on success, NULL otherwise.
95
96 .. c:function:: const char *grn_plugin_win32_base_dir(void)
97
98 .. deprecated:: 5.0.9. Use :c:func:`grn_plugin_windows_base_dir()`
99 instead.
100
101 It returns the Groonga install directory. The install directory is
102 computed from the directory that has ``groonga.dll``. You can use
103 the directory to generate install directory aware path. It only
104 works on Windows. It returns ``NULL`` on other platforms.
105
106 .. c:function:: const char *grn_plugin_windows_base_dir(void)
107
108 .. versionadded:: 5.0.9
109
110 It returns the Groonga install directory. The install directory is
111 computed from the directory that has ``groonga.dll``. You can use
112 the directory to generate install directory aware path. It only
113 works on Windows. It returns ``NULL`` on other platforms.
114
115 .. c:function:: int grn_plugin_charlen(grn_ctx *ctx, const char *str_ptr, unsigned int str_length, grn_encoding encoding)
116
117 grn_plugin_charlen() returns the length (#bytes) of the first character
118 in the string specified by `str_ptr` and `str_length`. If the starting bytes
119 are invalid as a character, grn_plugin_charlen() returns 0. See
120 grn_encoding in "groonga.h" for more details of `encoding`.
121
122 .. c:function:: int grn_plugin_isspace(grn_ctx *ctx, const char *str_ptr, unsigned int str_length, grn_encoding encoding)
123
124 grn_plugin_isspace() returns the length (#bytes) of the first character
125 in the string specified by `str_ptr` and `str_length` if it is a space
126 character. Otherwise, grn_plugin_isspace() returns 0.
127
128 .. c:function:: grn_rc grn_plugin_expr_var_init(grn_ctx *ctx, grn_expr_var *var, const char *name, int name_size)
129
130 It initializes a `grn_expr_var`.
131
132 :param var: The pointer of `grn_expr_var` object to be initialized.
133 :param name: The name of `grn_expr_var` object to be initialized.
134 :param name_size: The number of bytes of name. If `name_size` is negative, `name` must be NUL-terminated. `name_size` is computed by `strlen(name)` for the case.
135 :return: ``GRN_SUCCESS``. It doesn't fail.
136
137 .. c:function:: grn_obj * grn_plugin_command_create(grn_ctx *ctx, const char *name, int name_size, grn_proc_func func, unsigned int n_vars, grn_expr_var *vars)
138
139 It creates a command.
140
141 :param name: The `proc` name of the command to be created.
142 :param name_size: The number of bytes of name. If `name_size` is negative, `name` must be NUL-terminated. `name_size` is computed by `strlen(name)` for the case.
143 :param func: The function name to be called by the created command.
144 :param n_vars: The number of the variables of the command to create.
145 :param vars: The pointer of initialized `grn_expr_var` object.
146 :return: The created command object if it creates a command successfully,
147 `NULL` otherwise. See `ctx` for error details.