1 |
|
-module(mongoose_component_cets). |
2 |
|
-behaviour(mongoose_component_backend). |
3 |
|
|
4 |
|
-export([init/1, |
5 |
|
node_cleanup/1, |
6 |
|
register_components/1, |
7 |
|
unregister_components/1, |
8 |
|
lookup_component/1, |
9 |
|
lookup_component/2, |
10 |
|
get_all_components/1]). |
11 |
|
|
12 |
|
-include("external_component.hrl"). |
13 |
|
-define(TABLE, cets_external_component). |
14 |
|
|
15 |
|
init(_) -> |
16 |
:-( |
cets:start(?TABLE, #{type => bag, keypos => 2}), |
17 |
:-( |
cets_discovery:add_table(mongoose_cets_discovery, ?TABLE). |
18 |
|
|
19 |
|
node_cleanup(Node) -> |
20 |
:-( |
ets:match_delete(?TABLE, #external_component{node = Node, _ = '_'}), |
21 |
:-( |
ok. |
22 |
|
|
23 |
|
register_components(Components) -> |
24 |
:-( |
cets:insert_many(?TABLE, Components), |
25 |
:-( |
ok. |
26 |
|
|
27 |
|
unregister_components(Components) -> |
28 |
:-( |
cets:delete_objects(?TABLE, Components), |
29 |
:-( |
ok. |
30 |
|
|
31 |
|
lookup_component(Domain) -> |
32 |
:-( |
ets:lookup(?TABLE, Domain). |
33 |
|
|
34 |
|
lookup_component(Domain, Node) -> |
35 |
:-( |
ets:match_object(?TABLE, #external_component{domain = Domain, node = Node, _ = '_'}). |
36 |
|
|
37 |
|
get_all_components(all) -> |
38 |
:-( |
MatchAll = {#external_component{ domain = '$1', _ = '_' }, [], ['$1']}, |
39 |
:-( |
ets:select(?TABLE, [MatchAll]); |
40 |
|
get_all_components(only_public) -> |
41 |
:-( |
MatchNonHidden = {#external_component{ domain = '$1', is_hidden = false, _ = '_' }, [], ['$1']}, |
42 |
:-( |
ets:select(?TABLE, [MatchNonHidden]). |