From 3604756139b1a2dde383122745d37fe9d1c95f88 Mon Sep 17 00:00:00 2001
From: Martin Szulecki
Date: Mon, 5 Aug 2013 20:07:04 +0200
Subject: Implement *_start_service() helper to simplify creation of service
 clients

---
 src/afc.c                  | 20 ++++++++++++++++++++
 src/diagnostics_relay.c    | 20 ++++++++++++++++++++
 src/file_relay.c           | 20 ++++++++++++++++++++
 src/house_arrest.c         | 20 ++++++++++++++++++++
 src/installation_proxy.c   | 20 ++++++++++++++++++++
 src/misagent.c             | 20 ++++++++++++++++++++
 src/mobile_image_mounter.c | 20 ++++++++++++++++++++
 src/mobilebackup.c         | 20 ++++++++++++++++++++
 src/mobilebackup2.c        | 20 ++++++++++++++++++++
 src/mobilesync.c           | 20 ++++++++++++++++++++
 src/notification_proxy.c   | 20 ++++++++++++++++++++
 src/sbservices.c           | 20 ++++++++++++++++++++
 src/screenshotr.c          | 20 ++++++++++++++++++++
 13 files changed, 260 insertions(+)

(limited to 'src')

diff --git a/src/afc.c b/src/afc.c
index 7b4a396..a4cc17a 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -128,6 +128,26 @@ afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t serv
 	return err;
 }
 
