Skip to content

Commit

Permalink
Move USBMUXD_API to public headers
Browse files Browse the repository at this point in the history
  • Loading branch information
nikias committed Jan 29, 2024
1 parent 2d87841 commit 07cd6f7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 47 deletions.
10 changes: 5 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ AM_CONDITIONAL(WIN32, test x$win32 = xtrue)

AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -fvisibility=hidden $PTHREAD_CFLAGS")
GLOBAL_LDFLAGS="$PTHREAD_LIBS"

if test "x$enable_static" = "xyes" -a "x$enable_shared" = "xno"; then
GLOBAL_CFLAGS+=" -DLIBUSBMUXD_STATIC"
fi

AC_SUBST(GLOBAL_CFLAGS)
AC_SUBST(GLOBAL_LDFLAGS)

case "$GLOBAL_CFLAGS" in
*-fvisibility=hidden*)
AC_DEFINE([HAVE_FVISIBILITY], [1], [Define if compiled with -fvisibility=hidden])
esac

m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])

AC_CONFIG_FILES([
Expand Down
50 changes: 30 additions & 20 deletions include/usbmuxd.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
extern "C" {
#endif

#ifndef USBMUXD_API
#ifdef LIBUSBMUXD_STATIC
#define USBMUXD_API
#elif defined(_WIN32)
#define USBMUXD_API __declspec(dllimport)
#else
#define USBMUXD_API
#endif
#endif

/** Device lookup options for usbmuxd_get_device. */
enum usbmux_lookup_options {
DEVICE_LOOKUP_USBMUX = 1 << 1, /**< include USBMUX devices during lookup */
Expand Down Expand Up @@ -99,7 +109,7 @@ typedef struct usbmuxd_subscription_context* usbmuxd_subscription_context_t;
*
* @return 0 on success or a negative errno value.
*/
int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_event_cb_t callback, void *user_data);
USBMUXD_API int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_event_cb_t callback, void *user_data);

/**
* Unsubscribe callback function
Expand All @@ -108,7 +118,7 @@ int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_ev
*
* @return 0 on success or a negative errno value.
*/
int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context);
USBMUXD_API int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context);

/**
* Subscribe a callback (deprecated)
Expand All @@ -122,7 +132,7 @@ int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context);
* @note Deprecated. Use usbmuxd_events_subscribe and usbmuxd_events_unsubscribe instead.
* @see usbmuxd_events_subscribe
*/
int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data);
USBMUXD_API int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data);

/**
* Unsubscribe callback (deprecated)
Expand All @@ -132,7 +142,7 @@ int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data);
* @note Deprecated. Use usbmuxd_events_subscribe and usbmuxd_events_unsubscribe instead.
* @see usbmuxd_events_unsubscribe
*/
int usbmuxd_unsubscribe(void);
USBMUXD_API int usbmuxd_unsubscribe(void);

/**
* Contacts usbmuxd and retrieves a list of connected devices.
Expand All @@ -145,7 +155,7 @@ int usbmuxd_unsubscribe(void);
* @return number of attached devices, zero on no devices, or negative
* if an error occured.
*/
int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list);
USBMUXD_API int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list);

/**
* Frees the device list returned by an usbmuxd_get_device_list call
Expand All @@ -154,7 +164,7 @@ int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list);
*
* @return 0 on success, -1 on error.
*/
int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list);
USBMUXD_API int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list);

/**
* Looks up the device specified by UDID and returns device information.
Expand All @@ -172,7 +182,7 @@ int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list);
* @return 0 if no matching device is connected, 1 if the device was found,
* or a negative value on error.
*/
int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device);
USBMUXD_API int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device);

/**
* Looks up the device specified by UDID with given options and returns
Expand All @@ -197,7 +207,7 @@ int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device);
* @return 0 if no matching device is connected, 1 if the device was found,
* or a negative value on error.
*/
int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usbmux_lookup_options options);
USBMUXD_API int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usbmux_lookup_options options);

/**
* Request proxy connection to the specified device and port.
Expand All @@ -211,7 +221,7 @@ int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usb
* @return socket file descriptor of the connection, or a negative errno
* value on error.
*/
int usbmuxd_connect(const uint32_t handle, const unsigned short tcp_port);
USBMUXD_API int usbmuxd_connect(const uint32_t handle, const unsigned short tcp_port);

