File 1559-snmp-Types-and-specs-for-snmp_generic-table_func-2-4.patch of Package erlang
From f83c825304dbcf32f33f93717fa674d278d805da Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Fri, 12 Jan 2024 19:33:16 +0100
Subject: [PATCH 39/67] [snmp] Types and specs for snmp_generic:table_func/2,4
---
lib/snmp/doc/src/snmp.xml | 20 ++++++++++++++
lib/snmp/doc/src/snmp_generic.xml | 41 +++++++++++++++++------------
lib/snmp/src/agent/snmp_generic.erl | 22 +++++++++++++---
lib/snmp/src/app/snmp.erl | 11 +++-----
4 files changed, 67 insertions(+), 27 deletions(-)
diff --git a/lib/snmp/doc/src/snmp.xml b/lib/snmp/doc/src/snmp.xml
index 041951d22e..d46f974e4b 100644
--- a/lib/snmp/doc/src/snmp.xml
+++ b/lib/snmp/doc/src/snmp.xml
@@ -40,6 +40,26 @@
</description>
<datatypes>
+ <datatype>
+ <name name="oid"/>
+ <desc>
+ <p>
+ Represent an ASN.1 OBJECT IDENTIFIER.
+ </p>
+ </desc>
+ </datatype>
+
+ <datatype>
+ <name name="row_index"/>
+ <desc>
+ <p>
+ Denotes the last part of the OID which specifies the index of the
+ row in the table (see RFC1212, 4.1.6 for more information about
+ INDEX).
+ </p>
+ </desc>
+ </datatype>
+
<datatype>
<name name="bits"/>
<desc>
diff --git a/lib/snmp/doc/src/snmp_generic.xml b/lib/snmp/doc/src/snmp_generic.xml
index 8d93521f9e..7420d4d991 100644
--- a/lib/snmp/doc/src/snmp_generic.xml
+++ b/lib/snmp/doc/src/snmp_generic.xml
@@ -374,30 +374,39 @@ value() = term()
retrieve a given part of the table info.</p>
<marker id="table_func"></marker>
+ <marker id="table_func2"></marker>
</desc>
</func>
<func>
- <name since="">table_func(Op1, NameDb)</name>
- <name since="">table_func(Op2, RowIndex, Cols, NameDb) -> Ret</name>
+ <name name="table_func" arity="2" clause_i="1" since=""/>
<fsummary>Default instrumentation function for tables</fsummary>
- <type>
- <v>Op1 = new | delete </v>
- <v>Op2 = get | next | is_set_ok | set | undo</v>
- <v>NameDb = name_db()</v>
- <v>RowIndex = row_index()</v>
- <v>Cols = columns()</v>
- <v>Ret = term()</v>
- </type>
<desc>
- <p>This is the default instrumentation function for tables.
- </p>
+ <p>This is the default instrumentation function for tables. </p>
<list type="bulleted">
<item>The <c>new</c> function creates the table if it does
not exist, but only if the database is the SNMP internal db.</item>
<item>The <c>delete</c> function does not delete the table
from the database since unloading an MIB does not
necessarily mean that the table should be destroyed.</item>
+ </list>
+ <p>If it is possible for a manager to create or delete rows in
+ the table, there must be a <c>RowStatus</c> column for
+ <c>is_set_ok</c>, <c>set</c> and <c>undo</c> to work properly.
+ </p>
+ <p>The function returns according to the specification of an
+ instrumentation function. </p>
+
+ <marker id="table_func4"></marker>
+ </desc>
+ </func>
+
+ <func>
+ <name name="table_func" arity="4" clause_i="1" since=""/>
+ <fsummary>Default instrumentation function for tables</fsummary>
+ <desc>
+ <p>This is the default instrumentation function for tables. </p>
+ <list type="bulleted">
<item>The <c>is_set_ok</c> function checks that a row which
is to be modified or deleted exists, and that a row which
is to be created does not exist.</item>
@@ -411,12 +420,10 @@ value() = term()
handled within a transaction.</item>
</list>
<p>If it is possible for a manager to create or delete rows in
- the table, there must be a <c>RowStatus</c> column for
- <c>is_set_ok</c>, <c>set</c> and <c>undo</c> to work properly.
- </p>
+ the table, there must be a <c>RowStatus</c> column for
+ <c>is_set_ok</c>, <c>set</c> and <c>undo</c> to work properly. </p>
<p>The function returns according to the specification of an
- instrumentation function.
- </p>
+ instrumentation function. </p>
<marker id="table_get_elements"></marker>
</desc>
diff --git a/lib/snmp/src/agent/snmp_generic.erl b/lib/snmp/src/agent/snmp_generic.erl
index ed2c3db5e9..188eca0ae2 100644
--- a/lib/snmp/src/agent/snmp_generic.erl
+++ b/lib/snmp/src/agent/snmp_generic.erl
@@ -53,7 +53,7 @@
-endif.
--type column() :: integer().
+-type column() :: pos_integer().
-type columns() :: [column()] | [{column(), Value :: term()}].
-type table_info_item() :: nbr_of_cols |
defvals |
@@ -195,6 +195,7 @@ variable_func(set, Val, NameDb) ->
variable_func(undo, _Val, _NameDb) ->
noError.
+
%%------------------------------------------------------------------
%% Tables
%% Assumes the RowStatus is the last column in the
@@ -209,18 +210,33 @@ variable_func(undo, _Val, _NameDb) ->
%%------------------------------------------------------------------
%% Each database implements its own table_func
%%------------------------------------------------------------------
+
+-spec table_func(Op, NameDb) -> Return when
+ Op :: new | delete,
+ NameDb :: snmpa:name_db(),
+ Return :: term().
+
table_func(Op, {Name, mnesia}) ->
snmp_generic_mnesia:table_func(Op, Name);
table_func(Op, NameDb) ->
snmpa_local_db:table_func(Op, NameDb).
+
+-spec table_func(Op, RowIndex, Cols, NameDb) -> Return when
+ Op :: get | next | is_set_ok | set | undo,
+ RowIndex :: snmp:row_index(),
+ Cols :: columns(),
+ NameDb :: snmpa:name_db(),
+ Return :: term().
+
table_func(Op, RowIndex, Cols, {Name, mnesia}) ->
snmp_generic_mnesia:table_func(Op, RowIndex, Cols, Name);
table_func(Op, RowIndex, Cols, NameDb) ->
snmpa_local_db:table_func(Op, RowIndex, Cols, NameDb).
+
%%----------------------------------------------------------------------
%% DB independent.
%%----------------------------------------------------------------------
@@ -238,8 +254,8 @@ validate_get([_Col | Cols], [Res | Ress]) ->
NewVal =
case Res of
noinit -> {noValue, unSpecified};
- noacc -> {noAccess, unSpecified};
- Val -> {value, Val}
+ noacc -> {noAccess, unSpecified};
+ Val -> {value, Val}
end,
[NewVal | validate_get(Cols, Ress)];
validate_get([], []) -> [].
diff --git a/lib/snmp/src/app/snmp.erl b/lib/snmp/src/app/snmp.erl
index 5d8757863b..000f99e2aa 100644
--- a/lib/snmp/src/app/snmp.erl
+++ b/lib/snmp/src/app/snmp.erl
@@ -85,6 +85,7 @@
sec_level/0,
oid/0,
+ row_index/0,
varbind/0,
ivarbind/0,
asn1_type/0,
@@ -106,12 +107,6 @@
]).
-%% This is for XREF
-%% -deprecated(
-%% [
-%% ]).
-
-
-define(APPLICATION, snmp).
-define(ATL_BLOCK_DEFAULT, true).
@@ -138,6 +133,9 @@
-type bits() :: integer().
-type octet() :: 0..255.
-type octet_string() :: [octet()].
+-type oid() :: [non_neg_integer()].
+-type row_index() :: oid().
+
-type rfc1903_date_and_time() :: octet_string().
-type date_and_time_validator_kind() :: year | month | day |
@@ -163,7 +161,6 @@
-type sec_name() :: snmp_community_mib:security_name().
-type sec_level() :: noAuthNoPriv | authNoPriv | authPriv.
--type oid() :: [non_neg_integer()].
-type varbind() :: #varbind{}.
-type ivarbind() :: #ivarbind{}.
-type asn1_type() :: #asn1_type{}.
--
2.35.3