blob: 149456d8c10d2d0a54d4f977667a4635c25782f6 [file] [log] [blame]
Michael Wright1f2c7682015-06-03 13:46:48 +01001/*
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>
Michael Wright1f2c7682015-06-03 13:46:48 +010020
21namespace android {
22namespace uhid {
23
24class DeviceCallback {
25public:
26 DeviceCallback(JNIEnv* env, jobject callback);
27 ~DeviceCallback();
28
29 void onDeviceOpen();
30 void onDeviceError();
31
32private:
Siarhei Vishniakou55656e42017-03-31 17:23:39 -070033 JNIEnv* getJNIEnv();
Michael Wright1f2c7682015-06-03 13:46:48 +010034 jobject mCallbackObject;
Siarhei Vishniakou55656e42017-03-31 17:23:39 -070035 JavaVM* mJavaVM;
Michael Wright1f2c7682015-06-03 13:46:48 +010036};
37
38class Device {
39public:
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,
Siarhei Vishniakou55656e42017-03-31 17:23:39 -070042 std::unique_ptr<DeviceCallback> callback);
Michael Wright1f2c7682015-06-03 13:46:48 +010043
Siarhei Vishniakou55656e42017-03-31 17:23:39 -070044 Device(int32_t id, int fd, std::unique_ptr<DeviceCallback> callback);
Michael Wright1f2c7682015-06-03 13:46:48 +010045 ~Device();
46
47 void sendReport(uint8_t* report, size_t reportSize);
48 void close();
49
50 int handleEvents(int events);
51
52private:
53 int32_t mId;
54 int mFd;
55 std::unique_ptr<DeviceCallback> mDeviceCallback;
Michael Wright1f2c7682015-06-03 13:46:48 +010056};
57
58
59} // namespace uhid
60} // namespace android