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 DISTRIBUTED_INPUT_TOUCHPAD_EVENT_FRAGMENT_MGR_H 17 #define DISTRIBUTED_INPUT_TOUCHPAD_EVENT_FRAGMENT_MGR_H 18 19 #include "touchpad_event_fragment.h" 20 21 #include <map> 22 #include <mutex> 23 #include <string> 24 #include <vector> 25 26 #include "constants_dinput.h" 27 28 namespace OHOS { 29 namespace DistributedHardware { 30 namespace DistributedInput { 31 class TouchPadEventFragmentMgr { 32 public: TouchPadEventFragmentMgr()33 TouchPadEventFragmentMgr() : fragments_({}) {} 34 35 /** 36 * @brief Push the touchpad event 37 * 38 * @param dhId the device dhId where event from 39 * @param event the event 40 * @return std::pair<bool, std::vector<RawEvent>> 41 * true for NOT whole touchpad event that need simulate back to the other device. 42 * false for DO Nothing. 43 */ 44 std::pair<bool, std::vector<RawEvent>> PushEvent(const std::string &dhId, const RawEvent &event); 45 void Clear(const std::string &dhId); 46 std::vector<RawEvent> GetAndClearEvents(const std::string &dhId); 47 48 private: 49 bool IsPositionEvent(const RawEvent &event); 50 bool IsSynEvent(const RawEvent &event); 51 bool IsWholeTouchFragments(const std::vector<TouchPadEventFragment> &fragments); 52 std::pair<bool, std::vector<RawEvent>> DealSynEvent(const std::string &dhId); 53 private: 54 std::mutex fragmentsMtx_; 55 // record the event fragments for the dhid. { dhId, { events }} 56 std::map<std::string, std::vector<TouchPadEventFragment>> fragments_; 57 }; 58 } // namespace DistributedInput 59 } // namespace DistributedHardware 60 } // namespace OHOS 61 #endif // DISTRIBUTED_INPUT_TOUCHPAD_EVENT_FRAGMENT_MGR_H