1 /* 2 * Copyright (c) 2022 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 REMOTE_EXECUTOR_PACKET_H 17 #define REMOTE_EXECUTOR_PACKET_H 18 19 #include "isync_packet.h" 20 #include "message.h" 21 #include "prepared_stmt.h" 22 #include "relational_row_data_set.h" 23 #include "sync_types.h" 24 #include "version.h" 25 26 namespace DistributedDB { 27 class RemoteExecutorRequestPacket : public ISyncPacket { 28 public: 29 RemoteExecutorRequestPacket(); 30 ~RemoteExecutorRequestPacket() override; 31 32 uint32_t GetVersion() const; 33 34 void SetVersion(uint32_t version); 35 36 uint32_t GetFlag() const; 37 38 void SetFlag(uint32_t flag); 39 40 PreparedStmt GetPreparedStmt() const; 41 42 void SetPreparedStmt(const PreparedStmt &perparedStmt); 43 44 bool IsNeedResponse() const; 45 46 void SetNeedResponse(); 47 48 void SetExtraConditions(const std::map<std::string, std::string> &extraConditions); 49 50 std::map<std::string, std::string> GetExtraConditions() const; 51 52 uint32_t CalculateLen() const override; 53 54 int Serialization(Parcel &parcel) const override; 55 56 int DeSerialization(Parcel &parcel) override; 57 58 static RemoteExecutorRequestPacket* Create(); 59 60 static void Release(RemoteExecutorRequestPacket *&packet); 61 62 static const uint32_t REQUEST_PACKET_VERSION_V1 = SOFTWARE_VERSION_RELEASE_6_0; 63 static const uint32_t REQUEST_PACKET_VERSION_V2 = SOFTWARE_VERSION_RELEASE_6_0 + 1; 64 static const uint32_t REQUEST_PACKET_VERSION_CURRENT = REQUEST_PACKET_VERSION_V2; 65 private: 66 uint32_t version_ = 0u; 67 uint32_t flag_ = 0u; // 0x01 mean need reply ack 68 PreparedStmt perparedStmt_; 69 std::map<std::string, std::string> extraConditions_; 70 }; 71 72 class RemoteExecutorAckPacket : public ISyncPacket { 73 public: 74 RemoteExecutorAckPacket(); 75 76 ~RemoteExecutorAckPacket() override; 77 78 uint32_t GetVersion() const; 79 80 void SetVersion(uint32_t version); 81 82 uint32_t GetFlag() const; 83 84 void SetFlag(uint32_t flag); 85 86 int32_t GetAckCode() const; 87 88 void SetAckCode(int32_t ackCode); 89 90 void MoveInRowDataSet(RelationalRowDataSet &&rowDataSet); 91 92 RelationalRowDataSet &&MoveOutRowDataSet() const; 93 94 bool IsLastAck() const; 95 96 void SetLastAck(); 97 98 SecurityOption GetSecurityOption() const; 99 100 void SetSecurityOption(const SecurityOption &option); 101 102 uint32_t CalculateLen() const override; 103 104 int Serialization(Parcel &parcel) const override; 105 106 int DeSerialization(Parcel &parcel) override; 107 108 static const uint32_t RESPONSE_PACKET_VERSION_V1 = SOFTWARE_VERSION_RELEASE_6_0; 109 static const uint32_t RESPONSE_PACKET_VERSION_CURRENT = RESPONSE_PACKET_VERSION_V1; 110 private: 111 uint32_t version_ = 0u; 112 int32_t ackCode_ = 0; 113 uint32_t flag_ = 0u; // 0x01 mean last one 114 mutable RelationalRowDataSet rowDataSet_; 115 int32_t secLabel_ = 0; 116 int32_t secFlag_ = 0; 117 }; 118 } 119 #endif