libiphone 1.0 API cleanup
Reported by Martin S. | May 23rd, 2009 @ 12:00 PM | in 1.0 Release
As the usbmuxd integration is moving forward greatly I'd like to add this bug to remind of doing a final API cleanup of libiphone for the 1.0 release after we ripped things apart.
Overall
I'd propose to follow what we discussed in the architecture talks (See Figure 3) and cleanup the namespaces per device service as the iphone_* prefix is not really required (just look at the libiphone.h and notice the "grouping" of functions).
We should introduce headers purely for one service and keep this scheme for new yet unimplemented services.
This means "iphone_afc_*" becomes pure "afc_*" and one needs to use "libiphone/afc.h". "iphone_lckd_*" for instance becomes "lockdownd_*" and one uses "libiphone/lockdownd.h".
Lockdownd
Lockdownd has a defined request interface (like a webservice) which we should expose in the API, although that can happen past 1.0 as simple API additions. However it might be feasable to already adjust the GetValue requests to fit more into such an interface (generic_get_value stuff).
lockdownd API (request method to call for value of Request node)
is:
QueryType
StartSession
StopSession
StartService
Pair
Unpair
ValidatePair
Activate
Deactivate
GetValue
SetValue
RemoveValue
EnterRecovery
Goodbye
AFC
After talking with Nikias, as he was adding new symlink functionality for OS 3.0, it became evident that some refactoring should take place here.
Primarily things like get_file_attr() do not reflect the AFC protocol and are rather further abstraction/helper functionality on top of it. The AFC API should reflect the protocol (like get_file_info() should actually be exposed and it is enough to return a uint64_t as file handle, ...). This also gives more benefits like better portability (no struct stat) and focusing on the real protocol. Everything else is a matter of the implementation using AFC like the file attribute "conversion" which should take place on the consumer side of the API. Patches for this in the works.
NotificationProxy
As talked about with Nikias, the public API should only expose a callback way to grab notifications which makes the whole thing more elegant. Internally, a pull thread is still required and might be changed to an event based data retrieval in the future (as with libusb 1.0+).
MobileSync
We should remove the get_all_contacts test method until a correct interface is worked out from the ongoing synchronization research (like python-iphonesync). The remaining connect/send/recv looks ready.
Final
Thus libiphone becomes a package of higher level service client API implementations to use programatically or through a set of exposed tools (iphone_id, iphoneinfo, iphonesyslog, ...).
That should be the last change, allow us to keep a stable API and finally a 1.0 could be released.
Feedback welcome as the more people "think" through this, the better the API becomes.
Comments and changes to this ticket
-
Nikias Bassen May 24th, 2009 @ 10:21 PM
That all sounds reasonable, however I'd like to know what in your opinion is not good with the NotificationProxy interface, perhaps we can improve it.
I designed it to be as simple as possible ;) -
Martin S. June 30th, 2009 @ 03:35 PM
@nikias: As talked about, only exposing a callback way to grab notifications seems more elegant.
For lockdownd_ we might as well go straight with the request type of API:
lockdownd_client_t lockdownd_new_client(iphone_device_t phone); iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t
plist) iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) iphone_error_t lockdownd_free_client(lockdownd_client_t client) iphone_error_t lockdownd_query_type(lockdownd_client_t client) iphone_error_t lockdownd_get_value(lockdownd_client_t client, char domain, char key, plist_t value) iphone_error_t lockdownd_set_value(lockdownd_client_t client, char domain, char key, plist_t value) iphone_error_t lockdownd_remove_value(lockdownd_client_t client, char domain, char key) iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client) iphone_error_t lockdownd_goodbye(lockdownd_client_t client) iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char service, int port) iphone_error_t lockdownd_start_session(lockdownd_client_t client, char *session_id) iphone_error_t lockdownd_stop_session(lockdownd_client_t client, char session_id)
iphone_error_t lockdownd_pair(lockdownd_client_t client, char device_id, char host_id) iphone_error_t lockdownd_unpair(lockdownd_client_t client, char device_id, char host_id) iphone_error_t lockdownd_validate_pair(lockdownd_client_t client, char device_id, char host_id) ? TBD iphone_error_t lockdownd_activate() ? TBD iphone_error_t lockdownd_deactivate()
Convenience: iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t client, char uid) iphone_error_t lockdownd_get_device_name(iphone_lckd_client_t client, char device_name)
I'll see to cook some patches once everything else is pushed to Matt's repo. -
Nikias Bassen July 6th, 2009 @ 05:57 PM
- State changed from new to open
Here are two patches for AFC and NotificationProxy that make them API 1.0 compatible. As stated above by Martin a little rework of AFC was needed; I did that already, see ticket #55.
All patches attached have to be applied after applying the patches from Ticket #55
As the name says, 0004-iFuse-adaption-to-AFC-API-change.patch is to make iFuse work with the new API.
-
Nikias Bassen July 6th, 2009 @ 09:33 PM
The iFuse patch is not working for some strange reason; here it is again.
-
Matt Colyer July 7th, 2009 @ 03:37 PM
These are pretty large changes, do they look good to everyone else before I apply them?
-
Jonathan Beck July 7th, 2009 @ 05:27 PM
Shouldn't we keep libiphone/libiphone.h a meta-headers thats includes all protocols (and move error definitions to libiphone/errors.h) ?
Other than that those patches are ok to me.
-
Martin S. July 7th, 2009 @ 07:25 PM
Yes, all fine and working.
I've rewrote/cleaned up the lockdown API as explained above, too.
Some changes:
- rename functions to further stick to the request protocol
- move common request result checking code into helper (thanks Nikias)
- update tools and iFuse to use the new API
- expose the lockdown API within own header
- fix doc comments
- fix some compiler warnings
Please apply to libiphone and iFuse after the patches from Nikias.
-
Martin S. July 7th, 2009 @ 08:19 PM
Reposted patches for above comment due to issues with lighthouse. Patches for mobilesync coming...
-
Martin S. July 10th, 2009 @ 05:09 PM
Further patch for libiphone to make use of the new plist_copy() function and remove the workaround/hack.
-
Martin S. July 14th, 2009 @ 12:54 PM
Below the last patch to cleanup the MobileSync API, too.
Changes:
- Update API, expose it with own header and update SWIG bindings accordingly
- Do not expose get_all_contacts(), move it into msyncclient for now (it was rather a testing function)
Last bits that need work/discussion:
- Error codes: Like the individual service API's it appears we have also error codes from different domains (usbmux, iphone_device, lockdownd, afc, ...). Those should be moved and maintained within the individual service header instead. This is of particular interest for the AFC API since we could handle errors more elegantly for the consumer (now there is this errno conversion hack and unspecific IPHONE_E_AFC_ERROR). There might be better programming patterns for error handling, feedback welcome.
- libiphone.h: This might better be called "device.h" as it basically manages the device struct. What might be missing is a function to get all connected uuid's so consumers (like iphone_id for instance) would not have to use/know usbmuxd.h and simply go ahead with what's provided by libiphone.
- *_new_client(): Do the constructors really require a dst_port parameter? How about if they do the lockdownd_start_service() on their own and return errors/success instead of the consumer having to handle starting the service?
- @Jonathan: "keep libiphone/libiphone.h a meta-headers ... move error definitions to libiphone/errors.h", once the API is cleaned up, we might as well put everything in one header like before. However, considering the architecture talks/model, individual headers have their benefits in the longterm.
- I would propose moving "distributable/working/useful" tools (iphone_id, iphoneinfo, iphonesyslog, ...) into libiphone/tools/, make them installed by default and keep testing tools in libiphone/dev strictly as "noinst_*".
Once things get pushed to Matt's repo we'll be really close to 1.0 I guess and I'll focus on two-way mobilesync... :)
-
Martin S. July 15th, 2009 @ 02:19 PM
Further consecutive attached patch adds the following lockdownd request protocol API functions:
- lockdownd_set_value(): Sets values or full preference plists
- lockdownd_remove_value(): Removes values or preference node trees from the device
- lockdownd_enter_recovery(): Makes the device enter recovery mode (with the iTunes cable plug displayed)
-
Matt Colyer July 18th, 2009 @ 05:41 PM
- State changed from open to resolved
(from [0be7debdc3b08e07b7f8bc2e32fed6aed587e09d]) Implement lockdown set_value, remove_value and enter_recovery request API
[#46 state:resolved]
Signed-off-by: Matt Colyer matt@colyer.name
http://github.com/MattColyer/libiphone/commit/0be7debdc3b08e07b7f8b... -
Martin S. July 19th, 2009 @ 01:32 PM
- State changed from resolved to open
Sorry, have to reopen as some stuff is not quite right yet.
Patches below address:
- iphoneinfo now uses less code due to lockdownd_get_value()
- The mobilesync API update was missing a header
I'll also supply last patches to divide the tools into distributed and noinst_* ones and to fix the error system.
Also as Jonathan noted, the plist dependency must be bumped to at least 0.13.
Then the API should be fresh and clean (and possible to keep it like that past 1.0+). :) -
Nikias Bassen July 19th, 2009 @ 06:12 PM
Here's another patch for AFC for afc_lock_file. As only non-blocking locks are supported, I defined a type afc_lock_op_t with all allowed lock operations.
-
Nikias Bassen July 19th, 2009 @ 06:14 PM
- no changes were found...
-
teuf July 24th, 2009 @ 07:11 PM
Not sure at all this belongs here, but libiphone git with these patches applied misses a prototype for iphone_get_uuid in libiphone.h (either that, or this function isn't needed and can be removed). Sorry for the noise if this is not the right ticket to mention this issue.
-
Martin S. July 24th, 2009 @ 09:00 PM
@teuf: Right bug for this. :)
However I am preparing a huge changeset (172kb), currently splitting it into small commits. Got your issue handled there and exposing it as iphone_device_get_uuid().
-
Martin S. July 25th, 2009 @ 01:51 AM
As noted before I splitted out the error code definitions among services now.
Services return an error type in their own domain now, e.g.: mobilesync_error_tDue to looking into the errors I was also able to fix the AFC error code chain.
Now iFuse should be able to report more accurate AFC errors aswell.I also updated all affected tools/consumers and improved error reporting overall.
See the following posts for details.
-
Martin S. July 25th, 2009 @ 01:54 AM
libiphone changes:
- Update README structure, URLs and made requirements less Ubuntu specific
- Add missing copyright info to headers
- Add --debug option to afccheck
- Add new NP_ITDBPREP_DID_END notification signaling music db refresh
- Rename iphone_set_debug() to iphone_set_debug_level() and update code using it
- Add missing macro preventing cyclic includes in notification proxy header
- Remove DBGMASK_USBMUX as it is obsolete since the libusbmuxd code merge
- Improve debug output messages by using func everywhere and adjust wording
- Use iphone_device_get_uuid() instead of lockdown_get_device_uuid() for less overhead where possible
- Define remaining unknown AFC operations; SUCCESS is actually a DATA operation
- Fix build Python bindings due to signature change of iphone_device_get_uuid()
- Fix includes of utils
- Improve API of userpref system
- Update MobileSync API and introduce mobilesync error codes
- Update NotificationProxy API and introduce new error codes
- Update lockdown API and introduce new error codes
- Follow glib style and rename iphone_free_device to iphone_device_free
- Rename iphone_get_device_handle to iphone_device_get_handle and update tools
- Update AFC API and use error codes from the STATUS operation response
- Remove AFC to errno conversion and make afc_receive_data() return AFC errors
- Implement afc_file_tell() and adjust afc_receive_data() to handle it
teuf's patch is skipped as this was already implemented.
-
Martin S. July 25th, 2009 @ 01:55 AM
iFuse changes:
- Improve error message text when connecting to lockdown fails
- Add --debug command line option
- Update code to compile with latest libiphone error API changes
- Add a mapping from AFC error codes to errno and return errno codes where possible
-
Martin S. July 25th, 2009 @ 01:59 AM
Please test/review/commit. That should be the last API change for a 1.0. :)
All changes (incl. Nikias's afc lock code) are also pushed into the "martin" branch, if you prefer to pull, from here:
http://cgit.sukimashita.com/libiphone.git/ -
Matt Colyer July 27th, 2009 @ 02:35 AM
- State changed from open to resolved
(from [eea538c94f01f8054f69f059614f19400187a472]) Merge commit 'martin-s/martin'
[#46 state:resolved] http://github.com/MattColyer/libiphone/commit/eea538c94f01f8054f69f...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
A project around supporting the iPhone in Linux.
See http://libimobiledevice.org
People watching this ticket
Attachments
Referenced by
- 46 libiphone 1.0 API cleanup [#46 state:resolved]
- 46 libiphone 1.0 API cleanup [#46 state:resolved] http://github.com/MattColyer/libiph...