1b1994897Sopenharmony_ci# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2b1994897Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
3b1994897Sopenharmony_ci# you may not use this file except in compliance with the License.
4b1994897Sopenharmony_ci# You may obtain a copy of the License at
5b1994897Sopenharmony_ci#
6b1994897Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0
7b1994897Sopenharmony_ci#
8b1994897Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
9b1994897Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
10b1994897Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11b1994897Sopenharmony_ci# See the License for the specific language governing permissions and
12b1994897Sopenharmony_ci# limitations under the License.
13b1994897Sopenharmony_ci
14b1994897Sopenharmony_cirequire 'ostruct'
15b1994897Sopenharmony_cirequire 'delegate'
16b1994897Sopenharmony_ci
17b1994897Sopenharmony_ciclass Level
18b1994897Sopenharmony_ci  attr_reader :name
19b1994897Sopenharmony_ci  attr_reader :value
20b1994897Sopenharmony_ci  attr_reader :enum
21b1994897Sopenharmony_ci  attr_reader :tag
22b1994897Sopenharmony_ci
23b1994897Sopenharmony_ci  def initialize(dscr)
24b1994897Sopenharmony_ci     @dscr = dscr
25b1994897Sopenharmony_ci     @name = dscr['name']
26b1994897Sopenharmony_ci     @value = dscr['value']
27b1994897Sopenharmony_ci     @enum = dscr['enum'] || @name.upcase
28b1994897Sopenharmony_ci     @tag = dscr['tag'] || @name[0].upcase
29b1994897Sopenharmony_ci  end
30b1994897Sopenharmony_ciend
31b1994897Sopenharmony_ci
32b1994897Sopenharmony_ciclass Component
33b1994897Sopenharmony_ci  attr_reader :name
34b1994897Sopenharmony_ci  attr_reader :enum
35b1994897Sopenharmony_ci
36b1994897Sopenharmony_ci  def initialize(dscr)
37b1994897Sopenharmony_ci    @dscr = dscr
38b1994897Sopenharmony_ci    @name = dscr['name']
39b1994897Sopenharmony_ci    @enum = dscr['enum'] || @name.upcase
40b1994897Sopenharmony_ci  end
41b1994897Sopenharmony_ciend
42b1994897Sopenharmony_ci
43b1994897Sopenharmony_cimodule LoggerData
44b1994897Sopenharmony_ci  module_function
45b1994897Sopenharmony_ci
46b1994897Sopenharmony_ci  def levels
47b1994897Sopenharmony_ci    @levels
48b1994897Sopenharmony_ci  end
49b1994897Sopenharmony_ci
50b1994897Sopenharmony_ci  def components
51b1994897Sopenharmony_ci    @components
52b1994897Sopenharmony_ci  end
53b1994897Sopenharmony_ci
54b1994897Sopenharmony_ci  def dfx_components
55b1994897Sopenharmony_ci    @dfx_components
56b1994897Sopenharmony_ci  end
57b1994897Sopenharmony_ci
58b1994897Sopenharmony_ci  def wrap_data(data)
59b1994897Sopenharmony_ci    @data = data
60b1994897Sopenharmony_ci    @levels = data.levels.map { |op| Level.new(op) }
61b1994897Sopenharmony_ci    @components = data.components.map { |op| Component.new(op) }
62b1994897Sopenharmony_ci    @dfx_components = data.dfx_components.map { |op| Component.new(op) }
63b1994897Sopenharmony_ci  end
64b1994897Sopenharmony_ciend
65b1994897Sopenharmony_ci
66b1994897Sopenharmony_cidef Gen.on_require(data)
67b1994897Sopenharmony_ci  LoggerData.wrap_data(data)
68b1994897Sopenharmony_ciend
69