<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>7.20.3. Plugin &mdash; Groonga v5.0.3 documentation</title>
    
    <link rel="stylesheet" href="../../_static/groonga.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '5.0.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
    <link rel="top" title="Groonga v5.0.3 documentation" href="../../index.html" />
    <link rel="up" title="7.20. API" href="../api.html" />
    <link rel="next" title="7.20.4. grn_cache" href="grn_cache.html" />
    <link rel="prev" title="7.20.2. Global configurations" href="global_configurations.html" /> 
  </head>
  <body>
<div class="header">
  <h1 class="title">
    <a id="top-link" href="../../index.html">
      <span class="project">groonga</span>
      <span class="separator">-</span>
      <span class="description">An open-source fulltext search engine and column store.</span>
    </a>
  </h1>

  <div class="other-language-links">
    <ul>
      <li><a href="../../../../ja/html/reference/api/plugin.html">日本語</a></li>
    </ul>
  </div>
</div>
  

    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="grn_cache.html" title="7.20.4. grn_cache"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="global_configurations.html" title="7.20.2. Global configurations"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">Groonga v5.0.3 documentation</a> &raquo;</li>
          <li><a href="../../reference.html" >7. Reference manual</a> &raquo;</li>
          <li><a href="../api.html" accesskey="U">7.20. API</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="plugin">
<h1>7.20.3. Plugin<a class="headerlink" href="#plugin" title="Permalink to this headline">¶</a></h1>
<div class="section" id="summary">
<h2>7.20.3.1. Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
<p>Groonga supports plugin. You can create a new plugin with the
following API.</p>
<p>TOOD: Describe about how to create the minimum plugin here or create a
tutorial about it.</p>
</div>
<div class="section" id="reference">
<h2>7.20.3.2. Reference<a class="headerlink" href="#reference" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="c.GRN_PLUGIN_INIT">
grn_rc <tt class="descname">GRN_PLUGIN_INIT</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em><big>)</big><a class="headerlink" href="#c.GRN_PLUGIN_INIT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.GRN_PLUGIN_REGISTER">
grn_rc <tt class="descname">GRN_PLUGIN_REGISTER</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em><big>)</big><a class="headerlink" href="#c.GRN_PLUGIN_REGISTER" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.GRN_PLUGIN_FIN">
grn_rc <tt class="descname">GRN_PLUGIN_FIN</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em><big>)</big><a class="headerlink" href="#c.GRN_PLUGIN_FIN" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="macro">
<dt id="c.GRN_PLUGIN_MALLOC">
<tt class="descname">GRN_PLUGIN_MALLOC</tt><big>(</big>ctx, size<big>)</big><a class="headerlink" href="#c.GRN_PLUGIN_MALLOC" title="Permalink to this definition">¶</a></dt>
<dd><p>GRN_PLUGIN_MALLOC() allocates <cite>size</cite> bytes and returns a pointer to the
allocated memory space. Note that the memory space is associated with <cite>ctx</cite>.</p>
</dd></dl>

<dl class="macro">
<dt id="c.GRN_PLUGIN_REALLOC">
<tt class="descname">GRN_PLUGIN_REALLOC</tt><big>(</big>ctx, ptr, size<big>)</big><a class="headerlink" href="#c.GRN_PLUGIN_REALLOC" title="Permalink to this definition">¶</a></dt>
<dd><p>GRN_PLUGIN_REALLOC() resizes the memory space pointed to by <cite>ptr</cite> or
allocates a new memory space of <cite>size</cite> bytes. GRN_PLUGIN_REALLOC() returns
a pointer to the memory space. The contents is unchanged or copied from the
old memory space to the new memory space.</p>
</dd></dl>

<dl class="macro">
<dt id="c.GRN_PLUGIN_FREE">
<tt class="descname">GRN_PLUGIN_FREE</tt><big>(</big>ctx, ptr<big>)</big><a class="headerlink" href="#c.GRN_PLUGIN_FREE" title="Permalink to this definition">¶</a></dt>
<dd><p>GRN_PLUGIN_FREE() frees a memory space allocated by GRN_PLUGIN_MALLOC() or
GRN_PLUGIN_REALLOC(). This means that <cite>ptr</cite> must be a pointer returned by
GRN_PLUGIN_MALLOC() or GRN_PLUGIN_REALLOC().</p>
</dd></dl>

