8.15.5. grn_ctx¶
8.15.5.1. Summary¶
grn_ctx is the most important object. grn_ctx keeps the current infomation such as:
- The last occurred error.
- The current encoding.
- The default thresholds. (e.g. match_escalation_threshold)
- The default command version. (See コマンドバージョン)
grn_ctx provides platform features such as:
- Memory management.
- Logging.
Most APIs receive grn_ctx as the first argument.
You can't use the same grn_ctx from two or more threads. You need to create a grn_ctx for a thread. You can use two or more grn_ctx in a thread but it is not needed for usual use-case.
8.15.5.2. Example¶
TODO...
8.15.5.3. Reference¶
- grn_ctx¶
TODO...
- grn_rc grn_ctx_init(grn_ctx *ctx, int flags)¶
ctxを初期化します。
Parameters: - ctx -- 初期化するctx構造体へのポインタを指定します。
- flags -- 初期化する ctx のオプションを指定します。
Returns: GRN_SUCCESS on success, not GRN_SUCCESS on error.
- grn_rc grn_ctx_fin(grn_ctx *ctx)¶
ctxの管理するメモリを解放し、使用を終了します。
If ctx is initialized by grn_ctx_open() not grn_ctx_init(). You need also to call grn_ctx_close().
Parameters: - ctx -- 解放するctx構造体へのポインタを指定します。
Returns: GRN_SUCCESS on success, not GRN_SUCCESS on error.
- grn_ctx *grn_ctx_open(int flags)¶
初期化された grn_ctx オブジェクトを返します。
grn_ctx_init() で初期化された grn_ctx オブジェクトは構造体の実体をAPIの呼び元で確保するのに対して、 grn_ctx_open() ではGroongaライブラリの内部で、実体を確保します。 どちらで初期化された grn_ctx も、 grn_ctx_fin() で解放できます。 grn_ctx_open() で確保した grn_ctx 構造体に関しては、grn_ctx_fin() で解放した後に、その grn_ctx で作成した grn_obj を grn_obj_close() によって解放しても問題ありません。
Parameters: - flags -- 初期化する ctx のオプションを指定します。
Returns: 初期化された grn_ctx オブジェクトを返します。
- grn_rc grn_ctx_close(grn_ctx *ctx)¶
It calls grn_ctx_fin() and frees allocated memory for ctx by grn_ctx_open().
Parameters: - ctx -- no longer needed grn_ctx.
Returns: GRN_SUCCESS on success, not GRN_SUCCESS on error.
- grn_rc grn_ctx_set_finalizer(grn_ctx *ctx, grn_proc_func *func)¶
ctxを破棄するときに呼ばれる関数を設定します。
Parameters: - ctx -- 対象ctxを指定します。
- func -- ctx を破棄するときに呼ばれる関数を指定します。
Returns: GRN_SUCCESS on success, not GRN_SUCCESS on error.
- grn_command_version grn_ctx_get_command_version(grn_ctx *ctx)¶
command_versionを返します。
- grn_rc grn_ctx_set_command_version(grn_ctx *ctx, grn_command_version version)¶
command_versionを変更します。
Parameters: - version -- 変更後のcommand_versionを指定します。
- grn_rc grn_ctx_use(grn_ctx *ctx, grn_obj *db)¶
ctxが操作対象とするdbを指定します。NULLを指定した場合は、dbを操作しない状態(init直後の状態)になります。
Don't use it with grn_ctx that has GRN_CTX_PER_DB flag.
Parameters: - db -- ctxが使用するdbを指定します。