1 /* 2 * Copyright (c) 2025 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 #ifndef MC_PROTOCOL_CONVERTOR_H 16 #define MC_PROTOCOL_CONVERTOR_H 17 18 #include "mechbody_controller_types.h" 19 #include "mc_data_buffer.h" 20 21 namespace OHOS { 22 namespace MechBodyController { 23 24 class IProtocolConverter { 25 public: 26 virtual ~IProtocolConverter() = default; 27 28 virtual std::shared_ptr<MechDataBuffer> Convert( 29 OptType optType, uint16_t seqNo, std::shared_ptr<MechDataBuffer> data) const = 0; 30 31 virtual std::shared_ptr<MechDataBuffer> GetData( 32 std::shared_ptr<MechDataBuffer> pclData, uint16_t &seqNo, bool &isAck) const = 0; 33 34 virtual int32_t GetVersion() const = 0; 35 36 virtual bool Validate(const uint8_t* data, size_t length) const = 0; 37 }; 38 39 class ProtocolConverter : public IProtocolConverter { 40 private: 41 static constexpr int32_t PROTOCOL_VERSION = 0; 42 const std::string BT_PAYLOAD_MECH_SERVICE_NAME = "MechanicData"; 43 public: 44 std::shared_ptr<MechDataBuffer> Convert( 45 OptType optType, uint16_t seqNo, std::shared_ptr<MechDataBuffer> data) const override; 46 std::shared_ptr<MechDataBuffer> Convert( 47 OptType optType, uint16_t seqNo, std::shared_ptr<MechDataBuffer> data, std::string serviceName); 48 std::shared_ptr<MechDataBuffer> GetData( 49 std::shared_ptr<MechDataBuffer> pclData, uint16_t &seqNo, bool &isAck) const override; 50 GetVersion()51 int32_t GetVersion() const override { return PROTOCOL_VERSION; } 52 53 bool Validate(const uint8_t* data, size_t length) const override; 54 private: 55 std::string serviceName_ = BT_PAYLOAD_MECH_SERVICE_NAME; 56 }; 57 } // namespace MechBodyController 58 } // namespace OHOS 59 60 #endif // MC_PROTOCOL_CONVERTOR_H 61