• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
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 #include "vibrator_decoder_creator.h"
16 
17 #include "default_vibrator_decoder_factory.h"
18 #include "he_vibrator_decoder_factory.h"
19 #include "sensors_errors.h"
20 
21 #undef LOG_TAG
22 #define LOG_TAG "VibratorDecoderCreator"
23 
24 namespace OHOS {
25 namespace Sensors {
26 namespace {
27 const std::string JSON_TAG = "Channels";
28 } // namespace
CreateDecoder(const JsonParser & parser)29 IVibratorDecoder *VibratorDecoderCreator::CreateDecoder(const JsonParser &parser)
30 {
31     CALL_LOG_ENTER;
32     if (CheckJsonMetadata(parser)) {
33         MISC_HILOGD("Get oh_json tag");
34         DefaultVibratorDecoderFactory factory;
35         return factory.CreateDecoder();
36     } else {
37         MISC_HILOGD("Get he tag");
38         HEVibratorDecoderFactory factory;
39         return factory.CreateDecoder();
40     }
41     MISC_HILOGE("Create decoder fail");
42     return nullptr;
43 }
44 
CheckJsonMetadata(const JsonParser & parser)45 bool VibratorDecoderCreator::CheckJsonMetadata(const JsonParser &parser)
46 {
47     return parser.HasObjectItem(JSON_TAG);
48 }
49 
Create(const JsonParser & parser)50 extern "C" IVibratorDecoder *Create(const JsonParser &parser)
51 {
52     VibratorDecoderCreator creator;
53     return creator.CreateDecoder(parser);
54 }
55 
Destroy(IVibratorDecoder * decoder)56 extern "C" void Destroy(IVibratorDecoder *decoder)
57 {
58     if (decoder != nullptr) {
59         delete decoder;
60         decoder = nullptr;
61     }
62 }
63 } // namespace Sensors
64 } // namespace OHOS