Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Real-Time Software Components (RTSC) » How to access instance field of module?
How to access instance field of module? [message #541385] Sun, 20 June 2010 15:05 Go to next message
Tomasz  is currently offline Tomasz
Messages: 5
Registered: March 2010
Junior Member
Hello everyone,

I'm completely new in RTSC world. What I'm trying to do is to get access to variable defined in module from other module. Here is an example:

------------------------------------------------------------ -------------------------------
module ModA {
instance:
config Int A;
...
}
------------------------------------------------------------ ------------------------------
import ModA
module ModB{
Void doSth(ModA.Handle hModA)
...
}
------------------------------------------------------------ ---------------------------
Void ModB_doSth(ModA_Handle hModA)
{
Int B = hModA->A;
}

Everytime I try to compile package I get compilation error in ModB_doSth:

"pointer to incomplete class not allowed"

My question is: how to create the public field, in instance module, that I could reach using handle?

Thank You for any suggestions.

[Updated on: Mon, 21 June 2010 06:18]

Report message to a moderator

Re: How to access instance field of module? [message #541592 is a reply to message #541385] Mon, 21 June 2010 13:02 Go to previous messageGo to next message
Sasha Slijepcevic is currently offline Sasha Slijepcevic
Messages: 86
Registered: July 2009
Member
Tomasz,
in your example A is an instance configuration parameter, therefore its purpose is to be used when initializing an instance. If you need an instance property that is accessed throughout the lifetime of the instance, then you have to define Instance_State.

------------------------------------------------------------
module ModA {
instance:
    config Int initA;
internal:

    struct Instance_State {
        Int stateA;
    }
}

------------------------------------------------------------

Now, a function in ModB can access stateA:
------------------------------------------------------------
Void ModB_doSth(ModA_Handle hModA) 
{
    Int B = hModA->stateA;
}

------------------------------------------------------------

For all that to work properly, ModA needs Instance_init function that initializes Instance_State, when an instance is created:
Void ModA_Instance_init(ModA_Object *obj, const ModA_Params *params)
{
    obj->stateA = params->initA;
}


There is an example in RTSC Module Primer that describes in more details how to create and use instances:
http://rtsc.eclipse.org/docs-tip/RTSC_Module_Primer/Lesson_8

You may want to read the whole primer for better understanding of some concepts used in that lesson:
http://rtsc.eclipse.org/docs-tip/RTSC_Module_Primer
Re: How to access instance field of module? [message #541601 is a reply to message #541592] Mon, 21 June 2010 14:07 Go to previous messageGo to next message
Tomasz  is currently offline Tomasz
Messages: 5
Registered: March 2010
Junior Member
Sasha,

Thank You for reply, I did it exactly as You described, but still, even though I put my variable into Instance_State structure when I try to access the field in this structure I get always the same error, during building the package:

"pointer to incomplete class type not allowed"

It seems like I can access ModA Instance_State only within ModA.c file. When I try do the same from other module it crashes. So for now I need to write something like :
module ModA {
instance:
    config Int initA;
    create();
    Int getA();
internal:

    struct Instance_State {
        Int stateA;
    }
}



Int ModA_getA(ModA_Object  *moda)
{
     return (moda->stateA);
}


And I can access stateA only using the function ModA_getA. But actually, I need the access to the different instance module constatntly in the loop and calling the function, in lieu of direct call, would increase unnecessarily number of cycles.
Re: How to access instance field of module? [message #541648 is a reply to message #541601] Mon, 21 June 2010 18:54 Go to previous messageGo to next message
Sasha Slijepcevic is currently offline Sasha Slijepcevic
Messages: 86
Registered: July 2009
Member
Tomasz,
in my initial answer I was paying more attention to the separation between the config parameter and the internal state variable, so I incorrectly assumed direct access into the internal state of an instance. You do have to have a function that exposes an internal state field.

Such a solution does look less than optimal, but allows the internal state structure to be changed without breaking the public API.
Then, if you are building with RTSC targets that support whole-program optimization (TI targets do), the compiler will be able to recognize that the function simply returns a structure field and to optimize that code.

Here is the link to a short description of profiles:
http://rtsc.eclipse.org/cdoc-tip/xdc/bld/ITarget.html#profil es

Here is an example where the profile "whole_program" is used to build to build an executable:
http://rtsc.eclipse.org/docs-tip/RTSC_Interface_Primer/Lesso n_14
Re: How to access instance field of module? [message #541651 is a reply to message #541648] Mon, 21 June 2010 19:37 Go to previous message
Tomasz  is currently offline Tomasz
Messages: 5
Registered: March 2010
Junior Member
OK, that helped me a lot. Thank You!
Previous Topic:Release notification for XDCtools 3.16.04
Next Topic:solution for factory
Goto Forum:
  


Current Time: Mon Sep 01 03:37:05 EDT 2014

Powered by FUDForum. Page generated in 0.01829 seconds