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_base.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 /** 32 * @brief Declares native token info for distributed synchronize class 33 */ 34 class NativeTokenInfoForSync final { 35 public: 36 /** native token info */ 37 NativeTokenInfoBase baseInfo; 38 /** permission state list */ 39 std::vector<PermissionStateFull> permStateList; 40 }; 41 42 /** 43 * The base class for command. You can treat this as remote command header. 44 */ 45 class BaseRemoteCommand { 46 public: 47 BaseRemoteCommand() = default; 48 virtual ~BaseRemoteCommand() = default; 49 50 /* Prepare() is called in requestor */ 51 virtual void Prepare() = 0; 52 53 /* Execute() is called in responser */ 54 virtual void Execute() = 0; 55 56 /* Finish() is called in requestor, after get response, but the command object is not same with the request */ 57 virtual void Finish() = 0; 58 59 virtual std::string ToJsonPayload() = 0; 60 nlohmann::json ToRemoteProtocolJson(); 61 void FromRemoteProtocolJson(const nlohmann::json& jsonObject); 62 63 void ToPermStateJson(nlohmann::json& permStateJson, const PermissionStateFull& state); 64 void FromPermStateListJson(const nlohmann::json& hapTokenJson, 65 std::vector<PermissionStateFull>& permStateList); 66 67 void FromHapTokenBasicInfoJson(const nlohmann::json& hapTokenJson, 68 HapTokenInfo& hapTokenBasicInfo); 69 70 nlohmann::json ToHapTokenInfosJson(const HapTokenInfoForSync &tokenInfo); 71 void FromHapTokenInfoJson(const nlohmann::json& hapTokenJson, HapTokenInfoForSync& hapTokenInfo); 72 nlohmann::json ToNativeTokenInfoJson(const NativeTokenInfoForSync& tokenInfo); 73 void FromNativeTokenInfoJson(const nlohmann::json& nativeTokenJson, NativeTokenInfoForSync& nativeTokenInfo); 74 RemoteProtocol remoteProtocol_; 75 }; 76 } // namespace AccessToken 77 } // namespace Security 78 } // namespace OHOS 79 #endif // BASE_REMOTE_COMMON_H 80