11f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright/*
21f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright * Copyright (C) 2015 The Android Open Source Project
31f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright *
41f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright * Licensed under the Apache License, Version 2.0 (the "License");
51f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright * you may not use this file except in compliance with the License.
61f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright * You may obtain a copy of the License at
71f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright *
81f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright *      http://www.apache.org/licenses/LICENSE-2.0
91f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright *
101f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright * Unless required by applicable law or agreed to in writing, software
111f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright * distributed under the License is distributed on an "AS IS" BASIS,
121f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright * See the License for the specific language governing permissions and
141f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright * limitations under the License.
151f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright */
161f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
171f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright#include <memory>
181f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
191f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright#include <jni.h>
201f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright#include <utils/Looper.h>
211f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright#include <utils/StrongPointer.h>
221f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
231f2c7688c1f673790d61645632ae5e1838f021a4Michael Wrightnamespace android {
241f2c7688c1f673790d61645632ae5e1838f021a4Michael Wrightnamespace uhid {
251f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
261f2c7688c1f673790d61645632ae5e1838f021a4Michael Wrightclass DeviceCallback {
271f2c7688c1f673790d61645632ae5e1838f021a4Michael Wrightpublic:
281f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    DeviceCallback(JNIEnv* env, jobject callback);
291f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    ~DeviceCallback();
301f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
311f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    void onDeviceOpen();
321f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    void onDeviceError();
331f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
341f2c7688c1f673790d61645632ae5e1838f021a4Michael Wrightprivate:
351f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    jobject mCallbackObject;
361f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright};
371f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
381f2c7688c1f673790d61645632ae5e1838f021a4Michael Wrightclass Device {
391f2c7688c1f673790d61645632ae5e1838f021a4Michael Wrightpublic:
401f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    static Device* open(int32_t id, const char* name, int32_t vid, int32_t pid,
411f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright            std::unique_ptr<uint8_t[]> descriptor, size_t descriptorSize,
421f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright            std::unique_ptr<DeviceCallback> callback, sp<Looper> looper);
431f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
441f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    Device(int32_t id, int fd, std::unique_ptr<DeviceCallback> callback, sp<Looper> looper);
451f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    ~Device();
461f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
471f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    void sendReport(uint8_t* report, size_t reportSize);
481f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    void close();
491f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
501f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    int handleEvents(int events);
511f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
521f2c7688c1f673790d61645632ae5e1838f021a4Michael Wrightprivate:
531f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    int32_t mId;
541f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    int mFd;
551f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    std::unique_ptr<DeviceCallback> mDeviceCallback;
561f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright    sp<Looper> mLooper;
571f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright};
581f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
591f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright
601f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright} // namespace uhid
611f2c7688c1f673790d61645632ae5e1838f021a4Michael Wright} // namespace android
62