summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2010-12-18 18:32:39 +0100
committerGravatar Martin Szulecki2010-12-19 21:23:46 +0100
commit948e2a8a85dc5082279a6b3e1c586f2ce7622716 (patch)
tree9e187c41c2c7ded8a2e34376bfb2089f559829f0 /src
parent379c4f558a6baf0bb250b8e7900c22ea243577f5 (diff)
downloadsbmanager-948e2a8a85dc5082279a6b3e1c586f2ce7622716.tar.gz
sbmanager-948e2a8a85dc5082279a6b3e1c586f2ce7622716.tar.bz2
Add device_connect() to remove duplicated device connection code
Diffstat (limited to 'src')
-rw-r--r--src/device.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/device.c b/src/device.c
index 11aecc3..2d3b3c5 100644
--- a/src/device.c
+++ b/src/device.c
@@ -47,6 +47,28 @@ void device_init()
device_domain = g_quark_from_string("libimobiledevice");
}
+static gboolean device_connect(const char *uuid, idevice_t *phone, lockdownd_client_t *client, GError **error) {
+ gboolean res = FALSE;
+
+ if (!client || !phone) {
+ return res;
+ }
+
+ if (IDEVICE_E_SUCCESS != idevice_new(phone, uuid)) {
+ *error = g_error_new(device_domain, ENODEV, _("No device found, is it plugged in?"));
+ return res;
+ }
+
+ if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(*phone, client, "sbmanager")) {
+ *error = g_error_new(device_domain, EIO, _("Could not connect to lockdownd!"));
+ return res;
+ }
+
+ res = TRUE;
+
+ return res;
+}
+
sbservices_client_t device_sbs_new(const char *uuid, uint32_t *osversion, GError **error)
{
sbservices_client_t sbc = NULL;
@@ -57,16 +79,7 @@ sbservices_client_t device_sbs_new(const char *uuid, uint32_t *osversion, GError
printf("%s: %s\n", __func__, uuid);
g_mutex_lock(idevice_mutex);
- if (IDEVICE_E_SUCCESS != idevice_new(&phone, uuid)) {
- if (error)
- *error = g_error_new(device_domain, ENODEV, _("No device found, is it plugged in?"));
- g_mutex_unlock(idevice_mutex);
- return sbc;
- }
-
- if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "sbmanager")) {
- if (error)
- *error = g_error_new(device_domain, EIO, _("Could not connect to lockdownd!"));
+ if (!device_connect(uuid, &phone, &client, error)) {
goto leave_cleanup;
}
@@ -281,13 +294,7 @@ gboolean device_get_info(const char *uuid, device_info_t *device_info, GError **
printf("%s\n", __func__);
g_mutex_lock(idevice_mutex);
- if (IDEVICE_E_SUCCESS != idevice_new(&phone, uuid)) {
- *error = g_error_new(device_domain, ENODEV, _("No device found, is it plugged in?"));
- goto leave_cleanup;
- }
-
- if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "sbmanager")) {
- *error = g_error_new(device_domain, EIO, _("Could not connect to lockdownd!"));
+ if (!device_connect(uuid, &phone, &client, error)) {
goto leave_cleanup;
}