mars/kernel/mars_dummy.c

239 lines
5.4 KiB
C
Raw Normal View History

2014-11-21 10:51:34 +00:00
/*
* MARS Long Distance Replication Software
*
* This file is part of MARS project: http://schoebel.github.io/mars/
*
* Copyright (C) 2010-2014 Thomas Schoebel-Theuer
* Copyright (C) 2011-2014 1&1 Internet AG
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
2010-06-14 14:27:40 +00:00
// Dummy brick (just for demonstration)
2010-07-30 05:46:22 +00:00
//#define BRICK_DEBUGGING
//#define MARS_DEBUGGING
//#define IO_DEBUGGING
//#define STAT_DEBUGGING
2010-07-30 05:46:22 +00:00
2010-06-14 14:27:40 +00:00
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include "mars.h"
///////////////////////// own type definitions ////////////////////////
2010-06-20 18:55:34 +00:00
#include "mars_dummy.h"
2010-06-14 14:27:40 +00:00
2010-07-07 14:09:16 +00:00
///////////////////////// own helper functions ////////////////////////
2010-06-14 14:27:40 +00:00
////////////////// own brick / input / output operations //////////////////
2011-03-31 16:16:00 +00:00
static
int dummy_get_info(struct dummy_output *output, struct mars_info *info)
2010-06-28 05:53:46 +00:00
{
struct dummy_input *input = output->brick->inputs[0];
2010-07-07 14:09:16 +00:00
return GENERIC_INPUT_CALL(input, mars_get_info, info);
2010-07-05 15:56:58 +00:00
}
2011-03-31 16:16:00 +00:00
static
int dummy_ref_get(struct dummy_output *output, struct mref_object *mref)
2010-07-05 15:56:58 +00:00
{
struct dummy_input *input = output->brick->inputs[0];
2010-12-15 12:13:18 +00:00
return GENERIC_INPUT_CALL(input, mref_get, mref);
2010-07-05 15:56:58 +00:00
}
2011-03-31 16:16:00 +00:00
static
void dummy_ref_put(struct dummy_output *output, struct mref_object *mref)
2010-07-05 15:56:58 +00:00
{
struct dummy_input *input = output->brick->inputs[0];
2010-12-15 12:13:18 +00:00
GENERIC_INPUT_CALL(input, mref_put, mref);
2010-07-05 15:56:58 +00:00
}
2011-03-31 16:16:00 +00:00
static
void dummy_ref_io(struct dummy_output *output, struct mref_object *mref)
2010-07-05 15:56:58 +00:00
{
struct dummy_input *input = output->brick->inputs[0];
2010-12-15 12:13:18 +00:00
GENERIC_INPUT_CALL(input, mref_io, mref);
2010-06-28 05:53:46 +00:00
}
2011-03-31 16:16:00 +00:00
static
int dummy_switch(struct dummy_brick *brick)
2011-02-23 20:48:06 +00:00
{
if (brick->power.button) {
bool success = false;
if (brick->power.led_on)
goto done;
2011-02-23 20:48:06 +00:00
mars_power_led_off((void*)brick, false);
//...
success = true;
if (success) {
mars_power_led_on((void*)brick, true);
}
2011-02-23 20:48:06 +00:00
} else {
bool success = false;
if (brick->power.led_off)
goto done;
2011-02-23 20:48:06 +00:00
mars_power_led_on((void*)brick, false);
//...
success = true;
if (success) {
mars_power_led_off((void*)brick, true);
}
2011-02-23 20:48:06 +00:00
}
done:
2011-02-23 20:48:06 +00:00
return 0;
}
2011-03-31 16:16:00 +00:00
//////////////// informational / statistics ///////////////
static
char *dummy_statistics(struct dummy_brick *brick, int verbose)
{
char *res = brick_string_alloc(1024);
if (!res)
return NULL;
snprintf(res, 1023,
"nothing has happened.\n"
);
return res;
2011-03-31 16:16:00 +00:00
}
static
void dummy_reset_statistics(struct dummy_brick *brick)
{
}
2010-06-22 13:21:42 +00:00
//////////////// object / aspect constructors / destructors ///////////////
2011-03-31 16:16:00 +00:00
static
int dummy_mref_aspect_init_fn(struct generic_aspect *_ini)
2010-07-05 15:56:58 +00:00
{
2010-12-15 12:13:18 +00:00
struct dummy_mref_aspect *ini = (void*)_ini;
2010-08-08 09:03:42 +00:00
(void)ini;
2011-02-23 20:48:06 +00:00
//ini->my_own = 0;
2010-07-05 15:56:58 +00:00
return 0;
}
2011-03-31 16:16:00 +00:00
static
void dummy_mref_aspect_exit_fn(struct generic_aspect *_ini)
2010-08-08 09:03:42 +00:00
{
2010-12-15 12:13:18 +00:00
struct dummy_mref_aspect *ini = (void*)_ini;
2010-08-08 09:03:42 +00:00
(void)ini;
}
2010-07-23 11:55:18 +00:00
MARS_MAKE_STATICS(dummy);
2010-06-22 13:21:42 +00:00
////////////////////// brick constructors / destructors ////////////////////
2010-06-14 14:27:40 +00:00
2011-03-31 16:16:00 +00:00
static
int dummy_brick_construct(struct dummy_brick *brick)
2010-06-14 14:27:40 +00:00
{
2011-02-23 20:48:06 +00:00
//brick->my_own = 0;
return 0;
}
2011-03-31 16:16:00 +00:00
static
int dummy_brick_destruct(struct dummy_brick *brick)
2011-02-23 20:48:06 +00:00
{
2010-06-14 14:27:40 +00:00
return 0;
}
2011-03-31 16:16:00 +00:00
static
int dummy_output_construct(struct dummy_output *output)
2010-06-14 14:27:40 +00:00
{
2011-02-23 20:48:06 +00:00
//output->my_own = 0;
return 0;
}
2011-03-31 16:16:00 +00:00
static
int dummy_output_destruct(struct dummy_output *output)
2011-02-23 20:48:06 +00:00
{
2010-06-14 14:27:40 +00:00
return 0;
}
///////////////////////// static structs ////////////////////////
2011-03-31 16:16:00 +00:00
static
struct dummy_brick_ops dummy_brick_ops = {
2011-02-23 20:48:06 +00:00
.brick_switch = dummy_switch,
2011-03-31 16:16:00 +00:00
.brick_statistics = dummy_statistics,
.reset_statistics = dummy_reset_statistics,
2010-06-14 14:27:40 +00:00
};
2011-03-31 16:16:00 +00:00
static
struct dummy_output_ops dummy_output_ops = {
2010-07-07 14:09:16 +00:00
.mars_get_info = dummy_get_info,
2010-12-15 12:13:18 +00:00
.mref_get = dummy_ref_get,
.mref_put = dummy_ref_put,
.mref_io = dummy_ref_io,
2010-06-14 14:27:40 +00:00
};
2010-08-10 17:39:30 +00:00
const struct dummy_input_type dummy_input_type = {
2010-06-14 14:27:40 +00:00
.type_name = "dummy_input",
.input_size = sizeof(struct dummy_input),
};
2011-03-31 16:16:00 +00:00
static
const struct dummy_input_type *dummy_input_types[] = {
2010-06-14 14:27:40 +00:00
&dummy_input_type,
};
2010-08-10 17:39:30 +00:00
const struct dummy_output_type dummy_output_type = {
2010-06-14 14:27:40 +00:00
.type_name = "dummy_output",
.output_size = sizeof(struct dummy_output),
.master_ops = &dummy_output_ops,
.output_construct = &dummy_output_construct,
2011-02-23 20:48:06 +00:00
.output_destruct = &dummy_output_destruct,
2010-06-14 14:27:40 +00:00
};
2011-03-31 16:16:00 +00:00
static
const struct dummy_output_type *dummy_output_types[] = {
2010-06-14 14:27:40 +00:00
&dummy_output_type,
};
2010-07-23 11:55:18 +00:00
const struct dummy_brick_type dummy_brick_type = {
2010-06-14 14:27:40 +00:00
.type_name = "dummy_brick",
.brick_size = sizeof(struct dummy_brick),
.max_inputs = 1,
.max_outputs = 1,
.master_ops = &dummy_brick_ops,
.aspect_types = dummy_aspect_types,
2010-06-14 14:27:40 +00:00
.default_input_types = dummy_input_types,
.default_output_types = dummy_output_types,
.brick_construct = &dummy_brick_construct,
2011-02-23 20:48:06 +00:00
.brick_destruct = &dummy_brick_destruct,
2010-06-14 14:27:40 +00:00
};
EXPORT_SYMBOL_GPL(dummy_brick_type);
////////////////// module init stuff /////////////////////////
int __init init_mars_dummy(void)
2010-06-14 14:27:40 +00:00
{
2011-02-23 20:48:06 +00:00
MARS_INF("init_dummy()\n");
2010-06-14 14:27:40 +00:00
return dummy_register_brick_type();
}
2014-04-23 11:16:26 +00:00
void exit_mars_dummy(void)
2010-06-14 14:27:40 +00:00
{
2011-02-23 20:48:06 +00:00
MARS_INF("exit_dummy()\n");
2010-06-14 14:27:40 +00:00
dummy_unregister_brick_type();
}