• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "osal_time.h"
10 #include "hdf_log.h"
11 #include "event_hub.h"
12 
13 #define SEC_TO_USEC    1000000
14 
SendFramePackages(InputDevice * inputDev)15 static void SendFramePackages(InputDevice *inputDev)
16 {
17     struct HdfDeviceObject *hdfDev = inputDev->hdfDevObj;
18     if (hdfDev == NULL || inputDev->pkgBuf == NULL) {
19         HDF_LOGE("%s: hdf dev is null", __func__);
20         return;
21     }
22     HdfDeviceSendEvent(hdfDev, 0, inputDev->pkgBuf);
23 }
24 
PushOnePackage(InputDevice * inputDev,uint32_t type,uint32_t code,int32_t value)25 void PushOnePackage(InputDevice *inputDev, uint32_t type, uint32_t code, int32_t value)
26 {
27     OsalTimespec time;
28     EventPackage package = {0};
29     InputManager *inputManager = GetInputManager();
30 
31     if (inputDev == NULL) {
32         HDF_LOGE("%s: parm is null", __func__);
33         return;
34     }
35     OsalMutexLock(&inputManager->mutex);
36     package.type = type;
37     package.code = code;
38     package.value = value;
39     OsalGetTime(&time);
40     package.time = time.sec * SEC_TO_USEC + time.usec;
41 
42     if (!HdfSbufWriteBuffer(inputDev->pkgBuf, &package, sizeof(EventPackage))) {
43         HDF_LOGE("%s: sbuf write pkg failed, clear sbuf", __func__);
44         HdfSbufFlush(inputDev->pkgBuf);
45         inputDev->errFrameFlag = true;
46     }
47     inputDev->pkgCount++;
48 
49     if (inputDev->pkgCount >= inputDev->pkgNum) {
50         HDF_LOGE("%s: current pkgs num beyond the sbuf limit", __func__);
51         inputDev->errFrameFlag = true;
52     }
53 
54     if (type == EV_SYN && code == SYN_REPORT) {
55         if (!HdfSbufWriteBuffer(inputDev->pkgBuf, NULL, 0)) {
56             HDF_LOGE("%s: sbuf write null pkg failed, clear sbuf", __func__);
57             HdfSbufFlush(inputDev->pkgBuf);
58             inputDev->errFrameFlag = true;
59         }
60 
61         if (!inputDev->errFrameFlag) {
62             SendFramePackages(inputDev);
63         }
64 
65         inputDev->pkgCount = 0;
66         HdfSbufFlush(inputDev->pkgBuf);
67         inputDev->errFrameFlag = false;
68     }
69     OsalMutexUnlock(&inputManager->mutex);
70 }