1 /* 2 * Copyright (c) 2024 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 OHOS_RELATIONSHIP_SYNC_MGR_H 17 #define OHOS_RELATIONSHIP_SYNC_MGR_H 18 19 #include <cinttypes> 20 #include <string> 21 #include "cJSON.h" 22 #include "dm_single_instance.h" 23 namespace OHOS { 24 namespace DistributedHardware { 25 enum class RelationShipChangeType : uint32_t { 26 ACCOUNT_LOGOUT = 0, 27 DEVICE_UNBIND = 1, 28 APP_UNBIND = 2, 29 SERVICE_UNBIND = 3, 30 DEL_USER = 4, 31 APP_UNINSTALL = 5, 32 TYPE_MAX = 6 33 }; 34 35 struct RelationShipChangeMsg { 36 RelationShipChangeType type; 37 uint32_t userId; 38 std::string accountId; 39 uint64_t tokenId; 40 std::vector<std::string> peerUdids; 41 std::string peerUdid; 42 std::string accountName; 43 44 explicit RelationShipChangeMsg(); 45 bool ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) const; 46 bool FromBroadcastPayLoad(const cJSON *payloadJson, RelationShipChangeType type); 47 bool IsValid() const; 48 bool IsChangeTypeValid(); 49 bool IsChangeTypeValid(uint32_t type); 50 void ToAccountLogoutPayLoad(uint8_t *&msg, uint32_t &len) const; 51 void ToDeviceUnbindPayLoad(uint8_t *&msg, uint32_t &len) const; 52 void ToAppUnbindPayLoad(uint8_t *&msg, uint32_t &len) const; 53 cJSON *ToArrayJson() const; 54 55 bool FromAccountLogoutPayLoad(const cJSON *payloadJson); 56 bool FromDeviceUnbindPayLoad(const cJSON *payloadJson); 57 bool FromAppUnbindPayLoad(const cJSON *payloadJson); 58 59 std::string ToJson() const; 60 bool FromJson(const std::string &msgJson); 61 }; 62 63 class ReleationShipSyncMgr { 64 DM_DECLARE_SINGLE_INSTANCE(ReleationShipSyncMgr); 65 public: 66 std::string SyncTrustRelationShip(const RelationShipChangeMsg &msg); 67 RelationShipChangeMsg ParseTrustRelationShipChange(const std::string &msgJson); 68 }; 69 70 } // DistributedHardware 71 } // OHOS 72 #endif // OHOS_RELATIONSHIP_SYNC_MGR_H