Home | History | Annotate | Download | only in daemon
      1 #pragma once
      2 
      3 /*
      4  * Copyright (C) 2017 The Android Open Source Project
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  */
     18 
     19 #include <atomic>
     20 #include <condition_variable>
     21 #include <mutex>
     22 
     23 #include <asyncio/AsyncIO.h>
     24 
     25 struct aio_block {
     26     std::vector<struct iocb> iocb;
     27     std::vector<struct iocb*> iocbs;
     28     std::vector<struct io_event> events;
     29     aio_context_t ctx;
     30     int num_submitted;
     31     int fd;
     32 };
     33 
     34 struct usb_handle {
     35     usb_handle() : kicked(false) {
     36     }
     37 
     38     std::condition_variable notify;
     39     std::mutex lock;
     40     std::atomic<bool> kicked;
     41     bool open_new_connection = true;
     42 
     43     int (*write)(usb_handle* h, const void* data, int len);
     44     int (*read)(usb_handle* h, void* data, int len);
     45     void (*kick)(usb_handle* h);
     46     void (*close)(usb_handle* h);
     47 
     48     // FunctionFS
     49     int control = -1;
     50     int bulk_out = -1; /* "out" from the host's perspective => source for adbd */
     51     int bulk_in = -1;  /* "in" from the host's perspective => sink for adbd */
     52 
     53     // Access to these blocks is very not thread safe. Have one block for both the
     54     // read and write threads.
     55     struct aio_block read_aiob;
     56     struct aio_block write_aiob;
     57 };
     58 
     59