<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/en/2176/25/9/_/styles/combined.css?spaceKey=AST&forWysiwyg=true" type="text/css">
</head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
<h2><a href="https://wiki.asterisk.org/wiki/display/AST/Modules">Modules</a></h2>
<h4>Page <b>edited</b> by <a href="https://wiki.asterisk.org/wiki/display/~lathama">Andrew Latham</a>
</h4>
<div id="versionComment">
<b>Comment:</b>
including the text from the description is the the best option.<br />
</div>
<br/>
<h4>Changes (4)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" >{code} <br>/*! <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;"> * \brief Load Module <br> * Test dependencies and configuration requirements. Act upon results <br> * by loading, declining to load, or failure to load. <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;"> * \brief Load the module <br></td></tr>
<tr><td class="diff-unchanged" > * <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;"> * \return module load disposition <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;"> * Module loading including tests for configuration or dependencies. <br> * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, <br> * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails <br> * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the <br> * configuration file or other non-critical problem return <br> * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS. <br></td></tr>
<tr><td class="diff-unchanged" > */ <br>static int load_module(void) <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<p>All modules must have at least the following:</p>
<h2><a name="Modules-LoadModule"></a>Load Module</h2>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">static int load_module():</pre>
</div></div>
<p>Module loading including tests for configuration or dependencies. This function can return <b>AST_MODULE_LOAD_FAILURE</b>, <b>AST_MODULE_LOAD_DECLINE</b>, or <b>AST_MODULE_LOAD_SUCCESS</b>. If a dependency or environment variable fails tests return <b>AST_MODULE_LOAD_FAILURE</b>. If the module can not load the configuration file or other non-critical problem return <b>AST_MODULE_LOAD_DECLINE</b>. On success return <b>AST_MODULE_LOAD_SUCCESS</b>.</p>
<p>Example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
* \brief Load the module
*
* Module loading including tests for configuration or dependencies.
* This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
* or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
* tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
* configuration file or other non-critical problem return
* AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
*/
static int load_module(void)
{
if (dependency_does_not_exist) {
return AST_MODULE_LOAD_FAILURE;
}
if (configuration_file_does_not_exist) {
return AST_MODULE_LOAD_DECLINE;
}
return AST_MODULE_LOAD_SUCCESS;
}</pre>
</div></div>
<h2><a name="Modules-UnloadModule"></a>Unload Module</h2>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">static int unload_module():</pre>
</div></div>
<p>The module will soon be unloaded. If any channels are using your features, you should give them a softhangup in an effort to keep the program from crashing. Generally, unload_module is only called when the usecount is 0 or less, but the user can force unloading at their discretion, and thus a module should do its best to comply (although in some cases there may be no way to avoid a crash). This function should return 0 on success and non-zero on failure (i.e. it cannot yet be unloaded).</p>
<p>Example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*!
* \brief Unload Module
*/
static int unload_module(void)
{
if (active_use) {
return -1;
}
return 0;
}</pre>
</div></div>
<h2><a name="Modules-ModuleInformation"></a>Module Information</h2>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">AST_MODULE_INFO_STANDARD(keystr, desc);
... or ...
AST_MODULE_INFO(keystr, flags_to_set, desc, load_func, unload_func, reload_func, load_pri);</pre>
</div></div>
<p><b>AST_MODULE_INFO_STANDARD</b></p>
<ul>
        <li>keystr - Applicable license for module. In most cases this is ASTERISK_GPL_KEY.</li>
        <li>desc - Description of module.</li>
</ul>
<p><b>AST_MODULE_INFO</b></p>
<ul>
        <li>keystr</li>
        <li>flags_to_set</li>
        <li>desc</li>
        <li>load_func</li>
        <li>unload_func</li>
        <li>reload_func</li>
        <li>load_pri</li>
</ul>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;" class="grey">
<a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST">Stop watching space</a>
<span style="padding: 0px 5px;">|</span>
<a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
<a href="https://wiki.asterisk.org/wiki/display/AST/Modules">View Online</a>
|
<a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=4260026&revisedVersion=11&originalVersion=10">View Changes</a>
|
<a href="https://wiki.asterisk.org/wiki/display/AST/Modules?showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>