<dl class="macro">
<dt id="c.GRN_PLUGIN_LOG">
<tt class="descname">GRN_PLUGIN_LOG</tt><big>(</big>ctx, level, ...<big>)</big><a class="headerlink" href="#c.GRN_PLUGIN_LOG" title="Permalink to this definition">¶</a></dt>
<dd><p>GRN_PLUGIN_LOG() reports a log of <cite>level</cite>. Its error message is generated
from the varying number of arguments, in which the first one is the format
string and the rest are its arguments. See grn_log_level in &quot;groonga.h&quot; for
more details of <cite>level</cite>.</p>
</dd></dl>

<dl class="macro">
<dt id="c.GRN_PLUGIN_ERROR">
<tt class="descname">GRN_PLUGIN_ERROR</tt><big>(</big>ctx, error_code, ...<big>)</big><a class="headerlink" href="#c.GRN_PLUGIN_ERROR" title="Permalink to this definition">¶</a></dt>
<dd><p>GRN_PLUGIN_ERROR() reports an error of <cite>error_code</cite>. Its error message is
generated from the varying number of arguments, in which the first one is the
format string and the rest are its arguments. See grn_rc in &quot;groonga.h&quot; for
more details of <cite>error_code</cite>.</p>
</dd></dl>

<dl class="type">
<dt id="c.grn_plugin_mutex">
<tt class="descname">grn_plugin_mutex</tt><a class="headerlink" href="#c.grn_plugin_mutex" title="Permalink to this definition">¶</a></dt>
<dd><p>grn_plugin_mutex is available to make a critical section. See the
following functions.</p>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_mutex_open">
<a class="reference internal" href="#c.grn_plugin_mutex" title="grn_plugin_mutex">grn_plugin_mutex</a> *<tt class="descname">grn_plugin_mutex_open</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em><big>)</big><a class="headerlink" href="#c.grn_plugin_mutex_open" title="Permalink to this definition">¶</a></dt>
<dd><p>grn_plugin_mutex_open() returns a pointer to a new object of
grn_plugin_mutex. Memory for the new object is obtained with
GRN_PLUGIN_MALLOC(). grn_plugin_mutex_open() returns NULL if sufficient
memory is not available.</p>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_mutex_close">
void <tt class="descname">grn_plugin_mutex_close</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em>, <a class="reference internal" href="#c.grn_plugin_mutex" title="grn_plugin_mutex">grn_plugin_mutex</a><em>&nbsp;*mutex</em><big>)</big><a class="headerlink" href="#c.grn_plugin_mutex_close" title="Permalink to this definition">¶</a></dt>
<dd><p>grn_plugin_mutex_close() finalizes an object of grn_plugin_mutex and then
frees memory allocated for that object.</p>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_mutex_lock">
void <tt class="descname">grn_plugin_mutex_lock</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em>, <a class="reference internal" href="#c.grn_plugin_mutex" title="grn_plugin_mutex">grn_plugin_mutex</a><em>&nbsp;*mutex</em><big>)</big><a class="headerlink" href="#c.grn_plugin_mutex_lock" title="Permalink to this definition">¶</a></dt>
<dd><p>grn_plugin_mutex_lock() locks a mutex object. If the object is already
locked, the calling thread waits until the object will be unlocked.</p>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_mutex_unlock">
void <tt class="descname">grn_plugin_mutex_unlock</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em>, <a class="reference internal" href="#c.grn_plugin_mutex" title="grn_plugin_mutex">grn_plugin_mutex</a><em>&nbsp;*mutex</em><big>)</big><a class="headerlink" href="#c.grn_plugin_mutex_unlock" title="Permalink to this definition">¶</a></dt>
<dd><p>grn_plugin_mutex_unlock() unlocks a mutex object. grn_plugin_mutex_unlock()
should not be called for an unlocked object.</p>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_proc_alloc">
<a class="reference internal" href="grn_obj.html#c.grn_obj" title="grn_obj">grn_obj</a> *<tt class="descname">grn_plugin_proc_alloc</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em>, <a class="reference internal" href="grn_user_data.html#c.grn_user_data" title="grn_user_data">grn_user_data</a><em>&nbsp;*user_data</em>, grn_id<em>&nbsp;domain</em>, grn_obj_flags<em>&nbsp;flags</em><big>)</big><a class="headerlink" href="#c.grn_plugin_proc_alloc" title="Permalink to this definition">¶</a></dt>
<dd><p>grn_plugin_proc_alloc() allocates a <cite>grn_obj</cite> object.
You can use it in function that is registered as GRN_PROC_FUNCTION.</p>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_proc_get_var">
<a class="reference internal" href="grn_obj.html#c.grn_obj" title="grn_obj">grn_obj</a> <tt class="descname">grn_plugin_proc_get_var</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em>, <a class="reference internal" href="grn_user_data.html#c.grn_user_data" title="grn_user_data">grn_user_data</a><em>&nbsp;*user_data</em>, const char<em>&nbsp;*name</em>, int<em>&nbsp;name_size</em><big>)</big><a class="headerlink" href="#c.grn_plugin_proc_get_var" title="Permalink to this definition">¶</a></dt>
<dd><p>It gets a variable value from <cite>grn_user_data</cite> by specifying the variable name.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> -- The variable name.</li>
<li><strong>name_size</strong> -- The number of bytes of name. If <cite>name_size</cite> is negative, <cite>name</cite> must be NUL-terminated. <cite>name_size</cite> is computed by <cite>strlen(name)</cite> for the case.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A variable value on success, NULL otherwise.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_proc_get_var_by_offset">
<a class="reference internal" href="grn_obj.html#c.grn_obj" title="grn_obj">grn_obj</a> *<tt class="descname">grn_plugin_proc_get_var_by_offset</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em>, <a class="reference internal" href="grn_user_data.html#c.grn_user_data" title="grn_user_data">grn_user_data</a><em>&nbsp;*user_data</em>, unsigned int<em>&nbsp;offset</em><big>)</big><a class="headerlink" href="#c.grn_plugin_proc_get_var_by_offset" title="Permalink to this definition">¶</a></dt>
<dd><p>It gets a variable value from <cite>grn_user_data</cite> by specifying the offset position of the variable.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>offset</strong> -- The offset position of the variable.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A variable value on success, NULL otherwise.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_win32_base_dir">
const char *<tt class="descname">grn_plugin_win32_base_dir</tt><big>(</big>void<big>)</big><a class="headerlink" href="#c.grn_plugin_win32_base_dir" title="Permalink to this definition">¶</a></dt>
<dd><p>grn_plugin_win32_base_dir() returns the groonga install directory.
The install directory is computed from the directory that has
<cite>groonga.dll</cite>. You can use the directory to generate install
directory aware path.
It only works on Windows. It returns <cite>NULL</cite> on other platforms.</p>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_charlen">
int <tt class="descname">grn_plugin_charlen</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em>, const char<em>&nbsp;*str_ptr</em>, unsigned int<em>&nbsp;str_length</em>, <a class="reference internal" href="grn_encoding.html#c.grn_encoding" title="grn_encoding">grn_encoding</a><em>&nbsp;encoding</em><big>)</big><a class="headerlink" href="#c.grn_plugin_charlen" title="Permalink to this definition">¶</a></dt>
<dd><p>grn_plugin_charlen() returns the length (#bytes) of the first character
in the string specified by <cite>str_ptr</cite> and <cite>str_length</cite>. If the starting bytes
are invalid as a character, grn_plugin_charlen() returns 0. See
grn_encoding in &quot;groonga.h&quot; for more details of <cite>encoding</cite>.</p>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_isspace">
int <tt class="descname">grn_plugin_isspace</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em>, const char<em>&nbsp;*str_ptr</em>, unsigned int<em>&nbsp;str_length</em>, <a class="reference internal" href="grn_encoding.html#c.grn_encoding" title="grn_encoding">grn_encoding</a><em>&nbsp;encoding</em><big>)</big><a class="headerlink" href="#c.grn_plugin_isspace" title="Permalink to this definition">¶</a></dt>
<dd><p>grn_plugin_isspace() returns the length (#bytes) of the first character
in the string specified by <cite>str_ptr</cite> and <cite>str_length</cite> if it is a space
character. Otherwise, grn_plugin_isspace() returns 0.</p>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_expr_var_init">
grn_rc <tt class="descname">grn_plugin_expr_var_init</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em>, grn_expr_var<em>&nbsp;*var</em>, const char<em>&nbsp;*name</em>, int<em>&nbsp;name_size</em><big>)</big><a class="headerlink" href="#c.grn_plugin_expr_var_init" title="Permalink to this definition">¶</a></dt>
<dd><p>It initializes a <cite>grn_expr_var</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>var</strong> -- The pointer of <cite>grn_expr_var</cite> object to be initialized.</li>
<li><strong>name</strong> -- The name of <cite>grn_expr_var</cite> object to be initialized.</li>
<li><strong>name_size</strong> -- The number of bytes of name. If <cite>name_size</cite> is negative, <cite>name</cite> must be NUL-terminated. <cite>name_size</cite> is computed by <cite>strlen(name)</cite> for the case.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><tt class="docutils literal"><span class="pre">GRN_SUCCESS</span></tt>. It doesn't fail.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="c.grn_plugin_command_create">
<a class="reference internal" href="grn_obj.html#c.grn_obj" title="grn_obj">grn_obj</a> * <tt class="descname">grn_plugin_command_create</tt><big>(</big><a class="reference internal" href="grn_ctx.html#c.grn_ctx" title="grn_ctx">grn_ctx</a><em>&nbsp;*ctx</em>, const char<em>&nbsp;*name</em>, int<em>&nbsp;name_size</em>, <a class="reference internal" href="grn_proc.html#c.grn_proc_func" title="grn_proc_func">grn_proc_func</a><em>&nbsp;func</em>, unsigned int<em>&nbsp;n_vars</em>, grn_expr_var<em>&nbsp;*vars</em><big>)</big><a class="headerlink" href="#c.grn_plugin_command_create" title="Permalink to this definition">¶</a></dt>
<dd><p>It creates a command.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> -- The <cite>proc</cite> name of the command to be created.</li>
<li><strong>name_size</strong> -- The number of bytes of name. If <cite>name_size</cite> is negative, <cite>name</cite> must be NUL-terminated. <cite>name_size</cite> is computed by <cite>strlen(name)</cite> for the case.</li>
<li><strong>func</strong> -- The function name to be called by the created command.</li>
<li><strong>n_vars</strong> -- The number of the variables of the command to create.</li>
<li><strong>vars</strong> -- The pointer of initialized <cite>grn_expr_var</cite> object.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The created command object if it creates a command successfully,
<cite>NULL</cite> otherwise. See <cite>ctx</cite> for error details.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">7.20.3. Plugin</a><ul>
<li><a class="reference internal" href="#summary">7.20.3.1. Summary</a></li>
<li><a class="reference internal" href="#reference">7.20.3.2. Reference</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="global_configurations.html"
                        title="previous chapter">7.20.2. Global configurations</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="grn_cache.html"
                        title="next chapter">7.20.4. <tt class="docutils literal"><span class="pre">grn_cache</span></tt></a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/reference/api/plugin.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="grn_cache.html" title="7.20.4. grn_cache"
             >next</a> |</li>
        <li class="right" >
          <a href="global_configurations.html" title="7.20.2. Global configurations"
             >previous</a> |</li>
        <li><a href="../../index.html">Groonga v5.0.3 documentation</a> &raquo;</li>
          <li><a href="../../reference.html" >7. Reference manual</a> &raquo;</li>
          <li><a href="../api.html" >7.20. API</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2015, Brazil, Inc.
    </div>
  </body>
</html>