• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <memory>
18 
19 #include <jni.h>
20 
21 namespace android {
22 namespace uhid {
23 
24 class DeviceCallback {
25 public:
26     DeviceCallback(JNIEnv* env, jobject callback);
27     ~DeviceCallback();
28 
29     void onDeviceOpen();
30     void onDeviceError();
31 
32 private:
33     JNIEnv* getJNIEnv();
34     jobject mCallbackObject;
35     JavaVM* mJavaVM;
36 };
37 
38 class Device {
39 public:
40     static Device* open(int32_t id, const char* name, int32_t vid, int32_t pid,
41             std::unique_ptr<uint8_t[]> descriptor, size_t descriptorSize,
42             std::unique_ptr<DeviceCallback> callback);
43 
44     Device(int32_t id, int fd, std::unique_ptr<DeviceCallback> callback);
45     ~Device();
46 
47     void sendReport(uint8_t* report, size_t reportSize);
48     void close();
49 
50     int handleEvents(int events);
51 
52 private:
53     int32_t mId;
54     int mFd;
55     std::unique_ptr<DeviceCallback> mDeviceCallback;
56 };
57 
58 
59 } // namespace uhid
60 } // namespace android
61