|
|
Next, your peer will initialize the values of the MIB objects and the MIB database used by the peer. You will need to make more modifications to foomib.c to accomplish this.
The initializing routine init_foo()
is executed when the peer first starts running.
It is only for the foo MIB module.
init_foo() has two primary functions:
it initializes the values of the MIB
objects and it initializes the MIB
data structures used by the SMUX peer.
For each MIB module, make one of the following functions of name init_foo(), replacing the string ``foo'' with the identifying string you chose for your peer. The following example is for the foo MIB module:
int
init_foo()
{
Next, initialize the values of the MIB objects.
Initialize the value of each single instance leaf object
and each instance of variables in tables.
For each single instance variable initialize the value. If the object has an access of read-write set the ``new_name'' variable to a null value.
productName = "Foo Serial I/O Board";
boardStatus = ENABLED;
new_boardStatus = 0;
exampleIpAddr.s_addr = 0;
newflag_exampleIpAddr = 0;
exampleObjectID = make_obj_id_from_dot(DEFAULT_EXAMPLEOBJECTID);
new_exampleObjectID = NULLOID;
numberLines = 32;
Now, for each table in the
MIB
module, add a for() loop. This example is for the
serialLineTable, which has numberLines
rows:
for (i = 0; i < numberLines; i++) {
For every object in the table, add an assignment statement to the
for() loop that
initializes the variable to a legal value.
A ``real world''
SMUX
peer would probably read these start-up or default
values from the device being managed or from a configuration file.
serialLineTable[i].serialLineNumber = i + 1;You should also add an assignment statement to set the new pending value to null.
serialLineTable[i].new_serialLineBaudRate = 0;Next, initialize the MIB database used by the SMUX peer. For every leaf object in the MIB module, add an ``if'' statement as in the following examples. The
ot_getfnx
pointer points to the
function used to process the GetRequest operation
for this object. The
ot_setfnx pointer points to the function used to process the
SetRequest operation
for this object. Objects that have an access of
read-only have an ot_setfnx pointer that points to null. The
ot_info is the last octet in the object
ID
as specified in the #define above.
if (ot = text2obj("productName")) {
ot->ot_getfnx = get_single_instance;
ot->ot_info = (caddr_t) PRODUCTNAME;
}
if (ot = text2obj("boardStatus")) {
ot->ot_getfnx = get_single_instance;
ot->ot_setfnx = set_single_instance;
ot->ot_info = (caddr_t) BOARDSTATUS;
}
if (ot = text2obj("exampleIpAddr")) {
ot->ot_getfnx = get_single_instance;
ot->ot_setfnx = set_single_instance;
ot->ot_info = (caddr_t) EXAMPLEIPADDR;
}
if (ot = text2obj("exampleObjectID")) {
ot->ot_getfnx = get_single_instance;
ot->ot_setfnx = set_single_instance;
ot->ot_info = (caddr_t) EXAMPLEOBJECTID;
}
if (ot = text2obj("numberLines")) {
ot->ot_getfnx = get_single_instance;
ot->ot_info = (caddr_t) NUMBERLINES;
}
if (ot = text2obj("serialLineNumber")) {
ot->ot_getfnx = get_serialLineTable;
ot->ot_info = (caddr_t) SERIALLINENUMBER;
}
if (ot = text2obj("serialLineBaudRate")) {
ot->ot_getfnx = get_serialLineTable;
ot->ot_setfnx = set_serialLineTable;
ot->ot_info = (caddr_t) SERIALLINEBAUDRATE;
}
if (ot = text2obj("serialLineTermLocation")) {
ot->ot_getfnx = get_serialLineTable;
ot->ot_setfnx = set_serialLineTable;
ot->ot_info = (caddr_t) SERIALLINETERMLOCATION;
}