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 void SetSecLabel(int32_t secLabel); 59 60 int32_t GetSecLabel() const; 61 62 static RemoteExecutorRequestPacket* Create(); 63 64 static void Release(RemoteExecutorRequestPacket *&packet); 65 66 static const uint32_t REQUEST_PACKET_VERSION_V1 = SOFTWARE_VERSION_RELEASE_6_0; 67 static const uint32_t REQUEST_PACKET_VERSION_V2 = SOFTWARE_VERSION_RELEASE_6_0 + 1; 68 static const uint32_t REQUEST_PACKET_VERSION_V3 = SOFTWARE_VERSION_RELEASE_6_0 + 2; 69 static const uint32_t REQUEST_PACKET_VERSION_CURRENT = REQUEST_PACKET_VERSION_V3; 70 private: 71 uint32_t version_ = 0u; 72 uint32_t flag_ = 0u; // 0x01 mean need reply ack 73 PreparedStmt perparedStmt_; 74 std::map<std::string, std::string> extraConditions_; 75 int32_t secLabel_ = UNKNOWN_SECURITY_LABEL; // source sec label 76 }; 77 78 class RemoteExecutorAckPacket : public ISyncPacket { 79 public: 80 RemoteExecutorAckPacket(); 81 82 ~RemoteExecutorAckPacket() override; 83 84 uint32_t GetVersion() const; 85 86 void SetVersion(uint32_t version); 87 88 uint32_t GetFlag() const; 89 90 void SetFlag(uint32_t flag); 91 92 int32_t GetAckCode() const; 93 94 void SetAckCode(int32_t ackCode); 95 96 void MoveInRowDataSet(RelationalRowDataSet &&rowDataSet); 97 98 RelationalRowDataSet &&MoveOutRowDataSet() const; 99 100 bool IsLastAck() const; 101 102 void SetLastAck(); 103 104 SecurityOption GetSecurityOption() const; 105 106 void SetSecurityOption(const SecurityOption &option); 107 108 uint32_t CalculateLen() const override; 109 110 int Serialization(Parcel &parcel) const override; 111 112 int DeSerialization(Parcel &parcel) override; 113 114 static const uint32_t RESPONSE_PACKET_VERSION_V1 = SOFTWARE_VERSION_RELEASE_6_0; 115 static const uint32_t RESPONSE_PACKET_VERSION_CURRENT = RESPONSE_PACKET_VERSION_V1; 116 private: 117 uint32_t version_ = 0u; 118 int32_t ackCode_ = 0; 119 uint32_t flag_ = 0u; // 0x01 mean last one 120 mutable RelationalRowDataSet rowDataSet_; 121 int32_t secLabel_ = 0; 122 int32_t secFlag_ = 0; 123 }; 124 } 125 #endif