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 
24 namespace OHOS::DistributedData {
25 struct SessionPoint {
26     std::string deviceId;
27     uint32_t userId;
28     std::string appId;
29     std::string storeId;
30 };
31 
32 class Session : public Serializable {
33 public:
34     std::string sourceDeviceId;
35     std::string targetDeviceId;
36     uint32_t sourceUserId;
37     std::vector<uint32_t> targetUserIds;
38     std::string appId;
39     bool Marshal(json &node) const override;
40     bool Unmarshal(const json &node) override;
IsValid()41     inline bool IsValid()
42     {
43         return !targetUserIds.empty();
44     }
45 };
46 
47 class SessionManager {
48 public:
49     static SessionManager &GetInstance();
50     Session GetSession(const SessionPoint &from, const std::string &targetDeviceId) const;
51     bool CheckSession(const SessionPoint &from, const SessionPoint &to) const;
52 private:
53     bool GetAuthParams(const SessionPoint &from, std::string &bundleName, int32_t &auth) const;
54 };
55 } // namespace OHOS::DistributedData
56 
57 #endif // DISTRIBUTEDDATAMGR_SESSIONMANAGER_H
58