blob: 9802b919bff4e1093310a31f560dab183c0cd7ae [file] [log] [blame]
JP Abgrall408fa572011-03-16 15:57:42 -07001/*
2 * Copyright (C) 2011 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#ifndef __TRANSPORT_H
18#define __TRANSPORT_H
19
Dan Alberte9fca142015-02-18 18:03:26 -080020#include <sys/types.h>
21
Dan Albert76649012015-02-24 15:51:19 -080022#include "adb.h"
23
Dan Albert630b9af2014-11-24 23:34:35 -080024#ifdef __cplusplus
25extern "C" {
26#endif
27
Dan Albert76649012015-02-24 15:51:19 -080028/*
29 * Convenience wrappers around read/write that will retry on
30 * EINTR and/or short read/write. Returns 0 on success, -1
31 * on error or EOF.
32 */
JP Abgrall408fa572011-03-16 15:57:42 -070033int readx(int fd, void *ptr, size_t len);
34int writex(int fd, const void *ptr, size_t len);
Dan Albert630b9af2014-11-24 23:34:35 -080035
Dan Albert76649012015-02-24 15:51:19 -080036/*
37 * Obtain a transport from the available transports.
38 * If state is != CS_ANY, only transports in that state are considered.
39 * If serial is non-NULL then only the device with that serial will be chosen.
40 * If no suitable transport is found, error is set.
41 */
42atransport* acquire_one_transport(int state, transport_type ttype,
43 const char* serial, char** error_out);
44void add_transport_disconnect(atransport* t, adisconnect* dis);
45void remove_transport_disconnect(atransport* t, adisconnect* dis);
46void kick_transport(atransport* t);
47void run_transport_disconnects(atransport* t);
48void update_transports(void);
49
50/* transports are ref-counted
51** get_device_transport does an acquire on your behalf before returning
52*/
53void init_transport_registration(void);
54int list_transports(char* buf, size_t bufsize, int long_listing);
55atransport* find_transport(const char* serial);
56
57void register_usb_transport(usb_handle* h, const char* serial,
58 const char* devpath, unsigned writeable);
59
60/* cause new transports to be init'd and added to the list */
61int register_socket_transport(int s, const char* serial, int port, int local);
62
63/* this should only be used for transports with connection_state == CS_NOPERM */
64void unregister_usb_transport(usb_handle* usb);
65
66/* these should only be used for the "adb disconnect" command */
67void unregister_transport(atransport* t);
68void unregister_all_tcp_transports();
69
70int check_header(apacket* p);
71int check_data(apacket* p);
72
73/* for MacOS X cleanup */
74void close_usb_devices();
75
76void send_packet(apacket* p, atransport* t);
77
78asocket* create_device_tracker(void);
79
Dan Albert630b9af2014-11-24 23:34:35 -080080#ifdef __cplusplus
81}
82#endif
83
JP Abgrall408fa572011-03-16 15:57:42 -070084#endif /* __TRANSPORT_H */