/**
* Disconnect. For now, this just closes the socket file descriptor.
Expand All @@ -220,7 +230,7 @@ int usbmuxd_connect(const uint32_t handle, const unsigned short tcp_port);
*
* @return 0 on success, -1 on error.
*/
int usbmuxd_disconnect(int sfd);
USBMUXD_API int usbmuxd_disconnect(int sfd);

/**
* Send data to the specified socket.
Expand All @@ -232,7 +242,7 @@ int usbmuxd_disconnect(int sfd);
*
* @return 0 on success, a negative errno value otherwise.
*/
int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes);
USBMUXD_API int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes);

/**
* Receive data from the specified socket.
Expand All @@ -245,7 +255,7 @@ int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes);
*
* @return 0 on success, a negative errno value otherwise.
*/
int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout);
USBMUXD_API int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout);

/**
* Receive data from the specified socket with a default timeout.
Expand All @@ -257,7 +267,7 @@ int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes
*
* @return 0 on success, a negative errno value otherwise.
*/
int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes);
USBMUXD_API int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes);

/**
* Reads the SystemBUID
Expand All @@ -267,7 +277,7 @@ int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes);
*
* @return 0 on success, a negative errno value otherwise.
*/
int usbmuxd_read_buid(char** buid);
USBMUXD_API int usbmuxd_read_buid(char** buid);

/**
* Read a pairing record
Expand All @@ -280,7 +290,7 @@ int usbmuxd_read_buid(char** buid);
*
* @return 0 on success, a negative error value otherwise.
*/
int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size);
USBMUXD_API int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size);

/**
* Save a pairing record
Expand All @@ -291,7 +301,7 @@ int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t
*
* @return 0 on success, a negative error value otherwise.
*/
int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size);
USBMUXD_API int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size);

/**
* Save a pairing record with device identifier
Expand All @@ -303,7 +313,7 @@ int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uin
*
* @return 0 on success, a negative error value otherwise.
*/
int usbmuxd_save_pair_record_with_device_id(const char* record_id, uint32_t device_id, const char *record_data, uint32_t record_size);
USBMUXD_API int usbmuxd_save_pair_record_with_device_id(const char* record_id, uint32_t device_id, const char *record_data, uint32_t record_size);

/**
* Delete a pairing record
Expand All @@ -312,17 +322,17 @@ int usbmuxd_save_pair_record_with_device_id(const char* record_id, uint32_t devi
*
* @return 0 on success, a negative errno value otherwise.
*/
int usbmuxd_delete_pair_record(const char* record_id);
USBMUXD_API int usbmuxd_delete_pair_record(const char* record_id);

/**
* Enable or disable the use of inotify extension. Enabled by default.
* Use 0 to disable and 1 to enable inotify support.
* This only has an effect on linux systems if inotify support has been built
* in. Otherwise and on all other platforms this function has no effect.
*/
void libusbmuxd_set_use_inotify(int set);
USBMUXD_API void libusbmuxd_set_use_inotify(int set);

void libusbmuxd_set_debug_level(int level);
USBMUXD_API void libusbmuxd_set_debug_level(int level);

#ifdef __cplusplus
}
Expand Down
46 changes: 24 additions & 22 deletions src/libusbmuxd.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
#include <stdio.h>
#include <string.h>

#ifdef WIN32
#ifdef LIBUSBMUXD_STATIC
#define USBMUXD_API
#elif defined(_WIN32)
#define USBMUXD_API __declspec( dllexport )
#else
#ifdef HAVE_FVISIBILITY
#if __GNUC__ >= 4
#define USBMUXD_API __attribute__((visibility("default")))
#else
#define USBMUXD_API
Expand Down Expand Up @@ -1154,7 +1156,7 @@ static void init_listeners(void)
mutex_init(&listener_mutex);
}

USBMUXD_API int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_event_cb_t callback, void *user_data)
int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_event_cb_t callback, void *user_data)
{
if (!context || !callback) {
return -EINVAL;
Expand Down Expand Up @@ -1198,7 +1200,7 @@ USBMUXD_API int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context
return 0;
}

USBMUXD_API int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context)
int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context)
{
int ret = 0;
int num = 0;
Expand Down Expand Up @@ -1245,7 +1247,7 @@ USBMUXD_API int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t contex
return ret;
}

USBMUXD_API int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data)
int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data)
{
if (!callback) {
return -EINVAL;
Expand All @@ -1258,14 +1260,14 @@ USBMUXD_API int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data)
return usbmuxd_events_subscribe(&event_ctx, callback, user_data);
}

