This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
FWD: Re: [ECOS] Accessing config parameters in define_proc code
- From: Andrew Lunn <andrew dot lunn at ascom dot ch>
- To: Bart Veer <bartv at ecoscentric dot com>
- Cc: eCos Patches <ecos-patches at sources dot redhat dot com>
- Date: Tue, 5 Nov 2002 18:03:28 +0100
- Subject: FWD: Re: [ECOS] Accessing config parameters in define_proc code
> To: andrew.lunn@ascom.ch
> Cc: gthomas@ecoscentric.com, ecos-discuss@sources.redhat.com
> Subject: Re: [ECOS] Accessing config parameters in define_proc code
> From: Bart Veer <bartv@ecoscentric.com>
> Date: Thu, 31 Oct 2002 21:26:04 +0000 (GMT)
>
> >>>>> "Andrew" == Andrew Lunn <andrew.lunn@ascom.ch> writes:
>
> >> I'm sure that Bart will correct me if I'm wrong, but I'm pretty
> >> sure that the ability to use CDL variables like this was never
> >> implemented.
> >>
>
> Andrew> I think you are right. I found some documentation i didn't
> Andrew> know existed. host/libcdl/doc/*.sgml.
>
> That is the Component Writer's Guide, which I think is still the
> single largest piece of documentation in eCos. How could you miss it?
>
> Andrew> It says this is not implemented :-(
>
> Unfortunately true, like many things it is on the TODO list.
Hi Bart
I finally got my head around enough of the libcdl concepts to make a
stab at implementing this. Please can you take a look at this
patch. Is this the correct way to do it? It works. Unbelievably, it
even worked first time!
Thanks
Andrew
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/host/libcdl/ChangeLog,v
retrieving revision 1.22
diff -u -r1.22 ChangeLog
--- ChangeLog 21 Sep 2002 22:05:08 -0000 1.22
+++ ChangeLog 5 Nov 2002 16:56:44 -0000
@@ -1,3 +1,9 @@
+2002-11-05 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * build.cxx, cdlcore.hxx: Add TCL commands get_value, is_enabled,
+ is_active and is_loaded which can be used in a define_proc tcl
+ script.
+
2002-09-21 Bart Veer <bartv@ecoscentric.com>
* cdlcore.hxx, cdl.hxx, build.cxx, component.cxx, config.cxx,
Index: build.cxx
===================================================================
RCS file: /cvs/ecos/ecos/host/libcdl/build.cxx,v
retrieving revision 1.7
diff -u -r1.7 build.cxx
--- build.cxx 21 Sep 2002 22:05:08 -0000 1.7
+++ build.cxx 5 Nov 2002 16:56:45 -0000
@@ -1516,6 +1516,174 @@
}
//}}}
+//{{{ Commands that can be used inside define_proc scripts
+
+// Help functions for commands. Validate the parameters, check the
+// option exists and return its Node/Valuable.
+
+static CdlNode get_node(CdlInterpreter interp, int argc, const char* argv[]) {
+
+ CYG_REPORT_FUNCNAMETYPE("get_node", "result %x");
+ CYG_PRECONDITION_CLASSC(interp);
+
+ CdlToplevel toplevel = interp->get_toplevel();
+ CYG_ASSERT_CLASSC(toplevel);
+
+ CdlNode node;
+
+ node = toplevel->lookup(argv[1]);
+ CYG_REPORT_RETVAL(node);
+ return node;
+}
+
+static CdlValuable get_valuable(CdlInterpreter interp, int argc, const char* argv[])
+{
+ CYG_REPORT_FUNCNAMETYPE("get_valuable", "result %x");
+ CYG_PRECONDITION_CLASSC(interp);
+
+ CdlValuable valuable = NULL;
+ CdlNode node = get_node(interp, argc, argv);
+
+ if (0 == node) {
+ CdlParse::report_error(interp, "",
+ std::string("Option `")
+ + argv[1] +
+ "'is unknown.");
+ } else {
+ valuable = dynamic_cast<CdlValuable>(node);
+ if ( 0 == valuable) {
+ CdlParse::report_error(interp, "",
+ std::string("Option `")
+ + argv[1] +
+ "'cannot have a value.");
+ }
+ }
+
+ CYG_REPORT_RETVAL(valuable);
+ return valuable;
+}
+
+int
+CdlDefinableBody::do_get_data(CdlInterpreter interp, int argc, const char* argv[])
+{
+ CYG_REPORT_FUNCNAMETYPE("do_get_data", "result %d");
+ CYG_PRECONDITION_CLASSC(interp);
+
+ int result = TCL_ERROR;
+ std::string diag_argv0 = CdlParse::get_tcl_cmd_name(argv[0]);
+
+ if (2 != argc) {
+ CdlParse::report_error(interp, "",
+ std::string("Incorrect number of args to '")
+ + diag_argv0 +
+ "'\nExpected option.");
+ } else {
+ CdlValuable valuable = get_valuable(interp, argc, argv);
+
+ if (valuable) {
+ interp->set_result(valuable->get_value());
+ result = TCL_OK;
+ }
+ }
+ CYG_REPORT_RETVAL(result);
+ return result;
+}
+
+int
+CdlDefinableBody::do_is_active(CdlInterpreter interp, int argc, const char* argv[])
+{
+ CYG_REPORT_FUNCNAMETYPE("do_is_active", "result %d");
+ CYG_PRECONDITION_CLASSC(interp);
+
+ int result = TCL_ERROR;
+ std::string diag_argv0 = CdlParse::get_tcl_cmd_name(argv[0]);
+
+ if (2 != argc) {
+ CdlParse::report_error(interp, "",
+ std::string("Incorrect number of args to '")
+ + diag_argv0 +
+ "'\nExpected option.");
+ } else {
+ CdlNode node = get_node(interp, argc, argv);
+
+ if (0 == node) {
+ CdlParse::report_error(interp, "",
+ std::string("Option `")
+ + argv[1] +
+ "'is unknown.");
+ } else {
+ if (node->is_active()) {
+ interp->set_result(std::string("1"));
+ } else {
+ interp->set_result(std::string("0"));
+ }
+ result = TCL_OK;
+ }
+ }
+
+ CYG_REPORT_RETVAL(result);
+ return result;
+}
+
+int
+CdlDefinableBody::do_is_enabled(CdlInterpreter interp, int argc, const char* argv[])
+{
+ CYG_REPORT_FUNCNAMETYPE("do_is_enabled", "result %d");
+ CYG_PRECONDITION_CLASSC(interp);
+
+ int result = TCL_ERROR;
+ std::string diag_argv0 = CdlParse::get_tcl_cmd_name(argv[0]);
+
+ if (2 != argc) {
+ CdlParse::report_error(interp, "",
+ std::string("Incorrect number of args to '")
+ + diag_argv0 +
+ "'\nExpected option.");
+ } else {
+ CdlValuable valuable = get_valuable(interp, argc, argv);
+
+ if (valuable) {
+ if (valuable->is_enabled()) {
+ interp->set_result(std::string("1"));
+ } else {
+ interp->set_result(std::string("0"));
+ }
+ result = TCL_OK;
+ }
+ }
+
+ CYG_REPORT_RETVAL(result);
+ return result;
+}
+
+int
+CdlDefinableBody::do_is_loaded(CdlInterpreter interp, int argc, const char* argv[])
+{
+ CYG_REPORT_FUNCNAMETYPE("do_is_loaded", "result %d");
+ CYG_PRECONDITION_CLASSC(interp);
+
+ int result = TCL_ERROR;
+ std::string diag_argv0 = CdlParse::get_tcl_cmd_name(argv[0]);
+
+ if (2 != argc) {
+ CdlParse::report_error(interp, "",
+ std::string("Incorrect number of args to '")
+ + diag_argv0 +
+ "'\nExpected option.");
+ } else {
+ CdlNode node = get_node(interp, argc, argv);
+ if (node) {
+ interp->set_result(std::string("1"));
+ } else {
+ interp->set_result(std::string("0"));
+ }
+ result = TCL_OK;
+ }
+
+ CYG_REPORT_RETVAL(result);
+ return result;
+}
+//}}}
//{{{ generate_config_header()
// ----------------------------------------------------------------------------
@@ -1674,7 +1842,24 @@
}
// And define_proc properties
+ std::vector<CdlInterpreterCommandEntry> new_commands;
+ std::vector<CdlInterpreterCommandEntry>* old_commands = 0;
+ static CdlInterpreterCommandEntry commands[] =
+ {
+ CdlInterpreterCommandEntry("get_value", &CdlDefinableBody::do_get_data),
+ CdlInterpreterCommandEntry("is_active", &CdlDefinableBody::do_is_active),
+ CdlInterpreterCommandEntry("is_enabled", &CdlDefinableBody::do_is_enabled),
+ CdlInterpreterCommandEntry("is_loaded", &CdlDefinableBody::do_is_loaded),
+ CdlInterpreterCommandEntry("", 0 ),
+ };
+ int i;
+
+ for (i = 0; 0 != commands[i].command; i++) {
+ new_commands.push_back(commands[i]);
+ }
+ old_commands = interp->push_commands(new_commands);
std::vector<CdlProperty> define_proc_props;
+
get_properties(CdlPropertyId_DefineProc, define_proc_props);
for (prop_i = define_proc_props.begin(); prop_i != define_proc_props.end(); prop_i++) {
CdlProperty_TclCode codeprop = dynamic_cast<CdlProperty_TclCode>(*prop_i);
@@ -1686,7 +1871,7 @@
throw CdlInputOutputException("Error evaluating define_proc property for " + name + "\n" + result);
}
}
-
+ interp->pop_commands(old_commands);
CYG_REPORT_RETURN();
}
Index: cdlcore.hxx
===================================================================
RCS file: /cvs/ecos/ecos/host/libcdl/cdlcore.hxx,v
retrieving revision 1.9
diff -u -r1.9 cdlcore.hxx
--- cdlcore.hxx 21 Sep 2002 22:05:09 -0000 1.9
+++ cdlcore.hxx 5 Nov 2002 16:56:47 -0000
@@ -5565,6 +5565,13 @@
static int parse_if_define(CdlInterpreter, int, const char*[]);
static int parse_no_define(CdlInterpreter, int, const char*[]);
+ // Commands to access valuable nodes objects from within TCL
+ // define_proc code
+ static int do_get_data(CdlInterpreter, int, const char*[]);
+ static int do_is_active(CdlInterpreter, int, const char*[]);
+ static int do_is_enabled(CdlInterpreter, int, const char*[]);
+ static int do_is_loaded(CdlInterpreter, int, const char*[]);
+
virtual std::string get_class_name() const;
bool check_this(cyg_assert_class_zeal = cyg_quick) const;
CYGDBG_DECLARE_MEMLEAK_COUNTER();