mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-30 17:18:21 +03:00
libdm: report: implement DM_REPORT_GROUP_BASIC for extended report output
This patch introduces DM_REPORT_GROUP_BASIC report group type. This type has exactly the classical output format as we know from before introduction of report groups. However, in addition to that, it allows to put several reports into a group - this is the very basic grouping scheme that doesn't change the output format itself: Report: report1_name Header1 Header2 ... value value ... value value ... ... ... ... Report: report2_name Header1 Header2 ... value value ... value value ... ... ... ...
This commit is contained in:
parent
a9fe57db1c
commit
230b7ff0f6
@ -1,5 +1,6 @@
|
||||
Version 1.02.128 -
|
||||
=================================
|
||||
Introduce DM_REPORT_GROUP_BASIC for report group with basic report output.
|
||||
Introduce DM_REPORT_GROUP_SINGLE for report group having single report only.
|
||||
Add dm_report_group_{create,push,pop,destroy} to support report grouping.
|
||||
|
||||
|
@ -2710,6 +2710,7 @@ struct dm_report_group;
|
||||
|
||||
typedef enum {
|
||||
DM_REPORT_GROUP_SINGLE,
|
||||
DM_REPORT_GROUP_BASIC
|
||||
} dm_report_group_type_t;
|
||||
|
||||
struct dm_report_group *dm_report_group_create(dm_report_group_type_t type, void *data);
|
||||
|
@ -4205,6 +4205,12 @@ static int _sort_rows(struct dm_report *rh)
|
||||
|
||||
#define UNABLE_TO_EXTEND_OUTPUT_LINE_MSG "dm_report: Unable to extend output line"
|
||||
|
||||
static int _is_basic_report(struct dm_report *rh)
|
||||
{
|
||||
return rh->group_item &&
|
||||
(rh->group_item->group->type == DM_REPORT_GROUP_BASIC);
|
||||
}
|
||||
|
||||
/*
|
||||
* Produce report output
|
||||
*/
|
||||
@ -4463,9 +4469,29 @@ static struct report_group_item *_get_topmost_report_group_item(struct dm_report
|
||||
return item;
|
||||
}
|
||||
|
||||
static int _print_basic_report_header(struct dm_report *rh)
|
||||
{
|
||||
const char *report_name = (const char *) rh->group_item->data;
|
||||
size_t len = strlen(report_name);
|
||||
char *underline;
|
||||
|
||||
if (!(underline = dm_pool_zalloc(rh->mem, len + 1)))
|
||||
return_0;
|
||||
|
||||
memset(underline, '=', len);
|
||||
|
||||
if (rh->group_item->parent->store.finished_count > 0)
|
||||
log_print("%s", "");
|
||||
log_print("%s", report_name);
|
||||
log_print("%s", underline);
|
||||
|
||||
dm_pool_free(rh->mem, underline);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_report_output(struct dm_report *rh)
|
||||
{
|
||||
int r;
|
||||
int r = 0;
|
||||
|
||||
if (dm_list_empty(&rh->rows)) {
|
||||
r = 1;
|
||||
@ -4475,6 +4501,9 @@ int dm_report_output(struct dm_report *rh)
|
||||
if ((rh->flags & RH_SORT_REQUIRED))
|
||||
_sort_rows(rh);
|
||||
|
||||
if (_is_basic_report(rh) && !_print_basic_report_header(rh))
|
||||
goto_out;
|
||||
|
||||
if ((rh->flags & DM_REPORT_OUTPUT_COLUMNS_AS_ROWS))
|
||||
r = _output_as_rows(rh);
|
||||
else
|
||||
@ -4490,6 +4519,11 @@ static int _report_group_create_single(struct dm_report_group *group)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _report_group_create_basic(struct dm_report_group *group)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct dm_report_group *dm_report_group_create(dm_report_group_type_t type, void *data)
|
||||
{
|
||||
struct dm_report_group *group;
|
||||
@ -4522,6 +4556,10 @@ struct dm_report_group *dm_report_group_create(dm_report_group_type_t type, void
|
||||
if (!_report_group_create_single(group))
|
||||
goto_bad;
|
||||
break;
|
||||
case DM_REPORT_GROUP_BASIC:
|
||||
if (!_report_group_create_basic(group))
|
||||
goto_bad;
|
||||
break;
|
||||
default:
|
||||
goto_bad;
|
||||
}
|
||||
@ -4551,6 +4589,14 @@ static int _report_group_push_single(struct report_group_item *item, void *data)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _report_group_push_basic(struct report_group_item *item, const char *name)
|
||||
{
|
||||
if (!item->report && !name && item->parent->store.finished_count > 0)
|
||||
log_print("%s", "");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_report_group_push(struct dm_report_group *group, struct dm_report *report, void *data)
|
||||
{
|
||||
struct report_group_item *item, *tmp_item;
|
||||
@ -4584,6 +4630,10 @@ int dm_report_group_push(struct dm_report_group *group, struct dm_report *report
|
||||
if (!_report_group_push_single(item, data))
|
||||
goto_bad;
|
||||
break;
|
||||
case DM_REPORT_GROUP_BASIC:
|
||||
if (!_report_group_push_basic(item, data))
|
||||
goto_bad;
|
||||
break;
|
||||
default:
|
||||
goto_bad;
|
||||
}
|
||||
@ -4600,6 +4650,11 @@ static int _report_group_pop_single(struct report_group_item *item)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _report_group_pop_basic(struct report_group_item *item)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_report_group_pop(struct dm_report_group *group)
|
||||
{
|
||||
struct report_group_item *item;
|
||||
@ -4617,6 +4672,10 @@ int dm_report_group_pop(struct dm_report_group *group)
|
||||
if (!_report_group_pop_single(item))
|
||||
return_0;
|
||||
break;
|
||||
case DM_REPORT_GROUP_BASIC:
|
||||
if (!_report_group_pop_basic(item))
|
||||
return_0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -4640,6 +4699,11 @@ static int _report_group_destroy_single(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _report_group_destroy_basic(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_report_group_destroy(struct dm_report_group *group)
|
||||
{
|
||||
struct report_group_item *item, *tmp_item;
|
||||
@ -4660,6 +4724,10 @@ int dm_report_group_destroy(struct dm_report_group *group)
|
||||
if (!_report_group_destroy_single())
|
||||
goto_out;
|
||||
break;
|
||||
case DM_REPORT_GROUP_BASIC:
|
||||
if (!_report_group_destroy_basic())
|
||||
goto_out;
|
||||
break;
|
||||
default:
|
||||
goto_out;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user