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 "i_vibrator_decoder.h"
23 #include "json_parser.h"
24 
25 namespace OHOS {
26 namespace Sensors {
27 class DefaultVibratorDecoder : public IVibratorDecoder {
28 public:
29     DefaultVibratorDecoder() = default;
30     ~DefaultVibratorDecoder() = default;
31     int32_t DecodeEffect(const RawFileDescriptor &rawFd, const JsonParser &parser,
32         VibratePackage &patternPackage) override;
33 
34 private:
35     int32_t CheckMetadata(const JsonParser &parser);
36     int32_t ParseChannel(const JsonParser &parser, VibratePattern &originPattern, VibratePackage &patternPackage);
37     int32_t ParseChannelParameters(const JsonParser &parser, cJSON *channelParametersItem);
38     int32_t ParsePattern(const JsonParser &parser, cJSON *patternItem, VibratePattern &originPattern);
39     int32_t ParseEvent(const JsonParser &parser, cJSON *eveventItement, VibrateEvent &events);
40     bool CheckEventParameters(const VibrateEvent &event);
41     int32_t ParseCurve(const JsonParser &parser, cJSON *curveItem, VibrateEvent &event);
42     void PatternSplit(VibratePattern &originPattern, VibratePackage &patternPackage);
43     int32_t channelNumber_ = 0;
44     double version_ = 0.0;
45 };
46 }  // namespace Sensors
47 }  // namespace OHOS
48 #endif  // VIBRATOR_DECODER_H