Add callback function to show upload percentage to C example

This commit is contained in:
Jackson Coxson
2025-03-28 12:27:42 -06:00
parent 3dc75db34c
commit 935bb747c3

View File

@@ -34,6 +34,19 @@ static uint8_t *read_file(const char *path, size_t *len) {
return buffer; return buffer;
} }
// Callback function to show progress
void progress_callback(size_t progress, size_t total, void *context) {
size_t percent = (progress * 100) / total;
printf("\rUpload progress: %zu%%", percent);
fflush(stdout);
// Print newline when complete
if (progress == total) {
printf("\n");
}
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc < 5) { if (argc < 5) {
fprintf(stderr, fprintf(stderr,
@@ -166,12 +179,12 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
// Mount personalized image // Mount personalized image with progress callback
err = image_mounter_mount_personalized_tcp( err = image_mounter_mount_personalized_tcp_with_callback(
mounter_client, provider, image, image_len, trustcache, trustcache_len, mounter_client, provider, image, image_len, trustcache, trustcache_len,
build_manifest, manifest_len, build_manifest, manifest_len,
NULL, // info_plist NULL, // info_plist
unique_chip_id); unique_chip_id, progress_callback, NULL);
if (err != IdeviceSuccess) { if (err != IdeviceSuccess) {
fprintf(stderr, "Failed to mount personalized image: %d\n", err); fprintf(stderr, "Failed to mount personalized image: %d\n", err);