removed unnecessary aspect virtual functions + infrastructure

This commit is contained in:
schoebel 2011-10-02 22:11:39 +02:00 committed by Thomas Schoebel-Theuer
parent 507193ac69
commit e89088b7cb
15 changed files with 74 additions and 183 deletions

168
brick.c
View File

@ -405,6 +405,10 @@ int generic_brick_exit_recursively(struct generic_brick *brick, bool destroy_inp
}
EXPORT_SYMBOL_GPL(generic_brick_exit_recursively);
////////////////////////////////////////////////////////////////////////
// to disappear!
int generic_add_aspect(struct generic_output *output, struct generic_object_layout *object_layout, const struct generic_aspect_type *aspect_type)
{
struct generic_aspect_layout *aspect_layout;
@ -470,8 +474,75 @@ err:
return status;
}
/* Callback, usually called for each brick instance.
* Initialize the information for single aspect associated to a single brick.
*/
int default_make_object_layout(struct generic_output *output, struct generic_object_layout *object_layout)
{
struct generic_brick *brick;
const struct generic_output_type *output_type;
const struct generic_object_type *object_type;
const struct generic_aspect_type *aspect_type;
int i;
int nr;
int aspect_size = 0;
int status = -EINVAL;
EXPORT_SYMBOL_GPL(generic_add_aspect);
if (unlikely(!output)) {
BRICK_ERR("output is missing\n");
goto done;
}
if (unlikely(!object_layout || !object_layout->object_type)) {
BRICK_ERR("object_layout not inizialized\n");
goto done;
}
brick = output->brick;
if (unlikely(!brick)) {
BRICK_ERR("brick is missing\n");
goto done;
}
output_type = output->type;
if (unlikely(!output_type)) {
BRICK_ERR("output_type is missing\n");
goto done;
}
object_type = object_layout->object_type;
if (unlikely(!object_type)) {
BRICK_ERR("object_type is missing\n");
goto done;
}
nr = object_type->brick_obj_nr;
if (unlikely(nr < 0 || nr >= brick_obj_max)) {
BRICK_ERR("bad brick_obj_nr = %d\n", nr);
goto done;
}
aspect_type = output_type->aspect_types[nr];
status = -ENOENT;
if (unlikely(!aspect_type)) {
BRICK_ERR("aspect type on %s does not exist\n", output_type->type_name);
goto done;
}
aspect_size = aspect_type->aspect_size;
for (i = 0; i < brick->type->max_inputs; i++) {
struct generic_input *input = brick->inputs[i];
if (input && input->connect) {
int substatus = default_make_object_layout(input->connect, object_layout);
if (substatus < 0)
return substatus;
aspect_size += substatus;
}
}
status = generic_add_aspect(output, object_layout, aspect_type);
done:
if (status < 0)
return status;
return aspect_size;
}
////////////////////////////////////////////////////////////////////////
@ -569,7 +640,7 @@ int default_init_object_layout(struct generic_output *output, struct generic_obj
object_layout->free_list = NULL;
object_layout->module_name = module_name;
status = output->ops->make_object_layout(output, object_layout);
status = default_make_object_layout(output, object_layout);
if (unlikely(status < 0)) {
object_layout->object_type = NULL;
@ -591,99 +662,6 @@ done:
}
EXPORT_SYMBOL_GPL(default_init_object_layout);
/* Callback, usually called for each brick instance.
* Initialize the information for single aspect associated to a single brick.
*/
int default_make_object_layout(struct generic_output *output, struct generic_object_layout *object_layout)
{
struct generic_brick *brick;
const struct generic_output_type *output_type;
const struct generic_object_type *object_type;
const struct generic_aspect_type *aspect_type;
int nr;
int layout_code;
int aspect_size = 0;
int status = -EINVAL;
if (unlikely(!output)) {
BRICK_ERR("output is missing\n");
goto done;
}
if (unlikely(!object_layout || !object_layout->object_type)) {
BRICK_ERR("object_layout not inizialized\n");
goto done;
}
brick = output->brick;
if (unlikely(!brick)) {
BRICK_ERR("brick is missing\n");
goto done;
}
output_type = output->type;
if (unlikely(!output_type)) {
BRICK_ERR("output_type is missing\n");
goto done;
}
object_type = object_layout->object_type;
if (unlikely(!object_type)) {
BRICK_ERR("object_type is missing\n");
goto done;
}
nr = object_type->brick_obj_nr;
if (unlikely(nr < 0 || nr >= brick_obj_max)) {
BRICK_ERR("bad brick_obj_nr = %d\n", nr);
goto done;
}
layout_code = output_type->layout_code[nr];
aspect_type = output_type->aspect_types[nr];
status = -ENOENT;
if (unlikely(!aspect_type)) {
BRICK_ERR("aspect type on %s does not exist\n", output_type->type_name);
goto done;
}
aspect_size = aspect_type->aspect_size;
if (layout_code == LAYOUT_ALL) {
int i;
for (i = 0; i < brick->type->max_inputs; i++) {
struct generic_input *input = brick->inputs[i];
if (input && input->connect) {
int substatus = input->connect->ops->make_object_layout(input->connect, object_layout);
if (substatus < 0)
return substatus;
aspect_size += substatus;
}
}
} else {
for (; layout_code != 0; layout_code >>= 8) {
unsigned int my_code = layout_code & 255;
struct generic_input *input;
int substatus;
if (my_code == 255)
break;
if (my_code >= brick->type->max_inputs)
continue;
input = brick->inputs[my_code];
if (!input || !input->connect)
continue;
substatus = input->connect->ops->make_object_layout(input->connect, object_layout);
if (substatus < 0)
return substatus;
aspect_size += substatus;
}
}
status = generic_add_aspect(output, object_layout, aspect_type);
done:
if (status < 0)
return status;
return aspect_size;
}
EXPORT_SYMBOL_GPL(default_make_object_layout);
struct generic_object *alloc_generic(struct generic_object_layout *object_layout)
{

38
brick.h
View File

@ -258,7 +258,6 @@ struct generic_brick_ops {
#define GENERIC_OUTPUT_OPS(BRICK) \
/*int (*output_start)(struct BRICK##_output *output);*/ \
/*int (*output_stop)(struct BRICK##_output *output);*/ \
int (*make_object_layout)(struct BRICK##_output *output, struct generic_object_layout *object_layout); \
struct generic_output_ops {
GENERIC_OUTPUT_OPS(generic)
@ -300,18 +299,11 @@ struct generic_input_type {
int (*output_construct)(struct BRICK##_output *output); \
int (*output_destruct)(struct BRICK##_output *output); \
const struct generic_aspect_type **aspect_types; \
const int layout_code[BRICK_OBJ_MAX]; \
struct generic_output_type {
GENERIC_OUTPUT_TYPE(generic);
};
#define LAYOUT_NONE 0
#define LAYOUT_ALL -1
#define LAYOUT_1(X1) ((X1) | 255 << 8)
#define LAYOUT_2(X1,X2) ((X1) | (X2) << 8 | 255 << 16)
#define LAYOUT_3(X1,X2,X3) ((X1) | (X2) << 8 | (X3) << 16 | 255 << 24)
int generic_register_brick_type(const struct generic_brick_type *new_type);
int generic_unregister_brick_type(const struct generic_brick_type *old_type);
@ -498,11 +490,6 @@ static inline int BRICK##_unregister_brick_type(void) \
return generic_unregister_brick_type((const struct generic_brick_type*)&BRICK##_brick_type); \
} \
\
static inline int BRICK##_make_object_layout(struct BRICK##_output *output, struct generic_object_layout *object_layout) \
{ \
return default_make_object_layout((struct generic_output*)output, object_layout); \
} \
\
extern const struct BRICK##_brick_type BRICK##_brick_type; \
extern const struct BRICK##_input_type BRICK##_input_type; \
extern const struct BRICK##_output_type BRICK##_output_type; \
@ -547,7 +534,7 @@ INLINE int BRICK##_output_init(struct BRICK##_brick *brick, int index, struct BR
/* Define a pair of connectable subtypes.
* For type safety, use this for all possible combinations.
* Yes, this may become quadratic in large type systems, but
* (a) thou shalt not define many types,
* (a) thou shalt not define much types,
* (b) these macros generate only definitions, but no additional
* code at runtime.
*/
@ -573,10 +560,6 @@ INLINE int INPUT_BRICK##_##OUTPUT_BRICK####_disconnect( \
// default operations on objects / aspects
extern int default_make_object_layout(struct generic_output *output, struct generic_object_layout *object_layout);
extern int generic_add_aspect(struct generic_output *output, struct generic_object_layout *object_layout, const struct generic_aspect_type *aspect_type);
extern int default_init_object_layout(struct generic_output *output, struct generic_object_layout *object_layout, int aspect_max, const struct generic_object_type *object_type, char *module_name);
extern void default_exit_object_layout(struct generic_object_layout *object_layout);
@ -584,24 +567,6 @@ extern struct generic_object *alloc_generic(struct generic_object_layout *object
extern void free_generic(struct generic_object *object);
#define GENERIC_OBJECT_LAYOUT_FUNCTIONS(BRICK) \
\
INLINE int BRICK##_init_object_layout(struct BRICK##_output *output, struct generic_object_layout *object_layout, int aspect_max, const struct generic_object_type *object_type) \
{ \
if (likely(object_layout->aspect_layouts_table && object_layout->aspect_layouts && object_layout->object_layout_generation == brick_layout_generation)) \
return 0; \
return default_init_object_layout((struct generic_output*)output, object_layout, aspect_max, object_type, #BRICK); \
} \
#define GENERIC_ASPECT_LAYOUT_FUNCTIONS(BRICK,TYPE) \
\
INLINE int BRICK##_##TYPE##_add_aspect(struct BRICK##_output *output, struct TYPE##_object_layout *object_layout, const struct generic_aspect_type *aspect_type) \
{ \
int res = generic_add_aspect((struct generic_output*)output, (struct generic_object_layout *)object_layout, aspect_type); \
BRICK_DBG(#BRICK " " #TYPE "added aspect_type %p (%s) to object_layout %p (type %s) on output %p (type %s), status=%d\n", aspect_type, aspect_type->aspect_type_name, object_layout, object_layout->object_type->object_type_name, output, output->type->type_name, res); \
return res; \
} \
#define GENERIC_OBJECT_FUNCTIONS(TYPE) \
\
INLINE struct TYPE##_object *TYPE##_construct(void *data, struct TYPE##_object_layout *object_layout) \
@ -704,7 +669,6 @@ INLINE void BRICK##_free_##TYPE(struct TYPE##_object *object) \
} \
GENERIC_OBJECT_LAYOUT_FUNCTIONS(generic);
GENERIC_OBJECT_FUNCTIONS(generic);
///////////////////////////////////////////////////////////////////////

3
mars.h
View File

@ -237,8 +237,6 @@ _MARS_TYPES(BRICK) \
struct BRICK##_object_layout; \
\
GENERIC_MAKE_CONNECT(generic,BRICK); \
GENERIC_OBJECT_LAYOUT_FUNCTIONS(BRICK); \
GENERIC_ASPECT_LAYOUT_FUNCTIONS(BRICK,mref); \
GENERIC_ASPECT_FUNCTIONS(BRICK,mref); \
extern int init_mars_##BRICK(void); \
extern void exit_mars_##BRICK(void);
@ -251,7 +249,6 @@ GENERIC_OBJECT_FUNCTIONS(mref);
// instantiate a pseudo base-class "mars"
_MARS_TYPES(mars);
GENERIC_OBJECT_LAYOUT_FUNCTIONS(mars);
GENERIC_ASPECT_FUNCTIONS(mars,mref);
/////////////////////////////////////////////////////////////////////////

View File

@ -977,7 +977,6 @@ static struct aio_brick_ops aio_brick_ops = {
};
static struct aio_output_ops aio_output_ops = {
.make_object_layout = aio_make_object_layout,
.mref_get = aio_ref_get,
.mref_put = aio_ref_put,
.mref_io = aio_ref_io,
@ -1000,9 +999,6 @@ const struct aio_output_type aio_output_type = {
.output_construct = &aio_output_construct,
.output_destruct = &aio_output_destruct,
.aspect_types = aio_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_NONE,
}
};
static const struct aio_output_type *aio_output_types[] = {

View File

@ -616,7 +616,6 @@ static struct bio_brick_ops bio_brick_ops = {
};
static struct bio_output_ops bio_output_ops = {
.make_object_layout = bio_make_object_layout,
.mars_get_info = bio_get_info,
.mref_get = bio_ref_get,
.mref_put = bio_ref_put,
@ -639,9 +638,6 @@ const struct bio_output_type bio_output_type = {
.output_construct = &bio_output_construct,
.output_destruct = &bio_output_destruct,
.aspect_types = bio_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_ALL,
}
};
static const struct bio_output_type *bio_output_types[] = {

View File

@ -1098,7 +1098,6 @@ static struct buf_brick_ops buf_brick_ops = {
};
static struct buf_output_ops buf_output_ops = {
.make_object_layout = buf_make_object_layout,
.mars_get_info = buf_get_info,
.mref_get = buf_ref_get,
.mref_put = buf_ref_put,
@ -1120,9 +1119,6 @@ const struct buf_output_type buf_output_type = {
.master_ops = &buf_output_ops,
.output_construct = &buf_output_construct,
.aspect_types = buf_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_ALL,
}
};
static const struct buf_output_type *buf_output_types[] = {

View File

@ -306,7 +306,6 @@ static struct check_brick_ops check_brick_ops = {
};
static struct check_output_ops check_output_ops = {
.make_object_layout = check_make_object_layout,
.mars_get_info = check_get_info,
.mref_get = check_ref_get,
.mref_put = check_ref_put,
@ -328,9 +327,6 @@ const struct check_output_type check_output_type = {
.master_ops = &check_output_ops,
.output_construct = &check_output_construct,
.aspect_types = check_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_ALL,
}
};
static const struct check_output_type *check_output_types[] = {

View File

@ -554,7 +554,6 @@ static struct client_brick_ops client_brick_ops = {
};
static struct client_output_ops client_output_ops = {
.make_object_layout = client_make_object_layout,
.mars_get_info = client_get_info,
.mref_get = client_ref_get,
.mref_put = client_ref_put,
@ -577,9 +576,6 @@ const struct client_output_type client_output_type = {
.output_construct = &client_output_construct,
.output_destruct = &client_output_destruct,
.aspect_types = client_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_ALL,
}
};
static const struct client_output_type *client_output_types[] = {

View File

@ -628,7 +628,6 @@ static struct copy_brick_ops copy_brick_ops = {
};
static struct copy_output_ops copy_output_ops = {
.make_object_layout = copy_make_object_layout,
.mars_get_info = copy_get_info,
.mref_get = copy_ref_get,
.mref_put = copy_ref_put,
@ -654,9 +653,6 @@ const struct copy_output_type copy_output_type = {
.output_construct = &copy_output_construct,
.output_destruct = &copy_output_destruct,
.aspect_types = copy_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_ALL,
}
};
static const struct copy_output_type *copy_output_types[] = {

View File

@ -135,7 +135,6 @@ struct dummy_brick_ops dummy_brick_ops = {
static
struct dummy_output_ops dummy_output_ops = {
.make_object_layout = dummy_make_object_layout,
.mars_get_info = dummy_get_info,
.mref_get = dummy_ref_get,
.mref_put = dummy_ref_put,
@ -159,9 +158,6 @@ const struct dummy_output_type dummy_output_type = {
.output_construct = &dummy_output_construct,
.output_destruct = &dummy_output_destruct,
.aspect_types = dummy_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_ALL,
}
};
static

View File

@ -792,7 +792,6 @@ static struct if_brick_ops if_brick_ops = {
};
static struct if_output_ops if_output_ops = {
.make_object_layout = if_make_object_layout,
};
const struct if_input_type if_input_type = {
@ -812,9 +811,6 @@ const struct if_output_type if_output_type = {
.master_ops = &if_output_ops,
.output_construct = &if_output_construct,
.aspect_types = if_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_ALL,
}
};
static const struct if_output_type *if_output_types[] = {

View File

@ -519,7 +519,6 @@ static struct server_brick_ops server_brick_ops = {
};
static struct server_output_ops server_output_ops = {
.make_object_layout = server_make_object_layout,
.mars_get_info = server_get_info,
.mref_get = server_ref_get,
.mref_put = server_ref_put,
@ -541,9 +540,6 @@ const struct server_output_type server_output_type = {
.master_ops = &server_output_ops,
.output_construct = &server_output_construct,
.aspect_types = server_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_ALL,
}
};
static const struct server_output_type *server_output_types[] = {

View File

@ -504,7 +504,6 @@ static struct sio_brick_ops sio_brick_ops = {
};
static struct sio_output_ops sio_output_ops = {
.make_object_layout = sio_make_object_layout,
.mref_get = sio_ref_get,
.mref_put = sio_ref_put,
.mref_io = sio_mars_queue,
@ -527,9 +526,6 @@ const struct sio_output_type sio_output_type = {
.output_construct = &sio_output_construct,
.output_destruct = &sio_output_destruct,
.aspect_types = sio_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_NONE,
}
};
static const struct sio_output_type *sio_output_types[] = {

View File

@ -2639,7 +2639,6 @@ static struct trans_logger_brick_ops trans_logger_brick_ops = {
};
static struct trans_logger_output_ops trans_logger_output_ops = {
.make_object_layout = trans_logger_make_object_layout,
.mars_get_info = trans_logger_get_info,
.mref_get = trans_logger_ref_get,
.mref_put = trans_logger_ref_put,
@ -2667,9 +2666,6 @@ const struct trans_logger_output_type trans_logger_output_type = {
.master_ops = &trans_logger_output_ops,
.output_construct = &trans_logger_output_construct,
.aspect_types = trans_logger_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_ALL,
}
};
static const struct trans_logger_output_type *trans_logger_output_types[] = {

View File

@ -330,7 +330,6 @@ static struct usebuf_brick_ops usebuf_brick_ops = {
};
static struct usebuf_output_ops usebuf_output_ops = {
.make_object_layout = usebuf_make_object_layout,
.mars_get_info = usebuf_get_info,
.mref_get = usebuf_ref_get,
.mref_put = usebuf_ref_put,
@ -352,9 +351,6 @@ const struct usebuf_output_type usebuf_output_type = {
.master_ops = &usebuf_output_ops,
.output_construct = &usebuf_output_construct,
.aspect_types = usebuf_aspect_types,
.layout_code = {
[BRICK_OBJ_MREF] = LAYOUT_ALL,
}
};
static const struct usebuf_output_type *usebuf_output_types[] = {