• 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 #ifndef HIVIEWDFX_HIVIEW_UC_TELEMETRY_LISTENER_H
16 #define HIVIEWDFX_HIVIEW_UC_TELEMETRY_LISTENER_H
17 
18 #include <map>
19 
20 #include "event.h"
21 #include "plugin.h"
22 #include "trace_flow_controller.h"
23 #include "trace_state_machine.h"
24 
25 namespace OHOS::HiviewDFX {
26 struct StartMsg {
27     int64_t beginTime;
28     int64_t endTime;
29     std::string telemetryId;
30     std::string bundleName;
31 };
32 
33 class TelemetryListener : public EventListener {
34 public:
TelemetryListener(std::shared_ptr<Plugin> myPlugin)35     explicit TelemetryListener(std::shared_ptr<Plugin> myPlugin) : myPlugin_(myPlugin) {}
36     void OnUnorderedEvent(const Event &msg) override;
37 
GetListenerName()38     std::string GetListenerName() override
39     {
40         return "TelemetryListener";
41     }
42 
43 private:
44     std::string GetValidParam(const Event &msg, bool &isCloseMsg);
45     bool InitAndCorrectTimes(const Event &msg);
46     bool SendStartEvent(const Event &msg, int64_t traceDuration, int64_t delayTime = 0);
47     void SendStopEvent();
48     void WriteErrorEvent(const std::string &error);
49 
50 private:
51     std::weak_ptr<Plugin> myPlugin_;
52     std::string telemetryId_;
53     std::string bundleName_;
54     int64_t beginTime_ = -1;
55     int64_t endTime_ = -1;
56 };
57 
58 }
59 
60 #endif //HIVIEWDFX_HIVIEW_UC_TELEMETRY_LISTENER_H
61