aboutsummaryrefslogtreecommitdiffstats
path: root/lib/snmp/src/agent/snmpa_mib_storage_dets.erl
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2013-05-22 14:11:35 +0200
committerMicael Karlberg <[email protected]>2013-05-22 14:11:35 +0200
commit58309771ca695ed74dc92c72cca471b93eda8282 (patch)
tree3356c38cd34675d9ffd72942f78b2776d1dd0029 /lib/snmp/src/agent/snmpa_mib_storage_dets.erl
parentcac3dbfed3b3f703a012f52cd7093392a70a53cc (diff)
downloadotp-58309771ca695ed74dc92c72cca471b93eda8282.tar.gz
otp-58309771ca695ed74dc92c72cca471b93eda8282.tar.bz2
otp-58309771ca695ed74dc92c72cca471b93eda8282.zip
[snmp/agent] Add info/2 and some record checks
Add a new function/2 to behaviour. Also changed returnj type for info/1. Also make sure even ets and dets implementation(s) check that the correct type is written.
Diffstat (limited to 'lib/snmp/src/agent/snmpa_mib_storage_dets.erl')
-rw-r--r--lib/snmp/src/agent/snmpa_mib_storage_dets.erl27
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/snmp/src/agent/snmpa_mib_storage_dets.erl b/lib/snmp/src/agent/snmpa_mib_storage_dets.erl
index 6062f4327e..e84e18e7ea 100644
--- a/lib/snmp/src/agent/snmpa_mib_storage_dets.erl
+++ b/lib/snmp/src/agent/snmpa_mib_storage_dets.erl
@@ -33,19 +33,19 @@
write/2,
delete/1,
delete/2,
- sync/1,
- backup/2,
match_object/2,
match_delete/2,
tab2list/1,
- info/1
+ info/1, info/2,
+ sync/1,
+ backup/2
]).
-define(VMODULE, "MS-DETS").
-include("snmp_verbosity.hrl").
--record(tab, {id}).
+-record(tab, {id, rec_name}).
%% ---------------------------------------------------------------
@@ -62,7 +62,7 @@
%%
%% ---------------------------------------------------------------
-open(Name, _RecName, _Fields, Type, Opts) ->
+open(Name, RecName, _Fields, Type, Opts) ->
Dir = snmp_misc:get_option(dir, Opts),
Action = snmp_misc:get_option(action, Opts, keep),
AutoSave = snmp_misc:get_option(auto_save, Opts, default),
@@ -80,10 +80,10 @@ open(Name, _RecName, _Fields, Type, Opts) ->
end,
case dets:open_file(Name, OpenOpts) of
{ok, ID} when (Action =:= keep) ->
- {ok, #tab{id = ID}};
+ {ok, #tab{id = ID, rec_name = RecName}};
{ok, ID} when (Action =:= clear) ->
dets:match_delete(ID, '_'),
- {ok, #tab{id = ID}};
+ {ok, #tab{id = ID, rec_name = RecName}};
{error, Reason} ->
{error, {dets_open, Reason}}
end.
@@ -128,7 +128,8 @@ read(#tab{id = ID}, Key) ->
%% Write a record to the database table.
%% ---------------------------------------------------------------
-write(#tab{id = ID}, Rec) ->
+write(#tab{id = ID, rec_name = RecName}, Rec)
+ when (is_tuple(Rec) andalso (element(1, Rec) =:= RecName)) ->
?vtrace("write to table ~p", [ID]),
dets:insert(ID, Rec).
@@ -209,6 +210,16 @@ info(#tab{id = ID}) ->
dets:info(ID).
+info(TabId, all = _Item) ->
+ info(TabId);
+info(#tab{id = ID}, memory = _Item) ->
+ ?vtrace("info on ~p (~w)", [ID, _Item]),
+ dets:info(ID, file_size);
+info(#tab{id = ID}, Item) ->
+ ?vtrace("info on ~p (~w)", [ID, Item]),
+ dets:info(ID, Item).
+
+
%% ---------------------------------------------------------------
%% sync
%%