summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/afc.c18
-rw-r--r--src/afc.h8
-rw-r--r--src/installation_proxy.c34
-rw-r--r--src/installation_proxy.h9
-rw-r--r--src/mobile_image_mounter.c16
-rw-r--r--src/mobile_image_mounter.h8
-rw-r--r--src/notification_proxy.c36
-rw-r--r--src/notification_proxy.h9
-rw-r--r--src/sbservices.c16
-rw-r--r--src/sbservices.h8
10 files changed, 161 insertions, 1 deletions
diff --git a/src/afc.c b/src/afc.c
index 4d6293c..5ae9e38 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -42,7 +42,11 @@ static const int MAXIMUM_PACKET_SIZE = (2 << 15);
static void afc_lock(afc_client_t client)
{
debug_info("Locked");
+#ifdef WIN32
+ EnterCriticalSection(&client->mutex);
+#else
pthread_mutex_lock(&client->mutex);
+#endif
}
/**
@@ -53,7 +57,11 @@ static void afc_lock(afc_client_t client)
static void afc_unlock(afc_client_t client)
{
debug_info("Unlocked");
+#ifdef WIN32
+ LeaveCriticalSection(&client->mutex);
+#else
pthread_mutex_unlock(&client->mutex);
+#endif
}
/**
@@ -92,7 +100,11 @@ afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_
memcpy(client_loc->afc_packet->magic, AFC_MAGIC, AFC_MAGIC_LEN);
client_loc->file_handle = 0;
client_loc->lock = 0;
+#ifdef WIN32
+ InitializeCriticalSection(&client_loc->mutex);
+#else
pthread_mutex_init(&client_loc->mutex, NULL);
+#endif
*client = client_loc;
return AFC_E_SUCCESS;
@@ -150,7 +162,11 @@ afc_error_t afc_client_free(afc_client_t client)
client->connection = NULL;
}
free(client->afc_packet);
+#ifdef WIN32
+ DeleteCriticalSection(&client->mutex);
+#else
pthread_mutex_destroy(&client->mutex);
+#endif
free(client);
return AFC_E_SUCCESS;
}
@@ -402,7 +418,9 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint3
*bytes_recv = 0;
debug_info("WARNING: Unknown operation code received 0x%llx param1=%lld", header.operation, param1);
+#ifndef WIN32
fprintf(stderr, "%s: WARNING: Unknown operation code received 0x%llx param1=%lld", __func__, (long long)header.operation, (long long)param1);
+#endif
return AFC_E_OP_NOT_SUPPORTED;
}
diff --git a/src/afc.h b/src/afc.h
index c86828c..731746a 100644
--- a/src/afc.h
+++ b/src/afc.h
@@ -20,7 +20,11 @@
*/
#include <stdint.h>
+#ifdef WIN32
+#include <windows.h>
+#else
#include <pthread.h>
+#endif
#include "libimobiledevice/afc.h"
@@ -53,7 +57,11 @@ struct afc_client_private {
AFCPacket *afc_packet;
int file_handle;
int lock;
+#ifdef WIN32
+ CRITICAL_SECTION mutex;
+#else
pthread_mutex_t mutex;
+#endif
int own_connection;
};
diff --git a/src/installation_proxy.c b/src/installation_proxy.c
index e26a77d..a32fc50 100644
--- a/src/installation_proxy.c
+++ b/src/installation_proxy.c
@@ -43,7 +43,11 @@ struct instproxy_status_data {
static void instproxy_lock(instproxy_client_t client)
{
debug_info("InstallationProxy: Locked");
+#ifdef WIN32
+ EnterCriticalSection(&client->mutex);
+#else
pthread_mutex_lock(&client->mutex);
+#endif
}
/**
@@ -54,7 +58,11 @@ static void instproxy_lock(instproxy_client_t client)
static void instproxy_unlock(instproxy_client_t client)
{
debug_info("InstallationProxy: Unlocked");
+#ifdef WIN32
+ LeaveCriticalSection(&client->mutex);
+#else
pthread_mutex_unlock(&client->mutex);
+#endif
}
/**
@@ -106,8 +114,13 @@ instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instprox
instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private));
client_loc->parent = plistclient;
+#ifdef WIN32
+ InitializeCriticalSection(&client_loc->mutex);
+ client_loc->status_updater = NULL;
+#else
pthread_mutex_init(&client_loc->mutex, NULL);
client_loc->status_updater = (pthread_t)NULL;
+#endif
*client = client_loc;
return INSTPROXY_E_SUCCESS;
@@ -131,9 +144,17 @@ instproxy_error_t instproxy_client_free(instproxy_client_t client)
client->parent = NULL;
if (client->status_updater) {
debug_info("joining status_updater");
+#ifdef WIN32
+ WaitForSingleObject(client->status_updater, INFINITE);
+#else
pthread_join(client->status_updater, NULL);
+#endif
}
+#ifdef WIN32
+ DeleteCriticalSection(&client->mutex);
+#else
pthread_mutex_destroy(&client->mutex);
+#endif
free(client);
return INSTPROXY_E_SUCCESS;
@@ -356,7 +377,11 @@ static void* instproxy_status_updater(void* arg)
if (data->operation) {
free(data->operation);
}
+#ifdef WIN32
+ data->client->status_updater = NULL;
+#else
data->client->status_updater = (pthread_t)NULL;
+#endif
instproxy_unlock(data->client);
free(data);
@@ -391,9 +416,18 @@ static instproxy_error_t instproxy_create_status_updater(instproxy_client_t clie
data->operation = strdup(operation);
data->user_data = user_data;
+#ifdef WIN32
+ client->status_updater = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)instproxy_status_updater, data, 0, NULL);
+ if (client->status_updater != INVALID_HANDLE_VALUE) {
+ res = INSTPROXY_E_SUCCESS;
+ } else {
+ client->status_updater = NULL;
+ }
+#else
if (pthread_create(&client->status_updater, NULL, instproxy_status_updater, data) == 0) {
res = INSTPROXY_E_SUCCESS;
}
+#endif
}
} else {
/* sync mode */
diff --git a/src/installation_proxy.h b/src/installation_proxy.h
index 811ead6..642968d 100644
--- a/src/installation_proxy.h
+++ b/src/installation_proxy.h
@@ -21,15 +21,24 @@
#ifndef IINSTALLATION_PROXY_H
#define IINSTALLATION_PROXY_H
+#ifdef WIN32
+#include <windows.h>
+#else
#include <pthread.h>
+#endif
#include "libimobiledevice/installation_proxy.h"
#include "property_list_service.h"
struct instproxy_client_private {
property_list_service_client_t parent;
+#ifdef WIN32
+ CRITICAL_SECTION mutex;
+ HANDLE status_updater;
+#else
pthread_mutex_t mutex;
pthread_t status_updater;
+#endif
};
#endif
diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c
index 18caf73..557fbda 100644
--- a/src/mobile_image_mounter.c
+++ b/src/mobile_image_mounter.c
@@ -35,7 +35,11 @@
*/
static void mobile_image_mounter_lock(mobile_image_mounter_client_t client)
{
+#ifdef WIN32
+ EnterCriticalSection(&client->mutex);
+#else
pthread_mutex_lock(&client->mutex);
+#endif
}
/**
@@ -45,7 +49,11 @@ static void mobile_image_mounter_lock(mobile_image_mounter_client_t client)
*/
static void mobile_image_mounter_unlock(mobile_image_mounter_client_t client)
{
+#ifdef WIN32
+ LeaveCriticalSection(&client->mutex);
+#else
pthread_mutex_unlock(&client->mutex);
+#endif
}
/**
@@ -101,7 +109,11 @@ mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t
mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private));
client_loc->parent = plistclient;
+#ifdef WIN32
+ InitializeCriticalSection(&client_loc->mutex);
+#else
pthread_mutex_init(&client_loc->mutex, NULL);
+#endif
*client = client_loc;
return MOBILE_IMAGE_MOUNTER_E_SUCCESS;
@@ -123,7 +135,11 @@ mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_clie
property_list_service_client_free(client->parent);
client->parent = NULL;
+#ifdef WIN32
+ DeleteCriticalSection(&client->mutex);
+#else
pthread_mutex_destroy(&client->mutex);
+#endif
free(client);
return MOBILE_IMAGE_MOUNTER_E_SUCCESS;
diff --git a/src/mobile_image_mounter.h b/src/mobile_image_mounter.h
index e0828f9..ff0690d 100644
--- a/src/mobile_image_mounter.h
+++ b/src/mobile_image_mounter.h
@@ -21,14 +21,22 @@
#ifndef IMOBILE_IMAGE_MOUNTER_H
#define IMOBILE_IMAGE_MOUNTER_H
+#ifdef WIN32
+#include <windows.h>
+#else
#include <pthread.h>
+#endif
#include "libimobiledevice/mobile_image_mounter.h"
#include "property_list_service.h"
struct mobile_image_mounter_client_private {
property_list_service_client_t parent;
+#ifdef WIN32
+ CRITICAL_SECTION mutex;
+#else
pthread_mutex_t mutex;
+#endif
};
#endif
diff --git a/src/notification_proxy.c b/src/notification_proxy.c
index 792a165..086dec4 100644
--- a/src/notification_proxy.c
+++ b/src/notification_proxy.c
@@ -42,7 +42,11 @@ struct np_thread {
static void np_lock(np_client_t client)
{
debug_info("NP: Locked");
+#ifdef WIN32
+ EnterCriticalSection(&client->mutex);
+#else
pthread_mutex_lock(&client->mutex);
+#endif
}
/**
@@ -53,7 +57,11 @@ static void np_lock(np_client_t client)
static void np_unlock(np_client_t client)
{
debug_info("NP: Unlocked");
+#ifdef WIN32
+ LeaveCriticalSection(&client->mutex);
+#else
pthread_mutex_unlock(&client->mutex);
+#endif
}
/**
@@ -107,9 +115,13 @@ np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client)
np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private));
client_loc->parent = plistclient;
+#ifdef WIN32
+ InitializeCriticalSection(&client_loc->mutex);
+ client_loc->notifier = NULL;
+#else
pthread_mutex_init(&client_loc->mutex, NULL);
-
client_loc->notifier = (pthread_t)NULL;
+#endif
*client = client_loc;
return NP_E_SUCCESS;
@@ -132,9 +144,17 @@ np_error_t np_client_free(np_client_t client)
client->parent = NULL;
if (client->notifier) {
debug_info("joining np callback");
+#ifdef WIN32
+ WaitForSingleObject(client->notifier, INFINITE);
+#else
pthread_join(client->notifier, NULL);
+#endif
}
+#ifdef WIN32
+ DeleteCriticalSection(&client->mutex);
+#else
pthread_mutex_destroy(&client->mutex);
+#endif
free(client);
return NP_E_SUCCESS;
@@ -393,8 +413,13 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb,
debug_info("callback already set, removing\n");
property_list_service_client_t parent = client->parent;
client->parent = NULL;
+#ifdef WIN32
+ WaitForSingleObject(client->notifier, INFINITE);
+ client->notifier = NULL;
+#else
pthread_join(client->notifier, NULL);
client->notifier = (pthread_t)NULL;
+#endif
client->parent = parent;
}
@@ -405,9 +430,18 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb,
npt->cbfunc = notify_cb;
npt->user_data = user_data;
+#ifdef WIN32
+ client->notifier = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)np_notifier, npt, 0, NULL);
+ if (client->notifier != INVALID_HANDLE_VALUE) {
+ res = NP_E_SUCCESS;
+ } else {
+ client->notifier = NULL;
+ }
+#else
if (pthread_create(&client->notifier, NULL, np_notifier, npt) == 0) {
res = NP_E_SUCCESS;
}
+#endif
}
} else {
debug_info("no callback set");
diff --git a/src/notification_proxy.h b/src/notification_proxy.h
index 4a9cdad..0f92cdf 100644
--- a/src/notification_proxy.h
+++ b/src/notification_proxy.h
@@ -21,15 +21,24 @@
#ifndef INOTIFICATION_PROXY_H
#define INOTIFICATION_PROXY_H
+#ifdef WIN32
+#include <windows.h>
+#else
#include <pthread.h>
+#endif
#include "libimobiledevice/notification_proxy.h"
#include "property_list_service.h"
struct np_client_private {
property_list_service_client_t parent;
+#ifdef WIN32
+ CRITICAL_SECTION mutex;
+ HANDLE notifier;
+#else
pthread_mutex_t mutex;
pthread_t notifier;
+#endif
};
void* np_notifier(void* arg);
diff --git a/src/sbservices.c b/src/sbservices.c
index dd5f571..7f050bf 100644
--- a/src/sbservices.c
+++ b/src/sbservices.c
@@ -36,7 +36,11 @@
static void sbs_lock(sbservices_client_t client)
{
debug_info("SBServices: Locked");
+#ifdef WIN32
+ EnterCriticalSection(&client->mutex);
+#else
pthread_mutex_lock(&client->mutex);
+#endif
}
/**
@@ -47,7 +51,11 @@ static void sbs_lock(sbservices_client_t client)
static void sbs_unlock(sbservices_client_t client)
{
debug_info("SBServices: Unlocked");
+#ifdef WIN32
+ LeaveCriticalSection(&client->mutex);
+#else
pthread_mutex_unlock(&client->mutex);
+#endif
}
/**
@@ -100,7 +108,11 @@ sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbserv
sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_private));
client_loc->parent = plistclient;
+#ifdef WIN32
+ InitializeCriticalSection(&client_loc->mutex);
+#else
pthread_mutex_init(&client_loc->mutex, NULL);
+#endif
*client = client_loc;
return SBSERVICES_E_SUCCESS;
@@ -122,7 +134,11 @@ sbservices_error_t sbservices_client_free(sbservices_client_t client)
sbservices_error_t err = sbservices_error(property_list_service_client_free(client->parent));
client->parent = NULL;
+#ifdef WIN32
+ DeleteCriticalSection(&client->mutex);
+#else
pthread_mutex_destroy(&client->mutex);
+#endif
free(client);
return err;
diff --git a/src/sbservices.h b/src/sbservices.h
index 1c85fe8..2b600ad 100644
--- a/src/sbservices.h
+++ b/src/sbservices.h
@@ -21,14 +21,22 @@
#ifndef ISBSERVICES_H
#define ISBSERVICES_H
+#ifdef WIN32
+#include <windows.h>
+#else
#include <pthread.h>
+#endif
#include "libimobiledevice/sbservices.h"
#include "property_list_service.h"
struct sbservices_client_private {
property_list_service_client_t parent;
+#ifdef WIN32
+ CRITICAL_SECTION mutex;
+#else
pthread_mutex_t mutex;
+#endif
};
#endif