Skip to content

Commit

Permalink
Convert int16_t macro error types into enum to improve debugging/type…
Browse files Browse the repository at this point in the history
…-checking

This simple change provides various benefits for developers like compile
time errors, better auto-completition in editors and the ability of a
debugger to show the constant instead of just the raw value.
Thanks to Aaron Burghardt for the proposal.
  • Loading branch information
FunkyM committed Oct 5, 2014
1 parent 5552fa0 commit 5072dea
Show file tree
Hide file tree
Showing 27 changed files with 267 additions and 343 deletions.
67 changes: 32 additions & 35 deletions include/libimobiledevice/afc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,38 @@ extern "C" {

#define AFC_SERVICE_NAME "com.apple.afc"

/** @name Error Codes */
/*@{*/
#define AFC_E_SUCCESS 0
#define AFC_E_UNKNOWN_ERROR 1
#define AFC_E_OP_HEADER_INVALID 2
#define AFC_E_NO_RESOURCES 3
#define AFC_E_READ_ERROR 4
#define AFC_E_WRITE_ERROR 5
#define AFC_E_UNKNOWN_PACKET_TYPE 6
#define AFC_E_INVALID_ARG 7
#define AFC_E_OBJECT_NOT_FOUND 8
#define AFC_E_OBJECT_IS_DIR 9
#define AFC_E_PERM_DENIED 10
#define AFC_E_SERVICE_NOT_CONNECTED 11
#define AFC_E_OP_TIMEOUT 12
#define AFC_E_TOO_MUCH_DATA 13
#define AFC_E_END_OF_DATA 14
#define AFC_E_OP_NOT_SUPPORTED 15
#define AFC_E_OBJECT_EXISTS 16
#define AFC_E_OBJECT_BUSY 17
#define AFC_E_NO_SPACE_LEFT 18
#define AFC_E_OP_WOULD_BLOCK 19
#define AFC_E_IO_ERROR 20
#define AFC_E_OP_INTERRUPTED 21
#define AFC_E_OP_IN_PROGRESS 22
#define AFC_E_INTERNAL_ERROR 23

#define AFC_E_MUX_ERROR 30
#define AFC_E_NO_MEM 31
#define AFC_E_NOT_ENOUGH_DATA 32
#define AFC_E_DIR_NOT_EMPTY 33
/*@}*/

/** Represents an error code. */
typedef int16_t afc_error_t;
/** Error Codes */
typedef enum {
AFC_E_SUCCESS = 0,
AFC_E_UNKNOWN_ERROR = 1,
AFC_E_OP_HEADER_INVALID = 2,
AFC_E_NO_RESOURCES = 3,
AFC_E_READ_ERROR = 4,
AFC_E_WRITE_ERROR = 5,
AFC_E_UNKNOWN_PACKET_TYPE = 6,
AFC_E_INVALID_ARG = 7,
AFC_E_OBJECT_NOT_FOUND = 8,
AFC_E_OBJECT_IS_DIR = 9,
AFC_E_PERM_DENIED = 10,
AFC_E_SERVICE_NOT_CONNECTED = 11,
AFC_E_OP_TIMEOUT = 12,
AFC_E_TOO_MUCH_DATA = 13,
AFC_E_END_OF_DATA = 14,
AFC_E_OP_NOT_SUPPORTED = 15,
AFC_E_OBJECT_EXISTS = 16,
AFC_E_OBJECT_BUSY = 17,
AFC_E_NO_SPACE_LEFT = 18,
AFC_E_OP_WOULD_BLOCK = 19,
AFC_E_IO_ERROR = 20,
AFC_E_OP_INTERRUPTED = 21,
AFC_E_OP_IN_PROGRESS = 22,
AFC_E_INTERNAL_ERROR = 23,
AFC_E_MUX_ERROR = 30,
AFC_E_NO_MEM = 31,
AFC_E_NOT_ENOUGH_DATA = 32,
AFC_E_DIR_NOT_EMPTY = 33,
AFC_E_FORCE_SIGNED_TYPE = -1
} afc_error_t;

/** Flags for afc_file_open */
typedef enum {
Expand Down
21 changes: 9 additions & 12 deletions include/libimobiledevice/debugserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ extern "C" {

#define DEBUGSERVER_SERVICE_NAME "com.apple.debugserver"

/** @name Error Codes */
/*@{*/
#define DEBUGSERVER_E_SUCCESS 0
#define DEBUGSERVER_E_INVALID_ARG -1
#define DEBUGSERVER_E_MUX_ERROR -2
#define DEBUGSERVER_E_SSL_ERROR -3
#define DEBUGSERVER_E_RESPONSE_ERROR -4
#define DEBUGSERVER_E_UNKNOWN_ERROR -256
/*@}*/

/** Represents an error code. */
typedef int16_t debugserver_error_t;
/** Error Codes */
typedef enum {
DEBUGSERVER_E_SUCCESS = 0,
DEBUGSERVER_E_INVALID_ARG = -1,
DEBUGSERVER_E_MUX_ERROR = -2,
DEBUGSERVER_E_SSL_ERROR = -3,
DEBUGSERVER_E_RESPONSE_ERROR = -4,
DEBUGSERVER_E_UNKNOWN_ERROR = -256
} debugserver_error_t;

typedef struct debugserver_client_private debugserver_client_private;
typedef debugserver_client_private *debugserver_client_t; /**< The client handle. */
Expand Down
22 changes: 9 additions & 13 deletions include/libimobiledevice/diagnostics_relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ extern "C" {

#define DIAGNOSTICS_RELAY_SERVICE_NAME "com.apple.mobile.diagnostics_relay"

/** @name Error Codes */
/*@{*/
#define DIAGNOSTICS_RELAY_E_SUCCESS 0
#define DIAGNOSTICS_RELAY_E_INVALID_ARG -1
#define DIAGNOSTICS_RELAY_E_PLIST_ERROR -2
#define DIAGNOSTICS_RELAY_E_MUX_ERROR -3
#define DIAGNOSTICS_RELAY_E_UNKNOWN_REQUEST -4

#define DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR -256
/*@}*/
/** Error Codes */
typedef enum {
DIAGNOSTICS_RELAY_E_SUCCESS = 0,
DIAGNOSTICS_RELAY_E_INVALID_ARG = -1,
DIAGNOSTICS_RELAY_E_PLIST_ERROR = -2,
DIAGNOSTICS_RELAY_E_MUX_ERROR = -3,
DIAGNOSTICS_RELAY_E_UNKNOWN_REQUEST = -4,
DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR = -256
} diagnostics_relay_error_t;

#define DIAGNOSTICS_RELAY_ACTION_FLAG_WAIT_FOR_DISCONNECT (1 << 1)
#define DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_PASS (1 << 2)
Expand All @@ -52,9 +51,6 @@ extern "C" {
#define DIAGNOSTICS_RELAY_REQUEST_TYPE_GAS_GAUGE "GasGauge"
#define DIAGNOSTICS_RELAY_REQUEST_TYPE_NAND "NAND"

/** Represents an error code. */
typedef int16_t diagnostics_relay_error_t;

typedef struct diagnostics_relay_client_private diagnostics_relay_client_private;
typedef diagnostics_relay_client_private *diagnostics_relay_client_t; /**< The client handle. */

Expand Down
26 changes: 11 additions & 15 deletions include/libimobiledevice/file_relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,17 @@ extern "C" {

#define FILE_RELAY_SERVICE_NAME "com.apple.mobile.file_relay"

/** @name Error Codes */
/*@{*/
#define FILE_RELAY_E_SUCCESS 0
#define FILE_RELAY_E_INVALID_ARG -1
#define FILE_RELAY_E_PLIST_ERROR -2
#define FILE_RELAY_E_MUX_ERROR -3
#define FILE_RELAY_E_INVALID_SOURCE -4
#define FILE_RELAY_E_STAGING_EMPTY -5
#define FILE_RELAY_E_PERMISSION_DENIED -6

#define FILE_RELAY_E_UNKNOWN_ERROR -256
/*@}*/

/** Represents an error code. */
typedef int16_t file_relay_error_t;
/** Error Codes */
typedef enum {
FILE_RELAY_E_SUCCESS = 0,
FILE_RELAY_E_INVALID_ARG = -1,
FILE_RELAY_E_PLIST_ERROR = -2,
FILE_RELAY_E_MUX_ERROR = -3,
FILE_RELAY_E_INVALID_SOURCE = -4,
FILE_RELAY_E_STAGING_EMPTY = -5,
FILE_RELAY_E_PERMISSION_DENIED = -6,
FILE_RELAY_E_UNKNOWN_ERROR = -256
} file_relay_error_t;

typedef struct file_relay_client_private file_relay_client_private;
typedef file_relay_client_private *file_relay_client_t; /**< The client handle. */
Expand Down
21 changes: 9 additions & 12 deletions include/libimobiledevice/heartbeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ extern "C" {

#define HEARTBEAT_SERVICE_NAME "com.apple.mobile.heartbeat"

/** @name Error Codes */
/*@{*/
#define HEARTBEAT_E_SUCCESS 0
#define HEARTBEAT_E_INVALID_ARG -1
#define HEARTBEAT_E_PLIST_ERROR -2
#define HEARTBEAT_E_MUX_ERROR -3
#define HEARTBEAT_E_SSL_ERROR -4
#define HEARTBEAT_E_UNKNOWN_ERROR -256
/*@}*/

/** Represents an error code. */
typedef int16_t heartbeat_error_t;
/** Error Codes */
typedef enum {
HEARTBEAT_E_SUCCESS = 0,
HEARTBEAT_E_INVALID_ARG = -1,
HEARTBEAT_E_PLIST_ERROR = -2,
HEARTBEAT_E_MUX_ERROR = -3,
HEARTBEAT_E_SSL_ERROR = -4,
HEARTBEAT_E_UNKNOWN_ERROR = -256
} heartbeat_error_t;

typedef struct heartbeat_client_private heartbeat_client_private;
typedef heartbeat_client_private *heartbeat_client_t; /**< The client handle. */
Expand Down
22 changes: 9 additions & 13 deletions include/libimobiledevice/house_arrest.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@ extern "C" {

#define HOUSE_ARREST_SERVICE_NAME "com.apple.mobile.house_arrest"

/** @name Error Codes */
/*@{*/
#define HOUSE_ARREST_E_SUCCESS 0
#define HOUSE_ARREST_E_INVALID_ARG -1
#define HOUSE_ARREST_E_PLIST_ERROR -2
#define HOUSE_ARREST_E_CONN_FAILED -3
#define HOUSE_ARREST_E_INVALID_MODE -4

#define HOUSE_ARREST_E_UNKNOWN_ERROR -256
/*@}*/

/** Represents an error code. */
typedef int16_t house_arrest_error_t;
/** Error Codes */
typedef enum {
HOUSE_ARREST_E_SUCCESS = 0,
HOUSE_ARREST_E_INVALID_ARG = -1,
HOUSE_ARREST_E_PLIST_ERROR = -2,
HOUSE_ARREST_E_CONN_FAILED = -3,
HOUSE_ARREST_E_INVALID_MODE = -4,
HOUSE_ARREST_E_UNKNOWN_ERROR = -256
} house_arrest_error_t;

typedef struct house_arrest_client_private house_arrest_client_private;
typedef house_arrest_client_private *house_arrest_client_t; /**< The client handle. */
Expand Down
26 changes: 11 additions & 15 deletions include/libimobiledevice/installation_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,17 @@ extern "C" {

#define INSTPROXY_SERVICE_NAME "com.apple.mobile.installation_proxy"

/** @name Error Codes */
/*@{*/
#define INSTPROXY_E_SUCCESS 0
#define INSTPROXY_E_INVALID_ARG -1
#define INSTPROXY_E_PLIST_ERROR -2
#define INSTPROXY_E_CONN_FAILED -3
#define INSTPROXY_E_OP_IN_PROGRESS -4
#define INSTPROXY_E_OP_FAILED -5
#define INSTPROXY_E_RECEIVE_TIMEOUT -6

#define INSTPROXY_E_UNKNOWN_ERROR -256
/*@}*/

/** Represents an error code. */
typedef int16_t instproxy_error_t;
/** Error Codes */
typedef enum {
INSTPROXY_E_SUCCESS = 0,
INSTPROXY_E_INVALID_ARG = -1,
INSTPROXY_E_PLIST_ERROR = -2,
INSTPROXY_E_CONN_FAILED = -3,
INSTPROXY_E_OP_IN_PROGRESS = -4,
INSTPROXY_E_OP_FAILED = -5,
INSTPROXY_E_RECEIVE_TIMEOUT = -6,
INSTPROXY_E_UNKNOWN_ERROR = -256
} instproxy_error_t;

typedef struct instproxy_client_private instproxy_client_private;
typedef instproxy_client_private *instproxy_client_t; /**< The client handle. */
Expand Down
23 changes: 10 additions & 13 deletions include/libimobiledevice/libimobiledevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,16 @@ extern "C" {
#include <sys/stat.h>
#include <plist/plist.h>

/** @name Error Codes */
/*@{*/
#define IDEVICE_E_SUCCESS 0
#define IDEVICE_E_INVALID_ARG -1
#define IDEVICE_E_UNKNOWN_ERROR -2
#define IDEVICE_E_NO_DEVICE -3
#define IDEVICE_E_NOT_ENOUGH_DATA -4
#define IDEVICE_E_BAD_HEADER -5
#define IDEVICE_E_SSL_ERROR -6
/*@}*/

/** Represents an error code. */
typedef int16_t idevice_error_t;
/** Error Codes */
typedef enum {
IDEVICE_E_SUCCESS = 0,
IDEVICE_E_INVALID_ARG = -1,
IDEVICE_E_UNKNOWN_ERROR = -2,
IDEVICE_E_NO_DEVICE = -3,
IDEVICE_E_NOT_ENOUGH_DATA = -4,
IDEVICE_E_BAD_HEADER = -5,
IDEVICE_E_SSL_ERROR = -6
} idevice_error_t;

typedef struct idevice_private idevice_private;
typedef idevice_private *idevice_t; /**< The device handle. */
Expand Down
54 changes: 25 additions & 29 deletions include/libimobiledevice/lockdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,31 @@ extern "C" {
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>

/** @name Error Codes */
/*@{*/
#define LOCKDOWN_E_SUCCESS 0
#define LOCKDOWN_E_INVALID_ARG -1
#define LOCKDOWN_E_INVALID_CONF -2
#define LOCKDOWN_E_PLIST_ERROR -3
#define LOCKDOWN_E_PAIRING_FAILED -4
#define LOCKDOWN_E_SSL_ERROR -5
#define LOCKDOWN_E_DICT_ERROR -6
#define LOCKDOWN_E_START_SERVICE_FAILED -7
#define LOCKDOWN_E_NOT_ENOUGH_DATA -8
#define LOCKDOWN_E_SET_VALUE_PROHIBITED -9
#define LOCKDOWN_E_GET_VALUE_PROHIBITED -10
#define LOCKDOWN_E_REMOVE_VALUE_PROHIBITED -11
#define LOCKDOWN_E_MUX_ERROR -12
#define LOCKDOWN_E_ACTIVATION_FAILED -13
#define LOCKDOWN_E_PASSWORD_PROTECTED -14
#define LOCKDOWN_E_NO_RUNNING_SESSION -15
#define LOCKDOWN_E_INVALID_HOST_ID -16
#define LOCKDOWN_E_INVALID_SERVICE -17
#define LOCKDOWN_E_INVALID_ACTIVATION_RECORD -18
#define LOCKDOWN_E_PAIRING_DIALOG_PENDING -20
#define LOCKDOWN_E_USER_DENIED_PAIRING -21

#define LOCKDOWN_E_UNKNOWN_ERROR -256
/*@}*/

/** Represents an error code. */
typedef int16_t lockdownd_error_t;
/** Error Codes */
typedef enum {
LOCKDOWN_E_SUCCESS = 0,
LOCKDOWN_E_INVALID_ARG = -1,
LOCKDOWN_E_INVALID_CONF = -2,
LOCKDOWN_E_PLIST_ERROR = -3,
LOCKDOWN_E_PAIRING_FAILED = -4,
LOCKDOWN_E_SSL_ERROR = -5,
LOCKDOWN_E_DICT_ERROR = -6,
LOCKDOWN_E_START_SERVICE_FAILED = -7,
LOCKDOWN_E_NOT_ENOUGH_DATA = -8,
LOCKDOWN_E_SET_VALUE_PROHIBITED = -9,
LOCKDOWN_E_GET_VALUE_PROHIBITED = -10,
LOCKDOWN_E_REMOVE_VALUE_PROHIBITED = -11,
LOCKDOWN_E_MUX_ERROR = -12,
LOCKDOWN_E_ACTIVATION_FAILED = -13,
LOCKDOWN_E_PASSWORD_PROTECTED = -14,
LOCKDOWN_E_NO_RUNNING_SESSION = -15,
LOCKDOWN_E_INVALID_HOST_ID = -16,
LOCKDOWN_E_INVALID_SERVICE = -17,
LOCKDOWN_E_INVALID_ACTIVATION_RECORD = -18,
LOCKDOWN_E_PAIRING_DIALOG_PENDING = -20,
LOCKDOWN_E_USER_DENIED_PAIRING = -21,
LOCKDOWN_E_UNKNOWN_ERROR = -256
} lockdownd_error_t;

typedef struct lockdownd_client_private lockdownd_client_private;
typedef lockdownd_client_private *lockdownd_client_t; /**< The client handle. */
Expand Down
22 changes: 9 additions & 13 deletions include/libimobiledevice/misagent.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,15 @@ extern "C" {

#define MISAGENT_SERVICE_NAME "com.apple.misagent"

/** @name Error Codes */
/*@{*/
#define MISAGENT_E_SUCCESS 0
#define MISAGENT_E_INVALID_ARG -1
#define MISAGENT_E_PLIST_ERROR -2
#define MISAGENT_E_CONN_FAILED -3
#define MISAGENT_E_REQUEST_FAILED -4

#define MISAGENT_E_UNKNOWN_ERROR -256
/*@}*/

/** Represents an error code. */
typedef int16_t misagent_error_t;
/** Error Codes */
typedef enum {
MISAGENT_E_SUCCESS = 0,
MISAGENT_E_INVALID_ARG = -1,
MISAGENT_E_PLIST_ERROR = -2,
MISAGENT_E_CONN_FAILED = -3,
MISAGENT_E_REQUEST_FAILED = -4,
MISAGENT_E_UNKNOWN_ERROR = -256
} misagent_error_t;

typedef struct misagent_client_private misagent_client_private;
typedef misagent_client_private *misagent_client_t; /**< The client handle. */
Expand Down
Loading

0 comments on commit 5072dea

Please sign in to comment.