| Current File : //usr/share/doc/net-snmp/html/watched_8c_source.html |
<!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/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>net-snmp: watched.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">net-snmp
 <span id="projectnumber">5.4.1</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.7.6.1 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File List</span></a></li>
<li><a href="globals.html"><span>Globals</span></a></li>
</ul>
</div>
</div>
<div class="header">
<div class="headertitle">
<div class="title">watched.c</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * watched.c</span>
<a name="l00003"></a>00003 <span class="comment"> * $Id: watched.c 12097 2005-04-20 18:03:47Z rstory $</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> */</span>
<a name="l00013"></a>00013 <span class="comment">/*</span>
<a name="l00014"></a>00014 <span class="comment"> * start by including the appropriate header files </span>
<a name="l00015"></a>00015 <span class="comment"> */</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include <net-snmp/net-snmp-config.h></span>
<a name="l00017"></a>00017 <span class="preprocessor">#include <net-snmp/net-snmp-includes.h></span>
<a name="l00018"></a>00018 <span class="preprocessor">#include <net-snmp/agent/net-snmp-agent-includes.h></span>
<a name="l00019"></a>00019
<a name="l00020"></a>00020 <span class="keywordtype">void</span> init_watched_string(<span class="keywordtype">void</span>);
<a name="l00021"></a>00021
<a name="l00022"></a>00022 <span class="keywordtype">void</span> init_watched(<span class="keywordtype">void</span>)
<a name="l00023"></a>00023 {
<a name="l00024"></a>00024 init_watched_string();
<a name="l00025"></a>00025 }
<a name="l00026"></a>00026
<a name="l00027"></a>00027 <span class="keywordtype">void</span> init_watched_string(<span class="keywordtype">void</span>)
<a name="l00028"></a>00028 {
<a name="l00029"></a>00029 <span class="comment">/*</span>
<a name="l00030"></a>00030 <span class="comment"> * the storage for our string. It must be static or allocated.</span>
<a name="l00031"></a>00031 <span class="comment"> * we use static here for simplicity.</span>
<a name="l00032"></a>00032 <span class="comment"> */</span>
<a name="l00033"></a>00033 <span class="keyword">static</span> <span class="keywordtype">char</span> my_string[256] = <span class="stringliteral">"So long, and thanks for all the fish!"</span>;
<a name="l00034"></a>00034
<a name="l00035"></a>00035 <span class="comment">/*</span>
<a name="l00036"></a>00036 <span class="comment"> * the OID we want to register our string at. This should be a</span>
<a name="l00037"></a>00037 <span class="comment"> * fully qualified instance. In our case, it's a scalar at:</span>
<a name="l00038"></a>00038 <span class="comment"> * NET-SNMP-EXAMPLES-MIB::netSnmpExampleString.0 (note the trailing</span>
<a name="l00039"></a>00039 <span class="comment"> * 0 which is required for any instantiation of any scalar object) </span>
<a name="l00040"></a>00040 <span class="comment"> */</span>
<a name="l00041"></a>00041 oid my_registration_oid[] =
<a name="l00042"></a>00042 { 1, 3, 6, 1, 4, 1, 8072, 2, 1, 3, 0 };
<a name="l00043"></a>00043
<a name="l00044"></a>00044 <span class="comment">/*</span>
<a name="l00045"></a>00045 <span class="comment"> * variables needed for registration</span>
<a name="l00046"></a>00046 <span class="comment"> */</span>
<a name="l00047"></a>00047 <a class="code" href="structnetsnmp__handler__registration__s.html" title="Root registration info.">netsnmp_handler_registration</a> *reginfo;
<a name="l00048"></a>00048 <a class="code" href="structnetsnmp__watcher__info__s.html">netsnmp_watcher_info</a> *watcher_info;
<a name="l00049"></a>00049 <span class="keywordtype">int</span> watcher_flags;
<a name="l00050"></a>00050
<a name="l00051"></a>00051 <span class="comment">/*</span>
<a name="l00052"></a>00052 <span class="comment"> * a debugging statement. Run the agent with -Dexample_string_instance</span>
<a name="l00053"></a>00053 <span class="comment"> * to see the output of this debugging statement. </span>
<a name="l00054"></a>00054 <span class="comment"> */</span>
<a name="l00055"></a>00055 DEBUGMSGTL((<span class="stringliteral">"example_string_instance"</span>,
<a name="l00056"></a>00056 <span class="stringliteral">"Initalizing example string instance. Default value = %s\n"</span>,
<a name="l00057"></a>00057 my_string));
<a name="l00058"></a>00058
<a name="l00059"></a>00059 <span class="comment">/*</span>
<a name="l00060"></a>00060 <span class="comment"> * create the registration info for our string. If you want to</span>
<a name="l00061"></a>00061 <span class="comment"> *</span>
<a name="l00062"></a>00062 <span class="comment"> * If we wanted a callback when the value was retrieved or set</span>
<a name="l00063"></a>00063 <span class="comment"> * (even though the details of doing this are handled for you),</span>
<a name="l00064"></a>00064 <span class="comment"> * you could change the NULL pointer below to a valid handler</span>
<a name="l00065"></a>00065 <span class="comment"> * function.</span>
<a name="l00066"></a>00066 <span class="comment"> *</span>
<a name="l00067"></a>00067 <span class="comment"> * Change RWRITE to RONLY for a read-only string.</span>
<a name="l00068"></a>00068 <span class="comment"> */</span>
<a name="l00069"></a>00069 reginfo = netsnmp_create_handler_registration(<span class="stringliteral">"my example string"</span>, NULL,
<a name="l00070"></a>00070 my_registration_oid,
<a name="l00071"></a>00071 OID_LENGTH(my_registration_oid),
<a name="l00072"></a>00072 HANDLER_CAN_RWRITE);
<a name="l00073"></a>00073
<a name="l00074"></a>00074 <span class="comment">/*</span>
<a name="l00075"></a>00075 <span class="comment"> * the two options for a string watcher are:</span>
<a name="l00076"></a>00076 <span class="comment"> * fixed size string (length never changes)</span>
<a name="l00077"></a>00077 <span class="comment"> * variable size (length can be 0 - MAX, for some MAX)</span>
<a name="l00078"></a>00078 <span class="comment"> *</span>
<a name="l00079"></a>00079 <span class="comment"> * we'll use a variable length string.</span>
<a name="l00080"></a>00080 <span class="comment"> */</span>
<a name="l00081"></a>00081 watcher_flags = WATCHER_MAX_SIZE;
<a name="l00082"></a>00082
<a name="l00083"></a>00083 <span class="comment">/*</span>
<a name="l00084"></a>00084 <span class="comment"> * create the watcher info for our string, and set the max size.</span>
<a name="l00085"></a>00085 <span class="comment"> */</span>
<a name="l00086"></a>00086 watcher_info =
<a name="l00087"></a>00087 netsnmp_create_watcher_info(my_string, strlen(my_string),
<a name="l00088"></a>00088 ASN_OCTET_STR, watcher_flags);
<a name="l00089"></a>00089 watcher_info->max_size = <span class="keyword">sizeof</span>(my_string);
<a name="l00090"></a>00090
<a name="l00091"></a>00091 <span class="comment">/*</span>
<a name="l00092"></a>00092 <span class="comment"> * the line below registers our "my_string" variable above as</span>
<a name="l00093"></a>00093 <span class="comment"> * accessible and makes it writable. </span>
<a name="l00094"></a>00094 <span class="comment"> * </span>
<a name="l00095"></a>00095 <span class="comment"> * If we wanted a callback when the value was retrieved or set</span>
<a name="l00096"></a>00096 <span class="comment"> * (even though the details of doing this are handled for you),</span>
<a name="l00097"></a>00097 <span class="comment"> * you could change the NULL pointer below to a valid handler</span>
<a name="l00098"></a>00098 <span class="comment"> * function. </span>
<a name="l00099"></a>00099 <span class="comment"> */</span>
<a name="l00100"></a>00100 netsnmp_register_watched_instance(reginfo, watcher_info);
<a name="l00101"></a>00101
<a name="l00102"></a>00102 DEBUGMSGTL((<span class="stringliteral">"example_string_instance"</span>,
<a name="l00103"></a>00103 <span class="stringliteral">"Done initalizing example string instance\n"</span>));
<a name="l00104"></a>00104 }
</pre></div></div><!-- contents -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>
</body>
</html>