+/**
+ * Starts a new AFC service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     afc_client_t upon successful return. Must be freed using
+ *     afc_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return AFC_E_SUCCESS on success, or an AFC_E_* error
+ *     code otherwise.
+ */
+afc_error_t afc_client_start_service(idevice_t device, afc_client_t * client, const char* label)
+{
+	afc_error_t err = AFC_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, AFC_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(afc_client_new), &err);
+	return err;
+}
+
 /**
  * Frees up an AFC client. If the connection was created by the
  * client itself, the connection will be closed.
diff --git a/src/diagnostics_relay.c b/src/diagnostics_relay.c
index 6069169..9786f0e 100644
--- a/src/diagnostics_relay.c
+++ b/src/diagnostics_relay.c
@@ -101,6 +101,26 @@ diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, lockdow
 	return DIAGNOSTICS_RELAY_E_SUCCESS;
 }
 
+/**
+ * Starts a new diagnostics_relay service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     diagnostics_relay_client_t upon successful return. Must be freed using
+ *     diagnostics_relay_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, or an DIAGNOSTICS_RELAY_E_* error
+ *     code otherwise.
+ */
+diagnostics_relay_error_t diagnostics_relay_client_start_service(idevice_t device, diagnostics_relay_client_t * client, const char* label)
+{
+	diagnostics_relay_error_t err = DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, DIAGNOSTICS_RELAY_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(diagnostics_relay_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects a diagnostics_relay client from the device and frees up the 
  * diagnostics_relay client data.
diff --git a/src/file_relay.c b/src/file_relay.c
index 2b45d70..eacaa11 100644
--- a/src/file_relay.c
+++ b/src/file_relay.c
@@ -56,6 +56,26 @@ file_relay_error_t file_relay_client_new(idevice_t device, lockdownd_service_des
 	return FILE_RELAY_E_SUCCESS;
 }
 
+/**
+ * Starts a new file_relay service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     file_relay_client_t upon successful return. Must be freed using
+ *     file_relay_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return FILE_RELAY_E_SUCCESS on success, or an FILE_RELAY_E_* error
+ *     code otherwise.
+ */
+file_relay_error_t file_relay_client_start_service(idevice_t device, file_relay_client_t * client, const char* label)
+{
+	file_relay_error_t err = FILE_RELAY_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, FILE_RELAY_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(file_relay_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects a file_relay client from the device and frees up the file_relay
  * client data.
diff --git a/src/house_arrest.c b/src/house_arrest.c
index 4eaf5e3..f4314e7 100644
--- a/src/house_arrest.c
+++ b/src/house_arrest.c
@@ -82,6 +82,26 @@ house_arrest_error_t house_arrest_client_new(idevice_t device, lockdownd_service
 	return HOUSE_ARREST_E_SUCCESS;
 }
 
+/**
+ * Starts a new house_arrest service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     house_arrest_client_t upon successful return. Must be freed using
+ *     house_arrest_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return HOUSE_ARREST_E_SUCCESS on success, or an HOUSE_ARREST_E_* error
+ *     code otherwise.
+ */
+house_arrest_error_t house_arrest_client_start_service(idevice_t device, house_arrest_client_t * client, const char* label)
+{
+	house_arrest_error_t err = HOUSE_ARREST_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, HOUSE_ARREST_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(house_arrest_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects an house_arrest client from the device and frees up the
  * house_arrest client data.
diff --git a/src/installation_proxy.c b/src/installation_proxy.c
index 6873f26..cffadd9 100644
--- a/src/installation_proxy.c
+++ b/src/installation_proxy.c
@@ -111,6 +111,26 @@ instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descr
 	return INSTPROXY_E_SUCCESS;
 }
 
+/**
+ * Starts a new installation_proxy service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     instproxy_client_t upon successful return. Must be freed using
+ *     instproxy_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return INSTPROXY_E_SUCCESS on success, or an INSTPROXY_E_* error
+ *     code otherwise.
+ */
+instproxy_error_t instproxy_client_start_service(idevice_t device, instproxy_client_t * client, const char* label)
+{
+	instproxy_error_t err = INSTPROXY_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, INSTPROXY_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(instproxy_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects an installation_proxy client from the device and frees up the
  * installation_proxy client data.
diff --git a/src/misagent.c b/src/misagent.c
index 331fc6c..750cf52 100644
--- a/src/misagent.c
+++ b/src/misagent.c
@@ -114,6 +114,26 @@ misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descrip
 	return MISAGENT_E_SUCCESS;
 }
 
+/**
+ * Starts a new misagent service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     misagent_client_t upon successful return. Must be freed using
+ *     misagent_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return MISAGENT_E_SUCCESS on success, or an MISAGENT_E_* error
+ *     code otherwise.
+ */
+misagent_error_t misagent_client_start_service(idevice_t device, misagent_client_t * client, const char* label)
+{
+	misagent_error_t err = MISAGENT_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, MISAGENT_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(misagent_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects an misagent client from the device and frees up the
  * misagent client data.
diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c
index f2e423a..bc439f9 100644
--- a/src/mobile_image_mounter.c
+++ b/src/mobile_image_mounter.c
@@ -105,6 +105,26 @@ mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdown
 	return MOBILE_IMAGE_MOUNTER_E_SUCCESS;
 }
 
+/**
+ * Starts a new mobile_image_mounter service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     mobile_image_mounter_t upon successful return. Must be freed using
+ *     mobile_image_mounter_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return MOBILE_IMAGE_MOUNTER_E_SUCCESS on success, or an MOBILE_IMAGE_MOUNTER_E_* error
+ *     code otherwise.
+ */
+mobile_image_mounter_error_t mobile_image_mounter_start_service(idevice_t device, mobile_image_mounter_client_t * client, const char* label)
+{
+	mobile_image_mounter_error_t err = MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, MOBILE_IMAGE_MOUNTER_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(mobile_image_mounter_new), &err);
+	return err;
+}
+
 /**
  * Disconnects a mobile_image_mounter client from the device and frees up the
  * mobile_image_mounter client data.
diff --git a/src/mobilebackup.c b/src/mobilebackup.c
index 6382b94..c53a2cb 100644
--- a/src/mobilebackup.c
+++ b/src/mobilebackup.c
@@ -99,6 +99,26 @@ mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service
 	return ret;
 }
 
+/**
+ * Starts a new mobilebackup service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     mobilebackup_client_t upon successful return. Must be freed using
+ *     mobilebackup_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return MOBILEBACKUP_E_SUCCESS on success, or an MOBILEBACKUP_E_* error
+ *     code otherwise.
+ */
+mobilebackup_error_t mobilebackup_client_start_service(idevice_t device, mobilebackup_client_t * client, const char* label)
+{
+	mobilebackup_error_t err = MOBILEBACKUP_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, MOBILEBACKUP_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(mobilebackup_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects a mobilebackup client from the device and frees up the
  * mobilebackup client data.
diff --git a/src/mobilebackup2.c b/src/mobilebackup2.c
index c1159e1..594ba84 100644
--- a/src/mobilebackup2.c
+++ b/src/mobilebackup2.c
@@ -101,6 +101,26 @@ mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_servi
 	return ret;
 }
 
+/**
+ * Starts a new mobilebackup2 service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     mobilebackup2_client_t upon successful return. Must be freed using
+ *     mobilebackup2_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return MOBILEBACKUP2_E_SUCCESS on success, or an MOBILEBACKUP2_E_* error
+ *     code otherwise.
+ */
+mobilebackup2_error_t mobilebackup2_client_start_service(idevice_t device, mobilebackup2_client_t * client, const char* label)
+{
+	mobilebackup2_error_t err = MOBILEBACKUP2_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, MOBILEBACKUP2_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(mobilebackup2_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects a mobilebackup2 client from the device and frees up the
  * mobilebackup2 client data.
diff --git a/src/mobilesync.c b/src/mobilesync.c
index 0e98709..e9e05ee 100644
--- a/src/mobilesync.c
+++ b/src/mobilesync.c
@@ -108,6 +108,26 @@ mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_des
 	return ret;
 }
 
+/**
+ * Starts a new mobilesync service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     mobilesync_client_t upon successful return. Must be freed using
+ *     mobilesync_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return MOBILESYNC_E_SUCCESS on success, or an MOBILESYNC_E_* error
+ *     code otherwise.
+ */
+mobilesync_error_t mobilesync_client_start_service(idevice_t device, mobilesync_client_t * client, const char* label)
+{
+	mobilesync_error_t err = MOBILESYNC_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, MOBILESYNC_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(mobilesync_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects a mobilesync client from the device and frees up the
  * mobilesync client data.
diff --git a/src/notification_proxy.c b/src/notification_proxy.c
index 410a519..88ff72b 100644
--- a/src/notification_proxy.c
+++ b/src/notification_proxy.c
@@ -116,6 +116,26 @@ np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t servic
 	return NP_E_SUCCESS;
 }
 
+/**
+ * Starts a new notification proxy service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     np_client_t upon successful return. Must be freed using
+ *     np_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return NP_E_SUCCESS on success, or an NP_E_* error
+ *     code otherwise.
+ */
+np_error_t np_client_start_service(idevice_t device, np_client_t* client, const char* label)
+{
+	np_error_t err = NP_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, NP_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(np_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects a notification_proxy client from the device and frees up the
  * notification_proxy client data.
diff --git a/src/sbservices.c b/src/sbservices.c
index dde8b9d..9b66c7f 100644
--- a/src/sbservices.c
+++ b/src/sbservices.c
@@ -103,6 +103,26 @@ sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_des
 	return SBSERVICES_E_SUCCESS;
 }
 
+/**
+ * Starts a new sbservices service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     sbservices_client_t upon successful return. Must be freed using
+ *     sbservices_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return SBSERVICES_E_SUCCESS on success, or an SBSERVICES_E_* error
+ *     code otherwise.
+ */
+sbservices_error_t sbservices_client_start_service(idevice_t device, sbservices_client_t * client, const char* label)
+{
+	sbservices_error_t err = SBSERVICES_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, SBSERVICES_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(sbservices_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects an sbservices client from the device and frees up the
  * sbservices client data.
diff --git a/src/screenshotr.c b/src/screenshotr.c
index 2e16032..5367450 100644
--- a/src/screenshotr.c
+++ b/src/screenshotr.c
@@ -101,6 +101,26 @@ screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_d
 	return ret;
 }
 
+/**
+ * Starts a new screenshotr service on the specified device and connects to it.
+ *
+ * @param device The device to connect to.
+ * @param client Pointer that will point to a newly allocated
+ *     screenshotr_client_t upon successful return. Must be freed using
+ *     screenshotr_client_free() after use.
+ * @param label The label to use for communication. Usually the program name.
+ *  Pass NULL to disable sending the label in requests to lockdownd.
+ *
+ * @return SCREENSHOTR_E_SUCCESS on success, or an SCREENSHOTR_E_* error
+ *     code otherwise.
+ */
+screenshotr_error_t screenshotr_client_start_service(idevice_t device, screenshotr_client_t * client, const char* label)
+{
+	screenshotr_error_t err = SCREENSHOTR_E_UNKNOWN_ERROR;
+	service_client_factory_start_service(device, SCREENSHOTR_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(screenshotr_client_new), &err);
+	return err;
+}
+
 /**
  * Disconnects a screenshotr client from the device and frees up the
  * screenshotr client data.
-- 
cgit v1.1-32-gdbae