Shop OBEX P1 Docs P2 Docs Learn Events
Sharing Objects — Parallax Forums

Sharing Objects

ClaytronClaytron Posts: 6
edited 2007-04-21 04:41 in Propeller 1
I'm working in the planning stage for an application I'm about to write for the Propeller. This will be my first major Propeller project. I intend to two have two cogs running at all times. Upon execution, the main controller object spawns another one that's an input monitor object. They both need to access methods in a separate functionality controller. It's most important to the input monitor, so I was originally planning to have it as a child of that object, but the main cog needs it as well... what is the tidiest way to have the functionality object's methods available to both objects? Thanks for your thoughts.

Comments

  • CJCJ Posts: 470
    edited 2007-04-21 02:21
    as long as there isn't any contention for VARs/DAT or IO output, you can declare it in both objects without too much trouble.

    if there is, you need to have some way to keep order and only one cog at a time accessing it

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-21 02:26
    There are two ways to do this. One is to have the functionality controller be a child of the input monitor object and to have access functions declared in the input monitor object that just pass control to the functionality controller methods. You could use the same names and they'd all consist of just two lines like:
    obj func : "Functionality Controller"
    
    pub function1(x,y)
       return func.function1(x,y)
    
    pub function2(x)
       return func.function2(x)
    
    


    ... and so on.

    The second technique requires that any global variables in the functionality controller are in a DAT section and there's no VAR section. You declare this child object in both the main program and the input monitor. The code and DAT section(s) are the same for both instances.
  • ClaytronClaytron Posts: 6
    edited 2007-04-21 04:41
    Thanks for the quick response. I'll have to think this one over a bit to see which makes more sense. Much appreciated. So basically as long as the data that the functionality controller uses doesn't need modification then, then it can be a subclass of both without contention?

    Post Edited (Claytron) : 4/21/2007 4:48:18 AM GMT
Sign In or Register to comment.