USBMUXD_API int usbmuxd_unsubscribe(void)
int usbmuxd_unsubscribe(void)
{
int res = usbmuxd_events_unsubscribe(event_ctx);
event_ctx = NULL;
return res;
}

USBMUXD_API int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list)
int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list)
{
int sfd;
int tag;
Expand Down Expand Up @@ -1406,15 +1408,15 @@ USBMUXD_API int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list)
return dev_cnt;
}

USBMUXD_API int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list)
int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list)
{
if (device_list) {
free(*device_list);
}
return 0;
}

USBMUXD_API int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device)
int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device)
{
usbmuxd_device_info_t *dev_list = NULL;
usbmuxd_device_info_t *dev = NULL;
Expand Down Expand Up @@ -1457,7 +1459,7 @@ USBMUXD_API int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info
return result;
}

USBMUXD_API int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usbmux_lookup_options options)
int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usbmux_lookup_options options)
{
usbmuxd_device_info_t *dev_list = NULL;
usbmuxd_device_info_t *dev_network = NULL;
Expand Down Expand Up @@ -1522,7 +1524,7 @@ USBMUXD_API int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *devi
return result;
}

USBMUXD_API int usbmuxd_connect(const uint32_t handle, const unsigned short port)
int usbmuxd_connect(const uint32_t handle, const unsigned short port)
{
int sfd;
int tag;
Expand Down Expand Up @@ -1574,12 +1576,12 @@ USBMUXD_API int usbmuxd_connect(const uint32_t handle, const unsigned short port
return -result;
}

USBMUXD_API int usbmuxd_disconnect(int sfd)
int usbmuxd_disconnect(int sfd)
{
return socket_close(sfd);
}

USBMUXD_API int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes)
int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes)
{
int num_sent;

Expand All @@ -1604,7 +1606,7 @@ USBMUXD_API int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *
return 0;
}

USBMUXD_API int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout)
int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout)
{
int num_recv = socket_receive_timeout(sfd, (void*)data, len, 0, timeout);
if (num_recv < 0) {
Expand All @@ -1617,12 +1619,12 @@ USBMUXD_API int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t
return 0;
}

USBMUXD_API int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes)
int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes)
{
return usbmuxd_recv_timeout(sfd, data, len, recv_bytes, 5000);
}

USBMUXD_API int usbmuxd_read_buid(char **buid)
int usbmuxd_read_buid(char **buid)
{
int sfd;
int tag;
Expand Down Expand Up @@ -1663,7 +1665,7 @@ USBMUXD_API int usbmuxd_read_buid(char **buid)
return ret;
}

USBMUXD_API int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size)
int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size)
{
int sfd;
int tag;
Expand Down Expand Up @@ -1710,7 +1712,7 @@ USBMUXD_API int usbmuxd_read_pair_record(const char* record_id, char **record_da
return ret;
}

USBMUXD_API int usbmuxd_save_pair_record_with_device_id(const char* record_id, uint32_t device_id, const char *record_data, uint32_t record_size)
int usbmuxd_save_pair_record_with_device_id(const char* record_id, uint32_t device_id, const char *record_data, uint32_t record_size)
{
int sfd;
int tag;
Expand Down Expand Up @@ -1748,12 +1750,12 @@ USBMUXD_API int usbmuxd_save_pair_record_with_device_id(const char* record_id, u
return ret;
}

USBMUXD_API int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size)
int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size)
{
return usbmuxd_save_pair_record_with_device_id(record_id, 0, record_data, record_size);
}

USBMUXD_API int usbmuxd_delete_pair_record(const char* record_id)
int usbmuxd_delete_pair_record(const char* record_id)
{
int sfd;
int tag;
Expand Down Expand Up @@ -1789,14 +1791,14 @@ USBMUXD_API int usbmuxd_delete_pair_record(const char* record_id)
return ret;
}

USBMUXD_API void libusbmuxd_set_use_inotify(int set)
void libusbmuxd_set_use_inotify(int set)
{
#ifdef HAVE_INOTIFY
use_inotify = set;
#endif
}

USBMUXD_API void libusbmuxd_set_debug_level(int level)
void libusbmuxd_set_debug_level(int level)
{
libusbmuxd_debug = level;
socket_set_verbose(level);
Expand Down

0 comments on commit 07cd6f7

Please sign in to comment.