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 RPC_CHANNEL_H
17#define RPC_CHANNEL_H
18
19namespace OHOS {
20namespace Security {
21namespace AccessToken {
22/*
23 * Channel used for communicate with peer devices.
24 */
25class RpcChannel {
26public:
27    /**
28     * @brief Build connection with peer device.
29     *
30     * @return Result code represent if build successfully. 0 indicates success, -1 indicates failure.
31     * @since 1.0
32     * @version 1.0
33     */
34    virtual int BuildConnection() = 0;
35
36    /**
37     * @brief Execute BaseRemoteCommand at peer device.
38     *
39     * @param commandName The name of Command.
40     * @param jsonPayload The json payload of command.
41     * @return Executed result response string.
42     * @since 1.0
43     * @version 1.0
44     */
45    virtual std::string ExecuteCommand(const std::string &commandName, const std::string &jsonPayload) = 0;
46
47    /**
48     * @brief Handle data received. This interface only use for soft bus channel.
49     *
50     * @param session Session with peer device.
51     * @param bytes Data sent from the peer device.
52     * @param length Data length sent from the peer device.
53     * @since 1.0
54     * @version 1.0
55     */
56    virtual void HandleDataReceived(int session, const unsigned char *bytes, int length)
57    {}
58
59    /**
60     * @brief Close rpc connection when no data is being transmitted.
61     *
62     * @since 1.0
63     * @version 1.0
64     */
65    virtual void CloseConnection()
66    {}
67
68    /**
69     * @brief Release resources when the device offline.
70     *
71     * @since 1.0
72     * @version 1.0
73     */
74    virtual void Release() {}
75};
76}  // namespace AccessToken
77}  // namespace Security
78}  // namespace OHOS
79
80#endif