Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Real-Time Software Components (RTSC) » When can a module configure itself?
When can a module configure itself? [message #1548] Thu, 26 February 2009 18:56 Go to next message
Ramsey Harris is currently offline Ramsey HarrisFriend
Messages: 22
Registered: July 2009
Junior Member
Champs,

Reading the documentation for module$static$init() it states that changes to the configuration are *not* allowed. Indeed, if I attempt to change the following config param, I get an error.

config Int foobar = 0;

module$static$init(state, mod)
{
mod.foobar = 7;
}

error: ti.sdo.rcm.RCM: 'foobar' is sealed


However, I also have an array config param. It seems that I can change the elements of the array in module$static$init().

config UInt16 heapIdAry[length] = [];

app.cfg
RCM.heapIdAry.length = 4;
RCM.heapIdAry[1] = 2;

module$static$init(state, mod)
{
/* fill out the heapIdAry (undefined not allowed) */
for (var i = 0; i < mod.heapIdAry.length; i++) {
if (mod.heapIdAry[i] == undefined) {
mod.heapIdAry[i] = mod.INVALIDHEAPID;
}
}
}

In the app.cfg script, I set the array length to 4 but only initialize the second element. In module$static$init(), I initialize all undefined array elements. Is this allowed or a loophole?

If its a loophole, where should I be filling out the heapIdAry?

I'm looking at the following link which defines the order of evaluation.

http://rtsc.eclipse.org/docs-tip/Creating_Configurable_Conte nt

It seems I have three choices:

1. module$meta$init()
2. module$static$init()
3. module$use()

I cannot do this in module$meta$init() because the app.cfg script has not yet had a chance to set the array length.

The function module$static$init() runs in phase 4 which should not allow configuration changes.

If I do this in module$use() all is well if the array length was set in app.cfg because the call to module$use() is deferred (to phase 3) until after the app.cfg script completes. But if my module is loaded after the app.cfg script (say from an xdc.useModule() called in some package during phase 3, then my module$use() will run immediately before the calling package has had a chance to set the array length. To avoid this, the calling package would need to first call xdc.module(), set the heapIdAry config param, then call xdc.useModule().

var RCM = xdc.module('ti.sdo.rcm.RCM'); // just get a reference
var base = RCM.heapIdAry.length;
RCM.heapIdAry.length += 4
RCM.heapIdAry[base + 1] = 2;
xdc.useModule('ti.sdo.rcm.RCM'); // now mark it used

What happens if heapIdAry is set both in the app.cfg script and by another module during phase 3? Will RCM.module$use() be called twice?

What happens if yet another package also uses the RCM module? Is RCM.module$use() called again?

In short, where can a module finish configuring itself after all other clients have run?

Thanks
~ Ramsey
Re: When can a module configure itself? [message #1563 is a reply to message #1548] Fri, 27 February 2009 00:25 Go to previous messageGo to next message
Bob Frankel is currently offline Bob FrankelFriend
Messages: 10
Registered: July 2009
Junior Member
there has been some discussion about "deferring" calls to module$use in
phase 3, to all clients the opportunity to configure them fully....

sasa should weigh in on this point....

Ramsey Harris wrote:
> Champs,
>
> Reading the documentation for module$static$init() it states that
> changes to the configuration are *not* allowed. Indeed, if I attempt to
> change the following config param, I get an error.
>
> config Int foobar = 0;
>
> module$static$init(state, mod)
> {
> mod.foobar = 7;
> }
>
> error: ti.sdo.rcm.RCM: 'foobar' is sealed
>
>
> However, I also have an array config param. It seems that I can change
> the elements of the array in module$static$init().
>
> config UInt16 heapIdAry[length] = [];
>
> app.cfg
> RCM.heapIdAry.length = 4;
> RCM.heapIdAry[1] = 2;
>
> module$static$init(state, mod)
> {
> /* fill out the heapIdAry (undefined not allowed) */
> for (var i = 0; i < mod.heapIdAry.length; i++) {
> if (mod.heapIdAry[i] == undefined) {
> mod.heapIdAry[i] = mod.INVALIDHEAPID;
> }
> }
> }
>
> In the app.cfg script, I set the array length to 4 but only initialize
> the second element. In module$static$init(), I initialize all undefined
> array elements. Is this allowed or a loophole?
>
> If its a loophole, where should I be filling out the heapIdAry?
>
> I'm looking at the following link which defines the order of evaluation.
>
> http://rtsc.eclipse.org/docs-tip/Creating_Configurable_Conte nt
>
> It seems I have three choices:
>
> 1. module$meta$init()
> 2. module$static$init()
> 3. module$use()
>
> I cannot do this in module$meta$init() because the app.cfg script has
> not yet had a chance to set the array length.
>
> The function module$static$init() runs in phase 4 which should not allow
> configuration changes.
>
> If I do this in module$use() all is well if the array length was set in
> app.cfg because the call to module$use() is deferred (to phase 3) until
> after the app.cfg script completes. But if my module is loaded after the
> app.cfg script (say from an xdc.useModule() called in some package
> during phase 3, then my module$use() will run immediately before the
> calling package has had a chance to set the array length. To avoid this,
> the calling package would need to first call xdc.module(), set the
> heapIdAry config param, then call xdc.useModule().
>
> var RCM = xdc.module('ti.sdo.rcm.RCM'); // just get a reference
> var base = RCM.heapIdAry.length;
> RCM.heapIdAry.length += 4
> RCM.heapIdAry[base + 1] = 2;
> xdc.useModule('ti.sdo.rcm.RCM'); // now mark it used
>
> What happens if heapIdAry is set both in the app.cfg script and by
> another module during phase 3? Will RCM.module$use() be called twice?
>
> What happens if yet another package also uses the RCM module? Is
> RCM.module$use() called again?
>
> In short, where can a module finish configuring itself after all other
> clients have run?
>
> Thanks
> ~ Ramsey
Re: When can a module configure itself? [message #1876 is a reply to message #1548] Mon, 16 March 2009 18:46 Go to previous message
Sasha Slijepcevic is currently offline Sasha SlijepcevicFriend
Messages: 90
Registered: July 2009
Member
Ramsey,
at the time module$static$init runs, all config parameters should be
sealed, but it seems that there is loophole for array elements. So, these
elements should be finalized somewhere else, unless you put that array in
the module state, and define a metaonly array which is filled in during
configuration.
Then, in module$static$init, you copy the initialized values to your
module state array, and set the uninitialized ones to INVALIDHEAPID.

But, in general, there is no really a phase when a module or an instance
can change its config parameters, but no other module will be able to make
another change afterwards. There is no such concept, at least for now.
Either a parameter is sealed, and no one can change it, or anyone can
change it.

I recently made the change in the order of module$use calls after the user
config script. If xdc.useModule is invoked on a module whose package is
not closed yet, we now wait for that package to be closed and only then
the function module$use for the module is called. But, if a module is in
the package that is closed already, and its module$use did not run, the
call to module$use is made immediately. So, depending on other
dependencies between involved packages, module$use can be called
immediately or be delayed. However, module$use is never called twice.

Also, I am wondering if a function access would be more appropriate for a
parameter where a caller cares only about some elements of an array. It
seems that caller only wants to add its values to the array, rather than
specify its length and all values.
You could have a meta function to add values, and in that function, the
module RCM would manage the length.

Sasha

Ramsey Harris wrote:

> Champs,

> Reading the documentation for module$static$init() it states that changes to
the configuration are *not* allowed. Indeed, if I attempt to change the
following config param, I get an error.

> config Int foobar = 0;

> module$static$init(state, mod)
> {
> mod.foobar = 7;
> }

> error: ti.sdo.rcm.RCM: 'foobar' is sealed


> However, I also have an array config param. It seems that I can change the
elements of the array in module$static$init().

> config UInt16 heapIdAry[length] = [];

> app.cfg
> RCM.heapIdAry.length = 4;
> RCM.heapIdAry[1] = 2;

> module$static$init(state, mod)
> {
> /* fill out the heapIdAry (undefined not allowed) */
> for (var i = 0; i < mod.heapIdAry.length; i++) {
> if (mod.heapIdAry[i] == undefined) {
> mod.heapIdAry[i] = mod.INVALIDHEAPID;
> }
> }
> }

> In the app.cfg script, I set the array length to 4 but only initialize the
second element. In module$static$init(), I initialize all undefined array
elements. Is this allowed or a loophole?

> If its a loophole, where should I be filling out the heapIdAry?

> I'm looking at the following link which defines the order of evaluation.

> http://rtsc.eclipse.org/docs-tip/Creating_Configurable_Conte nt

> It seems I have three choices:

> 1. module$meta$init()
> 2. module$static$init()
> 3. module$use()

> I cannot do this in module$meta$init() because the app.cfg script has not
yet had a chance to set the array length.

> The function module$static$init() runs in phase 4 which should not allow
configuration changes.

> If I do this in module$use() all is well if the array length was set in
app.cfg because the call to module$use() is deferred (to phase 3) until after
the app.cfg script completes. But if my module is loaded after the app.cfg
script (say from an xdc.useModule() called in some package during phase 3,
then my module$use() will run immediately before the calling package has had a
chance to set the array length. To avoid this, the calling package would need
to first call xdc.module(), set the heapIdAry config param, then call
xdc.useModule().

> var RCM = xdc.module('ti.sdo.rcm.RCM'); // just get a reference
> var base = RCM.heapIdAry.length;
> RCM.heapIdAry.length += 4
> RCM.heapIdAry[base + 1] = 2;
> xdc.useModule('ti.sdo.rcm.RCM'); // now mark it used

> What happens if heapIdAry is set both in the app.cfg script and by another
module during phase 3? Will RCM.module$use() be called twice?

> What happens if yet another package also uses the RCM module? Is
RCM.module$use() called again?

> In short, where can a module finish configuring itself after all other
clients have run?

> Thanks
> ~ Ramsey
Previous Topic:runtime initialization of statically created and constructed instances
Next Topic:RTSC Packaging Primer examples
Goto Forum:
  


Current Time: Thu Nov 27 16:28:00 GMT 2014

Powered by FUDForum. Page generated in 0.03280 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software