• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024-2025 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 NOTIFICATION_DISTRIBUTED_EXTENSION_OPERATION_SERVICE_H
17 #define NOTIFICATION_DISTRIBUTED_EXTENSION_OPERATION_SERVICE_H
18 
19 #include "notifictaion_load_utils.h"
20 #include "ffrt.h"
21 #include "notification_config_parse.h"
22 #include "distributed_data_define.h"
23 #include "itimer_info.h"
24 #include "ians_operation_callback.h"
25 
26 #include <set>
27 #include <mutex>
28 #include <unordered_set>
29 
30 namespace OHOS {
31 namespace Notification {
32 
33 class OperationTimerInfo : public MiscServices::ITimerInfo {
34 public:
OperationTimerInfo(std::string timerHashCode)35     OperationTimerInfo(std::string timerHashCode) : timerHashCode_(timerHashCode) {};
~OperationTimerInfo()36     virtual ~OperationTimerInfo() {};
37 
38     /**
39      * When timing is up, this function will execute as call back.
40      */
41     void OnTrigger() override;
42 
43     /**
44      * Indicates the timing type.
45      */
SetType(const int32_t & type)46     void SetType(const int32_t &type) override {};
47 
48     /**
49      * Indicates the repeat policy.
50      */
SetRepeat(bool repeat)51     void SetRepeat(bool repeat) override {};
52 
53     /**
54      * Indicates the interval time for repeat timing.
55      */
SetInterval(const uint64_t & interval)56     void SetInterval(const uint64_t &interval) override {};
57 
58     /**
59      * Indicates the want agent information.
60      */
SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent)61     void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) override {};
62 
63 private:
64     std::string timerHashCode_;
65 };
66 
67 class DistributedOperationService {
68 public:
69     static DistributedOperationService& GetInstance();
70     void AddOperation(const std::string& hashCode,
71         const sptr<IAnsOperationCallback> &callback);
72     void ReplyOperationResponse(const std::string& hashCode, int32_t result);
73     void HandleOperationTimeOut(const std::string& hashCode);
74     void RemoveOperationResponse(const std::string& hashCode);
75 
76 private:
77     DistributedOperationService();
78     ~DistributedOperationService() = default;
79 
80 private:
81     ffrt::mutex mapLock_;
82     std::shared_ptr<ffrt::queue> operationQueue_ = nullptr;
83     std::map<std::string, uint64_t> timerMap_;
84     std::map<std::string, sptr<IAnsOperationCallback>> callbackMap_;
85 };
86 }
87 }
88 #endif // NOTIFICATION_DISTRIBUTED_EXTENSION_OPERATION_SERVICE_H
89