| 1 |
|
%% Copyright (c) 2022 Peter Morgan <peter.james.morgan@gmail.com> |
| 2 |
|
%% |
| 3 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
|
%% you may not use this file except in compliance with the License. |
| 5 |
|
%% You may obtain a copy of the License at |
| 6 |
|
%% |
| 7 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
|
%% |
| 9 |
|
%% Unless required by applicable law or agreed to in writing, software |
| 10 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
|
%% See the License for the specific language governing permissions and |
| 13 |
|
%% limitations under the License. |
| 14 |
|
|
| 15 |
|
|
| 16 |
|
-module(mcd_emulator). |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
-behaviour(mcd_protocol). |
| 20 |
|
-export([expire/1]). |
| 21 |
|
-export([flush_all/1]). |
| 22 |
|
-export([init/1]). |
| 23 |
|
-export([recv/1]). |
| 24 |
|
-include_lib("kernel/include/logger.hrl"). |
| 25 |
|
-include_lib("stdlib/include/ms_transform.hrl"). |
| 26 |
|
-include("mcd_emulator.hrl"). |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
init([]) -> |
| 30 |
11 |
{ok, #{table => ets:new(?MODULE, [{keypos, 2}, public, named_table])}}. |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
recv(#{message := #{header := _}} = Arg) -> |
| 34 |
15 |
mcd_emulator_binary:recv(Arg); |
| 35 |
|
|
| 36 |
|
recv(#{message := #{meta := _}} = Arg) -> |
| 37 |
50 |
mcd_emulator_meta:recv(Arg); |
| 38 |
|
|
| 39 |
|
recv(#{message := #{command := _}} = Arg) -> |
| 40 |
139 |
mcd_emulator_text:recv(Arg). |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
expire(#{key := Key, data := #{table := Table}}) -> |
| 44 |
4 |
ets:delete(Table, Key), |
| 45 |
4 |
ok. |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
flush_all(#{data := #{table := Table}}) -> |
| 49 |
2 |
ets:delete_all_objects(Table), |
| 50 |
2 |
ok. |