summaryrefslogtreecommitdiffstats
path: root/src/mobilesync.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2010-05-15 15:51:22 +0200
committerGravatar Martin Szulecki2010-05-15 15:51:22 +0200
commitff8a02b0613d37d61ccc7564dbfcde7b2d912b7f (patch)
tree5d3d2d27fdf4331b0be69ffe8da7b37025b1a955 /src/mobilesync.c
parent6820b067e3f0282e38b7450f46c6fcb8167a573b (diff)
downloadlibimobiledevice-ff8a02b0613d37d61ccc7564dbfcde7b2d912b7f.tar.gz
libimobiledevice-ff8a02b0613d37d61ccc7564dbfcde7b2d912b7f.tar.bz2
Add documentation for mobilesync API
Diffstat (limited to 'src/mobilesync.c')
-rw-r--r--src/mobilesync.c151
1 files changed, 151 insertions, 0 deletions
diff --git a/src/mobilesync.c b/src/mobilesync.c
index f0a6a79..0d68c40 100644
--- a/src/mobilesync.c
+++ b/src/mobilesync.c
@@ -161,6 +161,24 @@ mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist_t plist)
161 return mobilesync_error(device_link_service_send(client->parent, plist)); 161 return mobilesync_error(device_link_service_send(client->parent, plist));
162} 162}
163 163
164/**
165 * Requests starting synchronization of a data class with the device
166 *
167 * @param client The mobilesync client
168 * @param data_class The data class identifier to sync
169 * @param anchors The anchors required to exchange with the device. The anchors
170 * allow the device to tell if the synchronization information on the computer
171 * and device are consistent to determine what sync type is required.
172 * @param computer_data_class_version The version of the data class storage on the computer
173 * @param sync_type A pointer to store the sync type reported by the device_anchor
174 * @param device_data_class_version The version of the data class storage on the device
175 *
176 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
177 * one of the parameters is invalid, MOBILESYNC_E_PLIST_ERROR if
178 * the received plist is not of valid form, MOBILESYNC_E_SYNC_REFUSED if the
179 * device refused to sync or MOBILESYNC_E_CANCELLED if the device explicitly
180 * cancelled the sync request
181 */
164mobilesync_error_t mobilesync_start(mobilesync_client_t client, const char *data_class, mobilesync_anchors_t anchors, uint64_t computer_data_class_version, mobilesync_sync_type_t *sync_type, uint64_t *device_data_class_version) 182mobilesync_error_t mobilesync_start(mobilesync_client_t client, const char *data_class, mobilesync_anchors_t anchors, uint64_t computer_data_class_version, mobilesync_sync_type_t *sync_type, uint64_t *device_data_class_version)
165{ 183{
166 if (!client || client->data_class || !data_class || 184 if (!client || client->data_class || !data_class ||
@@ -289,6 +307,16 @@ mobilesync_error_t mobilesync_start(mobilesync_client_t client, const char *data
289 return err; 307 return err;
290} 308}
291 309
310/**
311 * Finish a synchronization session of a data class on the device.
312 * A session must have previously been started using mobilesync_start().
313 *
314 * @param client The mobilesync client
315 *
316 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
317 * one of the parameters is invalid, MOBILESYNC_E_PLIST_ERROR if
318 * the received plist is not of valid form
319 */
292mobilesync_error_t mobilesync_finish(mobilesync_client_t client) 320mobilesync_error_t mobilesync_finish(mobilesync_client_t client)
293{ 321{
294 if (!client || !client->data_class) { 322 if (!client || !client->data_class) {
@@ -374,16 +402,48 @@ static mobilesync_error_t mobilesync_get_records(mobilesync_client_t client, con
374 return err; 402 return err;
375} 403}
376 404
405/**
406 * Requests to receive all records of the currently set data class from the device.
407 * The actually changes are retrieved using mobilesync_receive_changes() after this
408 * request has been successful.
409 *
410 * @param client The mobilesync client
411 *
412 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
413 * one of the parameters is invalid
414 */
377mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client) 415mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client)
378{ 416{
379 return mobilesync_get_records(client, "SDMessageGetAllRecordsFromDevice"); 417 return mobilesync_get_records(client, "SDMessageGetAllRecordsFromDevice");
380} 418}
381 419
420/**
421 * Requests to receive only changed records of the currently set data class from the device.
422 * The actually changes are retrieved using mobilesync_receive_changes() after this
423 * request has been successful.
424 *
425 * @param client The mobilesync client
426 *
427 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
428 * one of the parameters is invalid
429 */
382mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client) 430mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client)
383{ 431{
384 return mobilesync_get_records(client, "SDMessageGetChangesFromDevice"); 432 return mobilesync_get_records(client, "SDMessageGetChangesFromDevice");
385} 433}
386 434
435/**
436 * Receives changed entitites of the currently set data class from the device
437 *
438 * @param client The mobilesync client
439 * @param entities A pointer to store the changed entity records as a PLIST_DICT
440 * @param is_last_record A pointer to store a flag indiciating if this submission is the last one
441 * @param actions A pointer to additional flags the device is sending or NULL to ignore
442 *
443 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
444 * one of the parameters is invalid, MOBILESYNC_E_CANCELLED if the device
445 * explicitly cancelled the session
446 */
387mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_t *entities, uint8_t *is_last_record, plist_t *actions) 447mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_t *entities, uint8_t *is_last_record, plist_t *actions)
388{ 448{
389 if (!client || !client->data_class) { 449 if (!client || !client->data_class) {
@@ -451,6 +511,14 @@ mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_
451 return err; 511 return err;
452} 512}
453 513
514/**
515 * Acknowledges to the device that the changes have been merged on the computer
516 *
517 * @param client The mobilesync client
518 *
519 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
520 * one of the parameters is invalid
521 */
454mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client) 522mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client)
455{ 523{
456 if (!client || !client->data_class) { 524 if (!client || !client->data_class) {
@@ -480,6 +548,20 @@ static plist_t create_process_changes_message(const char *data_class, plist_t en
480 return msg; 548 return msg;
481} 549}
482 550
551/**
552 * Verifies if the device is ready to receive changes from the computer.
553 * This call changes the synchronization direction so that mobilesync_send_changes()
554 * can be used to send changes to the device.
555 *
556 * @param client The mobilesync client
557 *
558 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
559 * one of the parameters is invalid, MOBILESYNC_E_PLIST_ERROR if
560 * the received plist is not of valid form, MOBILESYNC_E_WRONG_DIRECTION if the
561 * current sync direction does not permit this call, MOBILESYNC_E_CANCELLED if
562 * the device explicitly cancelled the session or MOBILESYNC_E_NOT_READY if the
563 * device is not ready to start receiving any changes
564 */
483mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_client_t client) 565mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_client_t client)
484{ 566{
485 if (!client || !client->data_class) { 567 if (!client || !client->data_class) {
@@ -543,6 +625,18 @@ mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_cli
543 return err; 625 return err;
544} 626}
545 627
628/**
629 * Sends changed entitites of the currently set data class to the device
630 *
631 * @param client The mobilesync client
632 * @param entities The changed entity records as a PLIST_DICT
633 * @param is_last_record A flag indiciating if this submission is the last one
634 * @param actions Additional flags for the device created with mobilesync_actions_new()
635 *
636 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
637 * one of the parameters is invalid, MOBILESYNC_E_WRONG_DIRECTION if the
638 * current sync direction does not permit this call
639 */
546mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist_t entities, uint8_t is_last_record, plist_t actions) 640mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist_t entities, uint8_t is_last_record, plist_t actions)
547{ 641{
548 if (!client || !client->data_class || !entities) { 642 if (!client || !client->data_class || !entities) {
@@ -571,6 +665,18 @@ mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist_t e
571 return err; 665 return err;
572} 666}
573 667
668/**
669 * Receives any remapped identifiers reported after the device merged submitted changes.
670 *
671 * @param client The mobilesync client
672 * @param mapping A pointer to an array plist containing a dict of identifier remappings
673 *
674 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
675 * one of the parameters is invalid, MOBILESYNC_E_PLIST_ERROR if
676 * the received plist is not of valid form, MOBILESYNC_E_WRONG_DIRECTION if the
677 * current sync direction does not permit this call or MOBILESYNC_E_CANCELLED if
678 * the device explicitly cancelled the session
679 */
574mobilesync_error_t mobilesync_remap_identifiers(mobilesync_client_t client, plist_t *mapping) 680mobilesync_error_t mobilesync_remap_identifiers(mobilesync_client_t client, plist_t *mapping)
575{ 681{
576 if (!client || !client->data_class) { 682 if (!client || !client->data_class) {
@@ -640,6 +746,15 @@ mobilesync_error_t mobilesync_remap_identifiers(mobilesync_client_t client, plis
640 return err; 746 return err;
641} 747}
642 748
749/**
750 * Cancells a running synchronization session with a device at any time.
751 *
752 * @param client The mobilesync client
753 * @param reason The reason to supply to the device for cancelling
754 *
755 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
756 * one of the parameters is invalid
757 */
643mobilesync_error_t mobilesync_cancel(mobilesync_client_t client, const char* reason) 758mobilesync_error_t mobilesync_cancel(mobilesync_client_t client, const char* reason)
644{ 759{
645 if (!client || !client->data_class || !reason) { 760 if (!client || !client->data_class || !reason) {
@@ -666,6 +781,15 @@ mobilesync_error_t mobilesync_cancel(mobilesync_client_t client, const char* rea
666 return err; 781 return err;
667} 782}
668 783
784/**
785 * Allocates memory for a new anchors struct initialized with the passed anchors.
786 *
787 * @param device_anchor An anchor the device reported the last time or NULL
788 * if none is known yet which for instance is true on first synchronization.
789 * @param computer_anchor An arbitrary string to use as anchor for the computer.
790 *
791 * @return A new mobilesync_anchors_t struct. Must be freed using mobilesync_anchors_free().
792 */
669mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const char *computer_anchor) 793mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const char *computer_anchor)
670{ 794{
671 mobilesync_anchors_t anchors = (mobilesync_anchors_t) malloc(sizeof(mobilesync_anchors)); 795 mobilesync_anchors_t anchors = (mobilesync_anchors_t) malloc(sizeof(mobilesync_anchors));
@@ -683,6 +807,11 @@ mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const cha
683 return anchors; 807 return anchors;
684} 808}
685 809
810/**
811 * Free memory used by anchors.
812 *
813 * @param anchors The anchors free.
814 */
686void mobilesync_anchors_free(mobilesync_anchors_t anchors) 815void mobilesync_anchors_free(mobilesync_anchors_t anchors)
687{ 816{
688 if (anchors->device_anchor != NULL) { 817 if (anchors->device_anchor != NULL) {
@@ -697,11 +826,28 @@ void mobilesync_anchors_free(mobilesync_anchors_t anchors)
697 anchors = NULL; 826 anchors = NULL;
698} 827}
699 828
829/**
830 * Create a new actions plist to use in mobilesync_send_changes().
831 *
832 * @return A new plist_t of type PLIST_DICT.
833 */
700plist_t mobilesync_actions_new() 834plist_t mobilesync_actions_new()
701{ 835{
702 return plist_new_dict(); 836 return plist_new_dict();
703} 837}
704 838
839/**
840 * Add one or more new key:value pairs to the given actions plist.
841 *
842 * @param actions The actions to modify.
843 * @param ... KEY, VALUE, [KEY, VALUE], NULL
844 *
845 * @note The known keys so far are "SyncDeviceLinkEntityNamesKey" which expects
846 * an array of entity names, followed by a count paramter as well as
847 * "SyncDeviceLinkAllRecordsOfPulledEntityTypeSentKey" which expects an
848 * integer to use as a boolean value indiciating that the device should
849 * link submitted changes and report remapped identifiers.
850 */
705void mobilesync_actions_add(plist_t actions, ...) 851void mobilesync_actions_add(plist_t actions, ...)
706{ 852{
707 if (!actions) 853 if (!actions)
@@ -734,6 +880,11 @@ void mobilesync_actions_add(plist_t actions, ...)
734 va_end(args); 880 va_end(args);
735} 881}
736 882
883/**
884 * Free actions plist.
885 *
886 * @param actions The actions plist to free. Does nothing if NULL is passed.
887 */
737void mobilesync_actions_free(plist_t actions) 888void mobilesync_actions_free(plist_t actions)
738{ 889{
739 if (actions) { 890 if (actions) {