<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/en/2176/18/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>
Add an example for load_module including doxygen documentation<br />
</div>
<br/>
<h4>Changes (5)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-unchanged" >All modules must have at least the following: <br> <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">h2. Load Module <br></td></tr>
<tr><td class="diff-unchanged" >{code} <br>static int load_module(): <br>{code} <br> <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Do what you need to do when you get started. This function can return AST_MODULE_LOAD_FAILURE if an action fails and the module is prevented from loading, AST_MODULE_LOAD_DECLINE if the module can not load because of a non-critical failure <br>(the configuration file was not found), or AST_MODULE_LOAD_SUCCESS if the module loaded fine. <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">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 retrun *AST_MODULE_LOAD_DECLINE*. On success return *AST_MODULE_LOAD_SUCCESS*. <br></td></tr>
<tr><td class="diff-unchanged" > <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">Example <br></td></tr>
<tr><td class="diff-unchanged" >{code} <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">/*! <br> * \brief Load Module <br> */ <br>static int load_module(void) <br>{ <br> <br> if (dependency_does_not_exist) { <br> return AST_MODULE_LOAD_FAILURE; <br> } <br> <br> if (configuration_file_does_not_exist) { <br> return AST_MODULE_LOAD_DECLINE; <br> } <br> <br> return AST_MODULE_LOAD_SUCCESS; <br>} <br>{code} <br> <br>h2. Unload Module <br>{code} <br></td></tr>
<tr><td class="diff-unchanged" >static int unload_module(): <br>{code} <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 retrun <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 Module
*/
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>
<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);</pre>
</div></div>
<ul>
        <li>keystr - Applicable license for module. In most cases this is ASTERISK_GPL_KEY.</li>
        <li>desc - Description of module.</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=2&originalVersion=1">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>