diff --git a/src/cl_backend.h b/src/cl_backend.h index 3b6ff3c..70308a1 100644 --- a/src/cl_backend.h +++ b/src/cl_backend.h @@ -54,11 +54,11 @@ int ptp_fsend_packets(struct PtpRuntime *r, int length, FILE *stream); // Reads the incoming packet to file, starting after an optional offset int ptp_freceive_bulk_packets(struct PtpRuntime *r, FILE *stream, int of); -int ptpip_connect(struct PtpRuntime *r, char *addr, int port); +int ptpip_connect(struct PtpRuntime *r, const char *addr, int port); int ptpip_cmd_write(struct PtpRuntime *r, void *data, int size); int ptpip_cmd_read(struct PtpRuntime *r, void *data, int size); -int ptpip_connect_events(struct PtpRuntime *r, char *addr, int port); +int ptpip_connect_events(struct PtpRuntime *r, const char *addr, int port); int ptpip_event_send(struct PtpRuntime *r, void *data, int size); int ptpip_event_read(struct PtpRuntime *r, void *data, int size); diff --git a/src/cl_ops.h b/src/cl_ops.h index d696a48..5dd75fa 100644 --- a/src/cl_ops.h +++ b/src/cl_ops.h @@ -5,7 +5,7 @@ /// @brief Set a generic property - abstraction over SetDeviceProp /// @note May reject writes if an invalid property is found (see event code) /// @memberof PtpRuntime -int ptp_set_generic_property(struct PtpRuntime *r, char *name, int value); +int ptp_set_generic_property(struct PtpRuntime *r, const char *name, int value); /// @brief Call before taking a picture - this is generally for 'focusing' /// On some cameras this does nothing. diff --git a/src/data.c b/src/data.c index 59743ab..8b24896 100644 --- a/src/data.c +++ b/src/data.c @@ -109,7 +109,7 @@ int parse_data_data_or_u32(uint8_t *d, int type, uint32_t *u32, void **data) { case PTP_TC_UINT16: case PTP_TC_INT32: case PTP_TC_UINT32: - return ptp_parse_data_u32(d, type, u32); + return ptp_parse_data_u32(d, type, (int *)u32); case PTP_TC_INT64: case PTP_TC_UINT64: (*data) = malloc(8); diff --git a/src/generic.c b/src/generic.c index 22edd27..f9e7542 100644 --- a/src/generic.c +++ b/src/generic.c @@ -50,7 +50,7 @@ static int ptp_eos_set_validate_prop(struct PtpRuntime *r, int prop_code, uint32 return ptp_eos_set_prop_value(r, prop_code, value); } -int ptp_set_generic_property(struct PtpRuntime *r, char *name, int value) { +int ptp_set_generic_property(struct PtpRuntime *r, const char *name, int value) { int dev = ptp_device_type(r); int rc = 0; if (!strcmp(name, "aperture")) { diff --git a/src/ip.c b/src/ip.c index c16607d..1bdc399 100644 --- a/src/ip.c +++ b/src/ip.c @@ -123,13 +123,14 @@ static struct PtpIpBackend *init_comm(struct PtpRuntime *r) { return (struct PtpIpBackend *)r->comm_backend; } -int ptpip_connect(struct PtpRuntime *r, char *addr, int port) { +int ptpip_connect(struct PtpRuntime *r, const char *addr, int port) { int fd = ptpip_new_timeout_socket(addr, port); struct PtpIpBackend *b = init_comm(r); if (fd > 0) { b->fd = fd; + r->io_kill_switch = 0; return 0; } else { b->fd = 0; @@ -137,7 +138,7 @@ int ptpip_connect(struct PtpRuntime *r, char *addr, int port) { } } -int ptpip_connect_events(struct PtpRuntime *r, char *addr, int port) { +int ptpip_connect_events(struct PtpRuntime *r, const char *addr, int port) { int fd = ptpip_new_timeout_socket(addr, port); struct PtpIpBackend *b = init_comm(r); diff --git a/src/lib.c b/src/lib.c index 8b07aa0..860bae4 100644 --- a/src/lib.c +++ b/src/lib.c @@ -106,7 +106,7 @@ void ptpusb_free_device_list(struct PtpDeviceEntry *e) { int ptp_buffer_resize(struct PtpRuntime *r, size_t size) { if (size < r->data_length) { - ptp_panic("You cannot downside the data buffer"); + ptp_panic("You cannot downsize the data buffer (%u -> %u)", r->data_length, size); } // realloc with a little extra space to minimize reallocs later on static int extra = 100; diff --git a/src/no_ip.c b/src/no_ip.c index 45c5f74..d669aee 100644 --- a/src/no_ip.c +++ b/src/no_ip.c @@ -7,11 +7,11 @@ int ptpip_new_timeout_socket(char *addr, int port) { return -1; } -int ptpip_connect(struct PtpRuntime *r, char *addr, int port) { +int ptpip_connect(struct PtpRuntime *r, const char *addr, int port) { return -1; } -int ptpip_connect_events(struct PtpRuntime *r, char *addr, int port) { +int ptpip_connect_events(struct PtpRuntime *r, const char *addr, int port) { return -1; } diff --git a/src/operations.c b/src/operations.c index 81dec51..77f2837 100644 --- a/src/operations.c +++ b/src/operations.c @@ -221,10 +221,16 @@ int ptp_get_object_handles(struct PtpRuntime *r, int id, int format, int in, str cmd.params[1] = format; cmd.params[2] = in; + ptp_mutex_keep_locked(r); + int rc = ptp_send(r, &cmd); + if (rc) goto end; (*a) = dup_uint_array((void *)ptp_get_payload(r)); + end:; + ptp_mutex_unlock(r); + return rc; } @@ -253,11 +259,16 @@ int ptp_get_prop_desc(struct PtpRuntime *r, int code, struct PtpPropDesc *pd) { cmd.param_length = 1; cmd.params[0] = code; - int x = ptp_send(r, &cmd); + ptp_mutex_keep_locked(r); + int rc = ptp_send(r, &cmd); + if (rc) goto end; ptp_parse_prop_desc(r, pd); - return x; + end:; + ptp_mutex_unlock(r); + + return rc; } int ptp_get_thumbnail(struct PtpRuntime *r, int handle) { diff --git a/src/transport.c b/src/transport.c index 20f2f89..bedca9a 100644 --- a/src/transport.c +++ b/src/transport.c @@ -42,7 +42,7 @@ int ptpip_read_packet(struct PtpRuntime *r, int of) { int rc = 0; int read = 0; - while (rc <= 0 && r->wait_for_response) { + while (r->wait_for_response) { rc = ptpip_cmd_read(r, r->data + of + read, 4); r->wait_for_response--; @@ -50,7 +50,7 @@ int ptpip_read_packet(struct PtpRuntime *r, int of) { if (rc > 0) break; if (r->wait_for_response) { - ptp_verbose_log("Trying again..."); + ptp_verbose_log("Trying again...\n"); CAMLIB_SLEEP(CAMLIB_WAIT_MS); } } @@ -126,7 +126,7 @@ int ptpip_receive_bulk_packets(struct PtpRuntime *r) { return PTP_IO_ERR; } } else if (h->type == PTPIP_COMMAND_RESPONSE) { - ptp_verbose_log("Recieved response packet\n"); + ptp_verbose_log("Received response packet\n"); } else { ptp_verbose_log("Unexpected packet: %X\n", h->type); return PTP_IO_ERR; @@ -167,7 +167,7 @@ int ptpusb_read_all_packets(struct PtpRuntime *r) { if (rc < 0) break; if (r->wait_for_response) { - ptp_verbose_log("Trying again..."); + ptp_verbose_log("Trying again...\n"); CAMLIB_SLEEP(CAMLIB_WAIT_MS); } } @@ -218,7 +218,7 @@ int ptpipusb_read_packet(struct PtpRuntime *r, int of) { int rc = 0; int read = 0; - while (rc <= 0 && r->wait_for_response) { + while (r->wait_for_response) { rc = ptpip_cmd_read(r, r->data + of + read, 4); r->wait_for_response--; @@ -226,7 +226,7 @@ int ptpipusb_read_packet(struct PtpRuntime *r, int of) { if (rc > 0) break; if (r->wait_for_response) { - ptp_verbose_log("Trying again..."); + ptp_verbose_log("Trying again...\n"); CAMLIB_SLEEP(CAMLIB_WAIT_MS); } } @@ -308,6 +308,7 @@ int ptpipusb_receive_bulk_packets(struct PtpRuntime *r) { } int ptp_receive_bulk_packets(struct PtpRuntime *r) { + if (r->io_kill_switch) return -1; if (r->connection_type == PTP_IP) { return ptpip_receive_bulk_packets(r); } else if (r->connection_type == PTP_USB) {