X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=resize%2Fprogress_c.c;fp=resize%2Fprogress_c.c;h=dddf78706473e04eb7aadfb4a373cebdb3190568;hp=0000000000000000000000000000000000000000;hb=2faef37957629e0436308e759211209e5e823ee0;hpb=9420eaf44ec4067c3740b91b0be0fede08a0c515 diff --git a/resize/progress_c.c b/resize/progress_c.c new file mode 100644 index 0000000..dddf787 --- /dev/null +++ b/resize/progress_c.c @@ -0,0 +1,101 @@ +/* virt-resize - interface to progress bar mini library + * Copyright (C) 2011 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "progress.h" + +#define Bar_val(v) (*((struct progress_bar **)Data_custom_val(v))) + +static void +progress_bar_finalize (value barv) +{ + struct progress_bar *bar = Bar_val (barv); + + if (bar) + progress_bar_free (bar); +} + +static struct custom_operations progress_bar_custom_operations = { + (char *) "progress_bar_custom_operations", + progress_bar_finalize, + custom_compare_default, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; + +value +virt_resize_progress_bar_init (value unitv) +{ + CAMLparam1 (unitv); + CAMLlocal1 (barv); + struct progress_bar *bar; + + /* XXX Have to do this to get nl_langinfo to work properly. However + * we should really only call this from main. + */ + setlocale (LC_ALL, ""); + + bar = progress_bar_init (0); + if (bar == NULL) + caml_raise_out_of_memory (); + + barv = caml_alloc_custom (&progress_bar_custom_operations, + sizeof (struct progress_bar *), 0, 1); + Bar_val (barv) = bar; + + CAMLreturn (barv); +} + +value +virt_resize_progress_bar_reset (value barv) +{ + CAMLparam1 (barv); + struct progress_bar *bar = Bar_val (barv); + + progress_bar_reset (bar); + + CAMLreturn (Val_unit); +} + +value +virt_resize_progress_bar_set (value barv, + value positionv, value totalv) +{ + CAMLparam3 (barv, positionv, totalv); + struct progress_bar *bar = Bar_val (barv); + uint64_t position = Int64_val (positionv); + uint64_t total = Int64_val (totalv); + + progress_bar_set (bar, position, total); + + CAMLreturn (Val_unit); +}