• 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 
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 };
34 
35 class Session : public Serializable {
36 public:
37     std::string sourceDeviceId;
38     std::string targetDeviceId;
39     uint32_t sourceUserId;
40     std::vector<uint32_t> targetUserIds;
41     std::string appId;
42     bool Marshal(json &node) const override;
43     bool Unmarshal(const json &node) override;
IsValid()44     inline bool IsValid()
45     {
46         return !targetUserIds.empty();
47     }
48 };
49 
50 class SessionManager {
51 public:
52     static SessionManager &GetInstance();
53     Session GetSession(const SessionPoint &local, const std::string &targetDeviceId) const;
54     bool CheckSession(const SessionPoint &local, const SessionPoint &peer) const;
55 private:
56     bool GetSendAuthParams(const SessionPoint &local, const std::string &targetDeviceId,
57         AclParams &aclParams) const;
58     bool GetRecvAuthParams(const SessionPoint &local, const std::string &targetDeviceId,
59         AclParams &aclParams, int peerUser) const;
60 };
61 } // namespace OHOS::DistributedData
62 
63 #endif // DISTRIBUTEDDATAMGR_SESSIONMANAGER_H
64