1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 1997-2016. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21-module(klas3). 22-compile(export_all). 23 24ftab(new) -> 25 mnesia:create_table([{name, friendsTable3}, 26 {snmp, [{key, integer}]}, 27 {attributes, [a1,a2]}]); 28 29ftab(delete) -> 30 ok. 31 32 33ftab(is_set_ok, [2], _Cols) -> 34% io:format("calling ftab is_set_ok - fail~n"), 35 {inconsistentValue, 2}; 36ftab(is_set_ok, _, _Cols) -> 37% io:format("calling ftab is_set_ok - ok~n"), 38 {noError, 0}; 39 40ftab(undo, [3], _Cols) -> 41% io:format("calling ftab undo - fail~n"), 42 {undoFailed, 2}; 43 44ftab(undo, [1], _Cols) -> 45% io:format("calling ftab undo~n"), 46 {noError, 0}; 47 48ftab(set, [4], _Cols) -> 49 {commitFailed, 2}; 50 51ftab(Op, RowIndex, Cols) -> 52 snmp_generic:table_func(Op, RowIndex, Cols, {friendsTable3, mnesia}). 53 54 55fname(new) -> ok; 56fname(delete) -> ok; 57fname(get) -> 58 Str2 = (catch begin 59 case snmpa:current_request_id() of 60 {value, Int} when is_integer(Int) -> ok; 61 {value, _} -> throw("bad_int"); 62 _ -> throw("bad_req") 63 end, 64 case snmpa:current_community() of 65 {value, Str} when is_list(Str) -> Str; 66 {value, _} -> throw("bad_str"); 67 _ -> throw("bad_com") 68 end, 69 case snmpa:current_address() of 70 {value, {[_A,_B,_C,_D], E}} when is_integer(E) -> ok; 71 {value, {D, _}} when is_atom(D) -> ok; 72 {value, Ip} -> 73 throw(format_string("bad_ip: ~p", [Ip])); 74 Other -> 75 throw(format_string("bad_adr: ~p", [Other])) 76 end, 77 case snmpa:current_net_if_data() of 78 {value, []} -> ok; 79 {value, [{request_ref, R}]} when is_reference(R) -> ok; 80 {value, _} -> throw("bad_nil"); 81 _ -> throw("bad_nid") 82 end, 83 "ok" 84 end), 85 {value, Str2}. 86 87fname(is_set_ok, "hoj") -> 88 inconsistentValue; 89fname(is_set_ok, "xfail") -> 90 i_know_this_is_wrong_it_should_be_user_error; 91fname(is_set_ok, _) -> 92% io:format("calling fname is_set_ok~n"), 93 noError; 94fname(set, "fel") -> commitFailed; 95fname(set, _) -> noError; 96fname(undo, "ufail") -> 97% io:format("calling fname undo - fail~n"), 98 undoFailed; 99fname(undo, _) -> 100% io:format("calling fname undo~n"), 101 noError. 102 103%% snmp_mgr:s([{[fStatus2, 1], 4}, {[fname2,0], "ok"}]). -> noError 104%% snmp_mgr:s([{[fStatus2, 1], 4}, {[fname2,0], "hoj"}]). -> {badValue, 2} 105%% snmp_mgr:s([{[fStatus2, 3], 4}, {[fname2,0], "hoj"}]). -> {genErr, 1} 106%% snmp_mgr:s([{[fStatus2, 4], 4}, {[fname2,0], "ok"}]). -> {genErr, 1} 107%% snmp_mgr:s([{[fStatus2, 4], 4}, {[fname2,0], "ufail"}]). -> {genErr, 1} 108%% snmp_mgr:s([{[fStatus2, 1], 4}, {[fname2,0], "xfail"}]). -> {genErr, 2} 109 110 111fname4(get) -> 112 {value, none}. 113 114 115ftab2(_) -> 116 ok. 117 118 119%% Following 2 clauses is for OTP-1222 120ftab2(is_set_ok, [1], _Cols) -> 121 % bad column - In: col 2 & 3 122 io:format("** Here comes Error Report is_set_ok bad column~n"), 123 {inconsistentValue, 1}; 124ftab2(is_set_ok, _, _Cols) -> 125 {noError, 0}; 126 127ftab2(set, [2], _Cols) -> 128 % bad column - In: col 2 & 3 129 io:format("** Here comes Error Report set bad column~n"), 130 {commitFailed, 4}; 131ftab2(set, _, _Cols) -> 132 {noError, 0}; 133 134%% Unfortunatly we can't force the undo - we don't know which var 135%% is tried first. 136%ftab2(undo, [3], Cols) -> 137% % bad column - In: col 2 & 3 138% io:format("** Here comes (no Error Report) undo bad column~n"), 139% {undoFailed, 5}; 140%ftab2(undo, _, Cols) -> 141% {noError, 0}; 142 143ftab2(get, [4], _Cols) -> 144 % bad return value 145 io:format("** Here comes Error Report get 1 bad return~n"), 146 []; 147ftab2(get, [5], _Cols) -> 148 % bad return value 149 io:format("** Here comes Error Report get 2 bad return~n"), 150 [{value, 1}]; 151ftab2(get, [6], _Cols) -> 152 % bad return value 153 io:format("** Here comes Error Report get 3 bad return~n"), 154 [{value,1},{value,2},{value,3}]; 155 156ftab2(get_next, [7], _Cols) -> 157 % bad return value 158 io:format("** Here comes Error Report get_next 1 bad return~n"), 159 []; 160ftab2(get_next, [8], _Cols) -> 161 % bad return value 162 io:format("** Here comes Error Report get_next 2 bad return~n"), 163 [endOfTable]; 164ftab2(get_next, [9], _Cols) -> 165 % bad return value 166 io:format("** Here comes Error Report get_next 3 bad return~n"), 167 [{[1,5],1},{[2,5],3},{[2,6],3}]. 168 169format_string(Format, Args) -> 170 lists:flatten(io_lib:format(Format, Args)). 171