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 EVENT_STATISTIC_H 17 #define EVENT_STATISTIC_H 18 19 #include <fstream> 20 #include <queue> 21 #include <sys/stat.h> 22 #include <unistd.h> 23 24 #include "pointer_event.h" 25 26 namespace OHOS { 27 namespace MMI { 28 class EventStatistic final { 29 public: 30 static void PushEvent(std::shared_ptr<InputEvent> eventPtr); 31 static void PushPointerEvent(std::shared_ptr<PointerEvent> eventPtr); 32 static std::string PopEvent(); 33 static void WriteEventFile(); 34 static void Dump(int32_t fd, const std::vector<std::string> &args); 35 static std::string ConvertEventToStr(const std::shared_ptr<InputEvent> eventPtr); 36 static std::string ConvertTimeToStr(int64_t timestamp); 37 38 private: 39 static std::queue<std::string> eventQueue_; 40 static std::list<std::string> dumperEventList_; 41 static std::mutex queueMutex_; 42 static std::condition_variable queueCondition_; 43 static bool writeFileEnabled_; 44 }; 45 } // namespace MMI 46 } // namespace OHOS 47 #endif // EVENT_STATISTIC_H