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