[powerdebug,13/22] Encapsulate the display (6)

Message ID 1308145856-6112-13-git-send-email-daniel.lezcano@linaro.org
State Accepted
Headers show

Commit Message

Daniel Lezcano June 15, 2011, 1:50 p.m.
Let's create some ops to be registered by the pm blocks to the display.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 clocks.c    |   53 +++++++++++++++++++++++++++++++----------------------
 display.c   |   11 +++++++++++
 display.h   |    7 ++++++-
 regulator.c |    8 ++++++++
 sensor.c    |    8 ++++++++
 5 files changed, 64 insertions(+), 23 deletions(-)

Patch

diff --git a/clocks.c b/clocks.c
index db219d8..86ae948 100644
--- a/clocks.c
+++ b/clocks.c
@@ -26,6 +26,7 @@ 
 #include <sys/stat.h>
 
 #include "powerdebug.h"
+#include "display.h"
 #include "clocks.h"
 #include "tree.h"
 #include "utils.h"
@@ -306,28 +307,6 @@  int clock_toggle_expanded(void)
 }
 
 /*
- * Initialize the clock framework
- */
-int clock_init(void)
-{
-	char clk_dir_path[PATH_MAX];
-
-	if (locate_debugfs(clk_dir_path))
-		return -1;
-
-	sprintf(clk_dir_path, "%s/clock", clk_dir_path);
-
-	if (access(clk_dir_path, F_OK))
-		return -1;
-
-	clock_tree = tree_load(clk_dir_path, NULL);
-	if (!clock_tree)
-		return -1;
-
-	return fill_clock_tree();
-}
-
-/*
  * Read the clock information and fill the tree with the information
  * found in the files. Then print the result to the text based interface
  * Return 0 on success, < 0 otherwise
@@ -366,3 +345,33 @@  int clock_dump(char *clk)
 
 	return ret;
 }
+
+static struct display_ops clock_ops = {
+	.display = clock_display,
+	.select  = clock_toggle_expanded,
+};
+
+/*
+ * Initialize the clock framework
+ */
+int clock_init(void)
+{
+	char clk_dir_path[PATH_MAX];
+
+	if (display_register(CLOCK, &clock_ops))
+		return -1;
+
+	if (locate_debugfs(clk_dir_path))
+		return -1;
+
+	sprintf(clk_dir_path, "%s/clock", clk_dir_path);
+
+	if (access(clk_dir_path, F_OK))
+		return -1;
+
+	clock_tree = tree_load(clk_dir_path, NULL);
+	if (!clock_tree)
+		return -1;
+
+	return fill_clock_tree();
+}
diff --git a/display.c b/display.c
index 384714b..d55d748 100644
--- a/display.c
+++ b/display.c
@@ -49,6 +49,7 @@  struct rowdata {
 struct windata {
 	WINDOW *win;
 	WINDOW *pad;
+	struct display_ops *ops;
 	struct rowdata *rowdata;
 	char *name;
 	int nrdata;
@@ -207,6 +208,16 @@  void print_sensor_header(void)
 	show_header_footer(SENSOR);
 }
 
+int display_register(int win, struct display_ops *ops)
+{
+	if (win < 0 || win >= TOTAL_FEATURE_WINS)
+		return -1;
+
+	windata[win].ops = ops;
+
+	return 0;
+}
+
 int display_next_panel(void)
 {
 	current_win++;
diff --git a/display.h b/display.h
index 9c0e38a..1222b44 100644
--- a/display.h
+++ b/display.h
@@ -13,8 +13,13 @@ 
  *       - initial API and implementation
  *******************************************************************************/
 
-extern int display_init(int wdefault);
+struct display_ops {
+	int (*display)(void);
+	int (*select)(void);
+};
 
+extern int display_init(int wdefault);
+extern int display_register(int win, struct display_ops *ops);
 extern int display_next_panel(void);
 extern int display_prev_panel(void);
 extern int display_next_line(void);
diff --git a/regulator.c b/regulator.c
index d4b41e1..4b9d36e 100644
--- a/regulator.c
+++ b/regulator.c
@@ -26,6 +26,7 @@ 
 #include <dirent.h>
 #include <string.h>
 #include <stdlib.h>
+#include "display.h"
 #include "powerdebug.h"
 #include "tree.h"
 #include "utils.h"
@@ -209,8 +210,15 @@  static int fill_regulator_tree(void)
 	return tree_for_each(reg_tree, fill_regulator_cb, NULL);
 }
 
+static struct display_ops regulator_ops = {
+	.display = regulator_display,
+};
+
 int regulator_init(void)
 {
+	if (display_register(REGULATOR, &regulator_ops))
+		return -1;
+
 	reg_tree = tree_load(SYSFS_REGULATOR, regulator_filter_cb);
 	if (!reg_tree)
 		return -1;
diff --git a/sensor.c b/sensor.c
index 9c97e72..db58137 100644
--- a/sensor.c
+++ b/sensor.c
@@ -23,6 +23,7 @@ 
 #include <stdlib.h>
 
 #include "powerdebug.h"
+#include "display.h"
 #include "sensor.h"
 #include "tree.h"
 #include "utils.h"
@@ -249,8 +250,15 @@  int sensor_display(void)
 	return ret;
 }
 
+static struct display_ops sensor_ops = {
+	.display = sensor_display,
+};
+
 int sensor_init(void)
 {
+	if (display_register(SENSOR, &sensor_ops))
+		return -1;
+
 	sensor_tree = tree_load(SYSFS_SENSOR, sensor_filter_cb);
 	if (!sensor_tree)
 		return -1;