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 DISTRIBUTED_RDB_RDB_RESULT_SET_STUB_H
17 #define DISTRIBUTED_RDB_RDB_RESULT_SET_STUB_H
18 
19 #include <iremote_stub.h>
20 #include "irdb_result_set.h"
21 #include "result_set.h"
22 
23 namespace OHOS::DistributedRdb {
24 class RdbResultSetStub : public IRemoteStub<IRdbResultSet> {
25 public:
26     using Code = NativeRdb::RemoteResultSet::Code;
27     explicit RdbResultSetStub(std::shared_ptr<NativeRdb::ResultSet> resultSet);
28     int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
29 
30 private:
31     int32_t OnGetAllColumnNames(MessageParcel &data, MessageParcel &reply);
32     int32_t OnGetColumnCount(MessageParcel &data, MessageParcel &reply);
33     int32_t OnGetColumnType(MessageParcel &data, MessageParcel &reply);
34     int32_t OnGetRowCount(MessageParcel &data, MessageParcel &reply);
35     int32_t OnGetRowIndex(MessageParcel &data, MessageParcel &reply);
36     int32_t OnGoTo(MessageParcel &data, MessageParcel &reply);
37     int32_t OnGoToRow(MessageParcel &data, MessageParcel &reply);
38     int32_t OnGoToFirstRow(MessageParcel &data, MessageParcel &reply);
39     int32_t OnGoToLastRow(MessageParcel &data, MessageParcel &reply);
40     int32_t OnGoToNextRow(MessageParcel &data, MessageParcel &reply);
41     int32_t OnGoToPreviousRow(MessageParcel &data, MessageParcel &reply);
42     int32_t OnIsEnded(MessageParcel &data, MessageParcel &reply);
43     int32_t OnIsStarted(MessageParcel &data, MessageParcel &reply);
44     int32_t OnIsAtFirstRow(MessageParcel &data, MessageParcel &reply);
45     int32_t OnIsAtLastRow(MessageParcel &data, MessageParcel &reply);
46     int32_t OnGet(MessageParcel &data, MessageParcel &reply);
47     int32_t OnGetSize(MessageParcel &data, MessageParcel &reply);
48     int32_t OnClose(MessageParcel &data, MessageParcel &reply);
49 
50     static bool CheckInterfaceToken(MessageParcel &data);
51     using RequestHandle = int (RdbResultSetStub::*)(MessageParcel &, MessageParcel &);
52     static constexpr RequestHandle HANDLERS[Code::CMD_MAX] = {
53         [Code::CMD_GET_ALL_COLUMN_NAMES] = &RdbResultSetStub::OnGetAllColumnNames,
54         [Code::CMD_GET_COLUMN_COUNT] = &RdbResultSetStub::OnGetColumnCount,
55         [Code::CMD_GET_COLUMN_TYPE] = &RdbResultSetStub::OnGetColumnType,
56         [Code::CMD_GET_ROW_COUNT] = &RdbResultSetStub::OnGetRowCount,
57         [Code::CMD_GET_ROW_INDEX] = &RdbResultSetStub::OnGetRowIndex,
58         [Code::CMD_GO_TO] = &RdbResultSetStub::OnGoTo,
59         [Code::CMD_GO_TO_ROW] = &RdbResultSetStub::OnGoToRow,
60         [Code::CMD_GO_TO_FIRST_ROW] = &RdbResultSetStub::OnGoToFirstRow,
61         [Code::CMD_GO_TO_LAST_ROW] = &RdbResultSetStub::OnGoToLastRow,
62         [Code::CMD_GO_TO_NEXT_ROW] = &RdbResultSetStub::OnGoToNextRow,
63         [Code::CMD_GO_TO_PREV_ROW] = &RdbResultSetStub::OnGoToPreviousRow,
64         [Code::CMD_IS_ENDED_ROW] = &RdbResultSetStub::OnIsEnded,
65         [Code::CMD_IS_STARTED_ROW] = &RdbResultSetStub::OnIsStarted,
66         [Code::CMD_IS_AT_FIRST_ROW] = &RdbResultSetStub::OnIsAtFirstRow,
67         [Code::CMD_IS_AT_LAST_ROW] = &RdbResultSetStub::OnIsAtLastRow,
68         [Code::CMD_GET] = &RdbResultSetStub::OnGet,
69         [Code::CMD_GET_SIZE] = &RdbResultSetStub::OnGetSize,
70         [Code::CMD_CLOSE] = &RdbResultSetStub::OnClose
71     };
72     std::shared_ptr<NativeRdb::ResultSet> resultSet_;
73 };
74 } // namespace OHOS::DistributedRdb
75 #endif // DISTRIBUTED_RDB_RDB_RESULT_SET_STUB_H
76