1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 1998-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-module(dbg_idb).
21
22%% External exports
23-export([insert/3, lookup/2, match_object/2]).
24
25%%====================================================================
26%% External exports
27%%====================================================================
28
29insert(DbRef, Key, Value) ->
30    case DbRef of
31	{Node, ModDb} ->
32	    rpc:block_call(Node, ets, insert, [ModDb, {Key, Value}]);
33	ModDb ->
34	    ets:insert(ModDb, {Key, Value})
35    end.
36
37lookup(DbRef, Key) ->
38    Res = case DbRef of
39	      {Node, ModDb} ->
40		  rpc:block_call(Node, ets, lookup, [ModDb, Key]);
41	      ModDb ->
42		  ets:lookup(ModDb, Key)
43	  end,
44    case Res of
45	[{Key, Value}] -> {ok, Value};
46	_ -> not_found
47    end.
48
49match_object(DbRef, Key) ->
50    case DbRef of
51	{Node, ModDb} ->
52	    rpc:block_call(Node, ets, match_object, [ModDb, Key]);
53	ModDb ->
54	    ets:match_object(ModDb, Key)
55    end.
56