summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/SBServices.c63
1 files changed, 45 insertions, 18 deletions
diff --git a/src/SBServices.c b/src/SBServices.c
index 9589ec2..18f9fb6 100644
--- a/src/SBServices.c
+++ b/src/SBServices.c
@@ -49,6 +49,32 @@ static void sbs_unlock(sbservices_client_t client)
49 g_mutex_unlock(client->mutex); 49 g_mutex_unlock(client->mutex);
50} 50}
51 51
52/**
53 * Convert a property_list_service_error_t value to a sbservices_error_t value.
54 * Used internally to get correct error codes.
55 *
56 * @param err A property_list_service_error_t error code
57 *
58 * @return A matching sbservices_error_t error code,
59 * SBSERVICES_E_UNKNOWN_ERROR otherwise.
60 */
61static sbservices_error_t sbservices_error(property_list_service_error_t err)
62{
63 switch (err) {
64 case PROPERTY_LIST_SERVICE_E_SUCCESS:
65 return SBSERVICES_E_SUCCESS;
66 case PROPERTY_LIST_SERVICE_E_INVALID_ARG:
67 return SBSERVICES_E_INVALID_ARG;
68 case PROPERTY_LIST_SERVICE_E_PLIST_ERROR:
69 return SBSERVICES_E_PLIST_ERROR;
70 case PROPERTY_LIST_SERVICE_E_MUX_ERROR:
71 return SBSERVICES_E_CONN_FAILED;
72 default:
73 break;
74 }
75 return SBSERVICES_E_UNKNOWN_ERROR;
76}
77
52sbservices_error_t sbservices_client_new(iphone_device_t device, int dst_port, sbservices_client_t *client) 78sbservices_error_t sbservices_client_new(iphone_device_t device, int dst_port, sbservices_client_t *client)
53{ 79{
54 /* makes sure thread environment is available */ 80 /* makes sure thread environment is available */
@@ -59,8 +85,9 @@ sbservices_error_t sbservices_client_new(iphone_device_t device, int dst_port, s
59 return SBSERVICES_E_INVALID_ARG; 85 return SBSERVICES_E_INVALID_ARG;
60 86
61 property_list_service_client_t plistclient = NULL; 87 property_list_service_client_t plistclient = NULL;
62 if (property_list_service_client_new(device, dst_port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 88 sbservices_error_t err = sbservices_error(property_list_service_client_new(device, dst_port, &plistclient));
63 return SBSERVICES_E_CONN_FAILED; 89 if (err != SBSERVICES_E_SUCCESS) {
90 return err;
64 } 91 }
65 92
66 sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_int)); 93 sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_int));
@@ -76,14 +103,14 @@ sbservices_error_t sbservices_client_free(sbservices_client_t client)
76 if (!client) 103 if (!client)
77 return SBSERVICES_E_INVALID_ARG; 104 return SBSERVICES_E_INVALID_ARG;
78 105
79 property_list_service_client_free(client->parent); 106 sbservices_error_t err = sbservices_error(property_list_service_client_free(client->parent));
80 client->parent = NULL; 107 client->parent = NULL;
81 if (client->mutex) { 108 if (client->mutex) {
82 g_mutex_free(client->mutex); 109 g_mutex_free(client->mutex);
83 } 110 }
84 free(client); 111 free(client);
85 112
86 return SBSERVICES_E_SUCCESS; 113 return err;
87} 114}
88 115
89sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist_t *state) 116sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist_t *state)
@@ -98,17 +125,17 @@ sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist_t
98 125
99 sbs_lock(client); 126 sbs_lock(client);
100 127
101 if (property_list_service_send_binary_plist(client->parent, dict) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 128 res = sbservices_error(property_list_service_send_binary_plist(client->parent, dict));
102 debug_info("could not send plist"); 129 if (res != SBSERVICES_E_SUCCESS) {
130 debug_info("could not send plist, error %d", res);
103 goto leave_unlock; 131 goto leave_unlock;
104 } 132 }
105 plist_free(dict); 133 plist_free(dict);
106 dict = NULL; 134 dict = NULL;
107 135
108 if (property_list_service_receive_plist(client->parent, state) == PROPERTY_LIST_SERVICE_E_SUCCESS) { 136 res = sbservices_error(property_list_service_receive_plist(client->parent, state));
109 res = SBSERVICES_E_SUCCESS; 137 if (res != SBSERVICES_E_SUCCESS) {
110 } else { 138 debug_info("could not get icon state, error %d", res);
111 debug_info("could not get icon state!");
112 if (*state) { 139 if (*state) {
113 plist_free(*state); 140 plist_free(*state);
114 *state = NULL; 141 *state = NULL;
@@ -136,13 +163,12 @@ sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist_t
136 163
137 sbs_lock(client); 164 sbs_lock(client);
138 165
139 if (property_list_service_send_binary_plist(client->parent, dict) != IPHONE_E_SUCCESS) { 166 res = sbservices_error(property_list_service_send_binary_plist(client->parent, dict));
140 debug_info("could not send plist"); 167 if (res != SBSERVICES_E_SUCCESS) {
141 goto leave_unlock; 168 debug_info("could not send plist, error %d", res);
142 } 169 }
143 // NO RESPONSE 170 // NO RESPONSE
144 171
145leave_unlock:
146 if (dict) { 172 if (dict) {
147 plist_free(dict); 173 plist_free(dict);
148 } 174 }
@@ -163,19 +189,20 @@ sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, const
163 189
164 sbs_lock(client); 190 sbs_lock(client);
165 191
166 if (property_list_service_send_binary_plist(client->parent, dict) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 192 res = sbservices_error(property_list_service_send_binary_plist(client->parent, dict));
167 debug_info("could not send plist"); 193 if (res != SBSERVICES_E_SUCCESS) {
194 debug_info("could not send plist, error %d", res);
168 goto leave_unlock; 195 goto leave_unlock;
169 } 196 }
170 plist_free(dict); 197 plist_free(dict);
171 198
172 dict = NULL; 199 dict = NULL;
173 if (property_list_service_receive_plist(client->parent, &dict) == PROPERTY_LIST_SERVICE_E_SUCCESS) { 200 res = sbservices_error(property_list_service_receive_plist(client->parent, &dict));
201 if (res == SBSERVICES_E_SUCCESS) {
174 plist_t node = plist_dict_get_item(dict, "pngData"); 202 plist_t node = plist_dict_get_item(dict, "pngData");
175 if (node) { 203 if (node) {
176 plist_get_data_val(node, pngdata, pngsize); 204 plist_get_data_val(node, pngdata, pngsize);
177 } 205 }
178 res = SBSERVICES_E_SUCCESS;
179 } 206 }
180 207
181leave_unlock: 208leave_unlock: