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 OHOS_ROSEN_SCB_DUMP_SUBSCRIBER_H
17 #define OHOS_ROSEN_SCB_DUMP_SUBSCRIBER_H
18 
19 #include <chrono>
20 #include <condition_variable>
21 #include <want.h>
22 
23 #include <common_event_data.h>
24 #include <common_event_publish_info.h>
25 #include "common_event_manager.h"
26 #include "common/include/task_scheduler.h"
27 #include "interfaces/include/ws_common.h"
28 #include "interfaces/include/ws_common_inner.h"
29 
30 namespace OHOS::Rosen {
31 class ScbDumpSubscriber : public EventFwk::CommonEventSubscriber {
32 public:
ScbDumpSubscriber(const EventFwk::CommonEventSubscribeInfo & subscribeInfo)33     explicit ScbDumpSubscriber(const EventFwk::CommonEventSubscribeInfo& subscribeInfo)
34         : CommonEventSubscriber(subscribeInfo)
35     {}
36     ~ScbDumpSubscriber() = default;
37 
38     void OnReceiveEvent(const EventFwk::CommonEventData& data);
39 
40     WSError Publish(std::string cmd);
41 
42     std::string GetDebugDumpInfo(std::chrono::milliseconds const& time);
43 
44     static void Subscribe(std::shared_ptr<ScbDumpSubscriber>& scbSubscriber);
45 
46     static void UnSubscribe(std::shared_ptr<ScbDumpSubscriber>& scbSubscriber);
47 
48     static std::string JoinCommands(const std::vector<std::string>& params, int size);
49 
50 private:
51     std::string dumpinfo_ = "";
52     bool valueReady_ = false;
53     std::mutex mutex_;
54     std::condition_variable cv_;
55 };
56 } // namespace OHOS::Rosen
57 
58 #endif // OHOS_ROSEN_SCB_DUMP_SUBSCRIBER_H