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 DISTRIBUTEDDATAMGR_SESSIONMANAGER_H 17 #define DISTRIBUTEDDATAMGR_SESSIONMANAGER_H 18 19 #include <string> 20 #include <vector> 21 22 #include "serializable/serializable.h" 23 #include "commu_types.h" 24 #include "metadata/user_meta_data.h" 25 namespace OHOS::DistributedData { 26 using AclParams = OHOS::AppDistributedKv::AclParams; 27 using DistributedData::UserStatus; 28 struct SessionPoint { 29 std::string deviceId; 30 uint32_t userId; 31 std::string appId; 32 std::string storeId; 33 std::string accountId; 34 }; 35 36 class Session : public Serializable { 37 public: 38 std::string sourceDeviceId; 39 std::string targetDeviceId; 40 uint32_t sourceUserId; 41 std::vector<uint32_t> targetUserIds; 42 std::string appId; 43 std::string storeId; 44 std::string accountId; 45 bool Marshal(json &node) const override; 46 bool Unmarshal(const json &node) override; IsValid()47 inline bool IsValid() 48 { 49 return !targetUserIds.empty(); 50 } 51 }; 52 53 class SessionManager { 54 public: 55 static SessionManager &GetInstance(); 56 Session GetSession(const SessionPoint &local, const std::string &targetDeviceId) const; 57 bool CheckSession(const SessionPoint &local, const SessionPoint &peer, bool accountFlag) const; 58 private: 59 bool GetSendAuthParams(const SessionPoint &local, const std::string &targetDeviceId, 60 AclParams &aclParams) const; 61 bool GetRecvAuthParams(const SessionPoint &local, const SessionPoint &peer, bool accountFlag, 62 AclParams &aclParams) const; 63 }; 64 } // namespace OHOS::DistributedData 65 66 #endif // DISTRIBUTEDDATAMGR_SESSIONMANAGER_H 67