• 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 #ifndef BASE_REMOTE_COMMON_H
16 #define BASE_REMOTE_COMMON_H
17 
18 #include <vector>
19 
20 #include "constant.h"
21 #include "hap_token_info.h"
22 #include "native_token_info.h"
23 #include "nlohmann/json.hpp"
24 #include "permission_state_full.h"
25 #include "remote_protocol.h"
26 
27 namespace OHOS {
28 namespace Security {
29 namespace AccessToken {
30 /**
31  * The base class for command. You can treat this as remote command header.
32  */
33 class BaseRemoteCommand {
34 public:
35     BaseRemoteCommand() = default;
36     virtual ~BaseRemoteCommand() = default;
37 
38     /* Prepare() is called in requestor */
39     virtual void Prepare() = 0;
40 
41     /* Execute() is called in responser */
42     virtual void Execute() = 0;
43 
44     /* Finish() is called in requestor, after get response, but the command object is not same with the request */
45     virtual void Finish() = 0;
46 
47     virtual std::string ToJsonPayload() = 0;
48     nlohmann::json ToRemoteProtocolJson();
49     void FromRemoteProtocolJson(const nlohmann::json& jsonObject);
50 
51     void ToPermStateJson(nlohmann::json& permStateJson, const PermissionStateFull& state);
52     void FromPermStateListJson(const nlohmann::json& hapTokenJson,
53         std::vector<PermissionStateFull>& permStateList);
54 
55     void FromHapTokenBasicInfoJson(const nlohmann::json& hapTokenJson,
56         HapTokenInfo& hapTokenBasicInfo);
57 
58     nlohmann::json ToHapTokenInfosJson(const HapTokenInfoForSync &tokenInfo);
59     void FromHapTokenInfoJson(const nlohmann::json& hapTokenJson, HapTokenInfoForSync& hapTokenInfo);
60     nlohmann::json ToNativeTokenInfoJson(const NativeTokenInfo& tokenInfo);
61     void FromNativeTokenInfoJson(const nlohmann::json& nativeTokenJson, NativeTokenInfo& nativeTokenInfo);
62     RemoteProtocol remoteProtocol_;
63 };
64 }  // namespace AccessToken
65 }  // namespace Security
66 }  // namespace OHOS
67 #endif  // BASE_REMOTE_COMMON_H
68