• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DISTRIBUTED_DEVICE_STATUS_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DISTRIBUTED_DEVICE_STATUS_H
18 
19 #include <cstdint>
20 #include <singleton.h>
21 #include <string>
22 #include <vector>
23 
24 #include "errors.h"
25 #include "ans_log_wrapper.h"
26 #include "safe_map.h"
27 #include "ffrt.h"
28 
29 namespace OHOS {
30 namespace Notification {
31 
32 struct DeviceStatus {
DeviceStatusDeviceStatus33     DeviceStatus(std::string type, std::string id) : deviceType(type), deviceId(id) {}
34     std::string deviceType;
35     std::string deviceId;
36     uint32_t status = 0;
37     int32_t userId = 0;
38 };
39 
40 class DistributedDeviceStatus : public DelayedSingleton<DistributedDeviceStatus> {
41 public:
42     DistributedDeviceStatus();
43     ~DistributedDeviceStatus();
44     ErrCode SetDeviceStatus(const std::string &deviceType, const uint32_t status,
45         const uint32_t controlFlag);
46     ErrCode SetDeviceStatus(const std::string &deviceType, const uint32_t status,
47         const uint32_t controlFlag, const std::string deviceId, int32_t userId);
48 
49     uint32_t GetDeviceStatus(const std::string &deviceType);
50 
51     DeviceStatus GetMultiDeviceStatus(const std::string &deviceType, const uint32_t status);
52 
53 private:
54     ffrt::mutex mapLock_;
55     std::vector<DeviceStatus> deviceInfo_;
56     SafeMap<std::string, uint32_t> deviceStatus_;
57 
58 public:
59     static constexpr int32_t NETWORKID_FLAG = 16;
60     static constexpr int32_t USERID_FLAG = 4;
61     static constexpr int32_t STATUS_SIZE = 4;
62     static constexpr int32_t USING_FLAG = 0;
63     static constexpr int32_t LOCK_FLAG = 1;
64     static constexpr int32_t OWNER_FLAG = 2;
65     static constexpr int32_t DISTURB_MODE_FLAG = 3;
66     static constexpr int32_t DISTURB_DEFAULT_FLAG = 13;
67 };
68 }  // namespace Notification
69 }  // namespace OHOS
70 
71 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DISTRIBUTED_DEVICE_STATUS_H
72