2 #include "fwp_foreach.h"
4 #include <fwp_contract.h>
5 #include "fwp_admctrl.h"
14 static char *num_with_unit(char *buf, unsigned num, const char *units[])
16 const int div[] = {100,10,1};
20 while (num > 999 && units[(order+3)/3] != NULL) {
27 sprintf(buf, "%4d %s", num, units[(order+2)/3]);
29 sprintf(buf, "%d.%.*d %s", num/d, (d==10) ? 1 : 2, num%d, units[(order+2)/3]);
33 char *bandwidth_to_text(char *buf, unsigned bandwidth_bps)
35 const char *unit[] = {"bps", "kbps", "Mbps", NULL};
36 return num_with_unit(buf, bandwidth_bps, unit);
39 char *usec_to_text(char *buf, unsigned usec)
41 const char *unit[] = {"us", "ms", "s", NULL};
42 return num_with_unit(buf, usec, unit);
45 #define addfield(width, title, format, ...) \
48 if (cd == NULL) addstr(title); \
50 snprintf(str, sizeof(str), format, __VA_ARGS__); \
54 static void print_contract(int y, fwp_contract_data_t *cd)
56 const char *ac_ids[] = { [FWP_AC_VO]="VO", [FWP_AC_VI]="VI", [FWP_AC_BE]="BE", [FWP_AC_BK]="BK" };
57 struct fwp_contract *c = &cd->contract;
58 char str[200], s1[20];
61 addfield(4, "ID", "%d", cd->id);
62 addfield(11, "BW", "%s", bandwidth_to_text(s1, (long long)1000*1000*8*c->budget/c->period_usec));
63 addfield(11, "Budget", "%d bytes", c->budget);
64 addfield(11, "Period", "%s", usec_to_text(s1, c->period_usec));
65 addfield(11, "Deadline", "%s", usec_to_text(s1, c->deadline_usec));
66 addfield(3, "AC", "%s", ac_ids[cd->vres_params.ac_id]);
69 void gui_print_status()
71 fwp_contract_data_t *cd;
72 struct foreach_contract fec;
76 clear(); /* Repaint the screen completely to
77 * delete error messages */
78 mvaddstr(0, 0, "FWP Manager");
79 sprintf(str, "Reserved utilization: %d%%", fwp_reserved_utilization/100);
84 print_contract(y, NULL);
88 fec.contdata_new = NULL;
89 for (cd=foreach_contract_begin(&fec);
91 cd=foreach_contract_next(&fec)) {
92 print_contract(y, cd);