summaryrefslogtreecommitdiffstats
path: root/src/device_link_service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/device_link_service.c')
-rw-r--r--src/device_link_service.c71
1 files changed, 69 insertions, 2 deletions
diff --git a/src/device_link_service.c b/src/device_link_service.c
index 10e9e9c..4140911 100644
--- a/src/device_link_service.c
+++ b/src/device_link_service.c
@@ -253,9 +253,20 @@ device_link_service_error_t device_link_service_disconnect(device_link_service_c
253 return err; 253 return err;
254} 254}
255 255
256/**
257 * Sends a DLMessageProcessMessage plist.
258 *
259 * @param client The device link service client to use.
260 * @param message PLIST_DICT to send.
261 *
262 * @return DEVICE_LINK_SERVICE_E_SUCCESS on success,
263 * DEVICE_LINK_SERVICE_E_INVALID_ARG if client or message is invalid or
264 * message is not a PLIST_DICT, or DEVICE_LINK_SERVICE_E_MUX_ERROR if
265 * the DLMessageProcessMessage plist could not be sent.
266 */
256device_link_service_error_t device_link_service_process_message(device_link_service_client_t client, plist_t message) 267device_link_service_error_t device_link_service_process_message(device_link_service_client_t client, plist_t message)
257{ 268{
258 if (!client || !message) 269 if (!client || !client->parent || !message)
259 return DEVICE_LINK_SERVICE_E_INVALID_ARG; 270 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
260 271
261 if (plist_get_node_type(message) != PLIST_DICT) 272 if (plist_get_node_type(message) != PLIST_DICT)
@@ -263,7 +274,7 @@ device_link_service_error_t device_link_service_process_message(device_link_serv
263 274
264 plist_t array = plist_new_array(); 275 plist_t array = plist_new_array();
265 plist_array_append_item(array, plist_new_string("DLMessageProcessMessage")); 276 plist_array_append_item(array, plist_new_string("DLMessageProcessMessage"));
266 plist_array_append_item(array, message); 277 plist_array_append_item(array, plist_copy(message));
267 278
268 device_link_service_error_t err = DEVICE_LINK_SERVICE_E_SUCCESS; 279 device_link_service_error_t err = DEVICE_LINK_SERVICE_E_SUCCESS;
269 if (property_list_service_send_binary_plist(client->parent, array) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 280 if (property_list_service_send_binary_plist(client->parent, array) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
@@ -274,6 +285,62 @@ device_link_service_error_t device_link_service_process_message(device_link_serv
274} 285}
275 286
276/** 287/**
288 * Receives a DLMessageProcessMessage plist.
289 *
290 * @param client The connected device link service client used for receiving.
291 * @param message Pointer to a plist that will be set to the contents of the
292 * message contents upon successful return.
293 *
294 * @return DEVICE_LINK_SERVICE_E_SUCCESS when a DLMessageProcessMessage was
295 * received, DEVICE_LINK_SERVICE_E_INVALID_ARG when client or message is
296 * invalid, DEVICE_LINK_SERVICE_E_PLIST_ERROR if the received plist is
297 * invalid or is not a DLMessageProcessMessage,
298 * or DEVICE_LINK_SERVICE_E_MUX_ERROR if receiving from device fails.
299 */
300device_link_service_error_t device_link_service_get_process_message(device_link_service_client_t client, plist_t *message)
301{
302 if (!client || !client->parent || !message)
303 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
304
305 plist_t pmsg = NULL;
306 if (property_list_service_receive_plist(client->parent, &pmsg) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
307 return DEVICE_LINK_SERVICE_E_MUX_ERROR;
308 }
309
310 device_link_service_error_t err = DEVICE_LINK_SERVICE_E_UNKNOWN_ERROR;
311
312 char *msg = device_link_service_get_message(pmsg);
313 if (!msg || strcmp(msg, "DLMessageProcessMessage")) {
314 debug_info("Did not receive DLMessageProcessMessage as expected!");
315 err = DEVICE_LINK_SERVICE_E_PLIST_ERROR;
316 goto leave;
317 }
318
319 if (plist_array_get_size(pmsg) != 2) {
320 debug_info("Malformed plist received for DLMessageProcessMessage");
321 err = DEVICE_LINK_SERVICE_E_PLIST_ERROR;
322 goto leave;
323 }
324
325 plist_t msg_loc = plist_array_get_item(pmsg, 1);
326 if (msg_loc) {
327 *message = plist_copy(msg_loc);
328 err = DEVICE_LINK_SERVICE_E_SUCCESS;
329 } else {
330 *message = NULL;
331 err = DEVICE_LINK_SERVICE_E_PLIST_ERROR;
332 }
333
334leave:
335 if (msg)
336 free(msg);
337 if (pmsg)
338 plist_free(pmsg);
339
340 return err;
341}
342
343/**
277 * Generic device link service send function. 344 * Generic device link service send function.
278 * 345 *
279 * @param client The device link service client to use for sending 346 * @param client The device link service client to use for sending