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 16 #ifndef DEFAULT_VIBRATOR_DECODER_H 17 #define DEFAULT_VIBRATOR_DECODER_H 18 19 #include <cstdint> 20 #include <vector> 21 22 #include "json_parser.h" 23 #include "vibrator_decoder.h" 24 25 namespace OHOS { 26 namespace Sensors { 27 class DefaultVibratorDecoder : public VibratorDecoder { 28 public: 29 DefaultVibratorDecoder() = default; 30 ~DefaultVibratorDecoder() = default; 31 std::set<VibrateEvent> DecodeEffect(const RawFileDescriptor &rawFd) override; 32 33 private: 34 int32_t CheckMetadata(const JsonParser &parser); 35 int32_t ParseChannel(const JsonParser &parser, std::set<VibrateEvent> &vibrateSet); 36 int32_t ParseChannelParameters(const JsonParser &parser, cJSON *channelParameters); 37 int32_t ParsePattern(const JsonParser &parser, cJSON *pattern, std::set<VibrateEvent> &vibrateSet); 38 int32_t ParseEvent(const JsonParser &parser, cJSON *event, std::set<VibrateEvent> &vibrateSet); 39 bool CheckParameters(const VibrateEvent &vibrateEvent); 40 int32_t channelNumber_ = 0; 41 double version_ = 0.0; 42 }; 43 } // namespace Sensors 44 } // namespace OHOS 45 #endif // VIBRATOR_DECODER_H