• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 NET_POLICY_FILE_EVENT_HANDLER_H
17 #define NET_POLICY_FILE_EVENT_HANDLER_H
18 
19 #include <iostream>
20 
21 #include "event_handler.h"
22 #include "event_runner.h"
23 #include "singleton.h"
24 
25 struct PolicyFileEvent {
26     std::string json;
27 };
28 
29 namespace OHOS {
30 namespace NetManagerStandard {
31 class NetPolicyFileEventHandler : public AppExecFwk::EventHandler {
32 public:
33     static constexpr uint32_t MSG_POLICY_FILE_WRITE = 2;
34     static constexpr uint32_t MSG_POLICY_FILE_DELETE = 3;
35     static constexpr uint32_t MSG_POLICY_FILE_COMMIT = 4;
36 
37     explicit NetPolicyFileEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner);
38     virtual ~NetPolicyFileEventHandler() = default;
39     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
40     void SendWriteEvent(AppExecFwk::InnerEvent::Pointer &event);
41 
42 private:
43     bool Write();
44     bool DeleteBak();
45 
46     std::atomic<int64_t> timeStamp_ = 0;
47     std::atomic<bool> commitWait_ = false;
48     std::string fileContent_;
49 };
50 } // namespace NetManagerStandard
51 } // namespace OHOS
52 #endif // NET_POLICY_EVENT_HANDLER_H