• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     const PreparedStmt &GetPreparedStmt() const;
41 
42     bool IsNeedResponse() const;
43 
44     void SetNeedResponse();
45 
46     void SetExtraConditions(const std::map<std::string, std::string> &extraConditions);
47 
48     std::map<std::string, std::string> GetExtraConditions() const;
49 
50     uint32_t CalculateLen() const override;
51 
52     int Serialization(Parcel &parcel) const override;
53 
54     int DeSerialization(Parcel &parcel) override;
55 
56     void SetOpCode(PreparedStmt::ExecutorOperation opCode);
57 
58     void SetSql(const std::string &sql);
59 
60     void SetBindArgs(const std::vector<std::string> &bindArgs);
61 
62     void SetSecLabel(int32_t secLabel);
63 
64     int32_t GetSecLabel() const;
65 
66     static RemoteExecutorRequestPacket* Create();
67 
68     static void Release(RemoteExecutorRequestPacket *&packet);
69 
70     static const uint32_t REQUEST_PACKET_VERSION_V1 = SOFTWARE_VERSION_RELEASE_6_0;
71     static const uint32_t REQUEST_PACKET_VERSION_V2 = SOFTWARE_VERSION_RELEASE_6_0 + 1;
72     static const uint32_t REQUEST_PACKET_VERSION_V3 = SOFTWARE_VERSION_RELEASE_6_0 + 2;
73     static const uint32_t REQUEST_PACKET_VERSION_CURRENT = REQUEST_PACKET_VERSION_V3;
74 private:
75     uint32_t version_ = 0u;
76     uint32_t flag_ = 0u; // 0x01 mean need reply ack
77     PreparedStmt preparedStmt_;
78     std::map<std::string, std::string> extraConditions_;
79     int32_t secLabel_ = UNKNOWN_SECURITY_LABEL; // source sec label
80 };
81 
82 class RemoteExecutorAckPacket : public ISyncPacket {
83 public:
84     RemoteExecutorAckPacket();
85 
86     ~RemoteExecutorAckPacket() override;
87 
88     uint32_t GetVersion() const;
89 
90     void SetVersion(uint32_t version);
91 
92     uint32_t GetFlag() const;
93 
94     void SetFlag(uint32_t flag);
95 
96     int32_t GetAckCode() const;
97 
98     void SetAckCode(int32_t ackCode);
99 
100     void MoveInRowDataSet(RelationalRowDataSet &&rowDataSet);
101 
102     RelationalRowDataSet &&MoveOutRowDataSet() const;
103 
104     bool IsLastAck() const;
105 
106     void SetLastAck();
107 
108     SecurityOption GetSecurityOption() const;
109 
110     void SetSecurityOption(const SecurityOption &option);
111 
112     uint32_t CalculateLen() const override;
113 
114     int Serialization(Parcel &parcel) const override;
115 
116     int DeSerialization(Parcel &parcel) override;
117 
118     static const uint32_t RESPONSE_PACKET_VERSION_V1 = SOFTWARE_VERSION_RELEASE_6_0;
119     static const uint32_t RESPONSE_PACKET_VERSION_CURRENT = RESPONSE_PACKET_VERSION_V1;
120 private:
121     uint32_t version_ = 0u;
122     int32_t ackCode_ = 0;
123     uint32_t flag_ = 0u; // 0x01 mean last one
124     mutable RelationalRowDataSet rowDataSet_;
125     int32_t secLabel_ = 0;
126     int32_t secFlag_ = 0;
127 };
128 }
129 #endif