Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
Global Library scope?
This thread has 7 replies. Displaying all posts.
Post 1 made on Thursday July 15, 2010 at 17:30
pnnielsen
Long Time Member
Joined:
Posts:
February 2010
37
Is it possible to include a library globally as one single instance that can be used by all activities?

It seems like this is not possible. When adding a library globally (to the system properties), it seems that each activity still creates its own instance of the library. Is this correct?

Thanks,
Peter

Last edited by pnnielsen on July 15, 2010 17:54.
Post 2 made on Thursday July 15, 2010 at 19:03
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Unfortunately, there is no shared scope across activities. Upon entry into each activity, the ECMA/Javascript engine is started. Upon exit from the activity, the engine is stopped. To overcome this, use System.setGlobal/getGlobal.

Rusty Fobe has been nice enough to upload some utility scripts in the files section that let you save/restore object trees. Also note that this is basically what JSON (Javascript Object Notation) does as well.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 3 made on Thursday July 15, 2010 at 19:24
pnnielsen
Long Time Member
Joined:
Posts:
February 2010
37
At this point, I'm trying to understand how it works so that I can do things right and in the best possible way.

Are you implying that I *can* create one instance of the object and share it with System.setGlobal? I did try this, but it does not seem to work...

I do realize that I can use setGlobal to set global settings and use getGlobal in the library to retrieve settings & data, making it easy to use the library. This will probably work out fine for my needs, but *if* there is a way to just create one instance and use it, that would of course be ideal...

Save/restore object trees? Do I understand correctly: does this mean the same as saving all instance specific data and then letting you apply the data onto another instance of the same type? Correct? (I'm not familiar with JSON - yet).

Thanks,
Peter
Post 4 made on Thursday July 15, 2010 at 23:11
buzz
Super Member
Joined:
Posts:
May 2003
4,366
You can use the PS Libraries feature of PEP2 to copy text into activities. While this is not a global scope, at least you don't need to copy the text into each activity after you make a change.

Since I program units for multiple customers, this can be both an advantage and a disadvantage because the PS Libraries code is public. This means that if I make a library change down the road, older programs might break. I must carefully track my changes.

Another technique is to store the code in a label, probably on a page in the Home activity and execute that code as required in each activity. This can be a very powerful technique because the execute can be conditional. I've used this technique to flip an activity between IR and RS-232.

Finally, you could use the "include" statement. This is similar to the library concept, but the file name can be dynamic. In my case I could use a custom file for each customer.
Post 5 made on Thursday July 15, 2010 at 23:59
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
On July 15, 2010 at 19:24, pnnielsen said...
At this point, I'm trying to understand how it works so that I can do things right and in the best possible way.

Are you implying that I *can* create one instance of the object and share it with System.setGlobal? I did try this, but it does not seem to work...

No, I'm saying that you can create an object, use Rusty's utilities to convert said object to a string (or use Javascript toSource() function - see mozilla site) and the store into System global as string. You can then convert back to an object using:

var myObj = eval(System.getGlobal('MySavedObject'));
I do realize that I can use setGlobal to set global settings and use getGlobal in the library to retrieve settings & data, making it easy to use the library. This will probably work out fine for my needs, but *if* there is a way to just create one instance and use it, that would of course be ideal...

Save/restore object trees? Do I understand correctly: does this mean the same as saving all instance specific data and then letting you apply the data onto another instance of the same type? Correct? (I'm not familiar with JSON - yet).

I was explictily referring to Save/restore of an object tree. That is, saving a top-level object that contains fields referring to other objects and so on. It's called an Object Tree as it looks like an upside down tree when object references are drawn as a graph.

Thanks,
Peter
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 6 made on Friday July 16, 2010 at 00:09
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Also, have you reviewed the sections in the latest Dev Guide and the previous Dev Guide that discuss scope? You might find those sections interesting.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 7 made on Friday July 16, 2010 at 06:22
pnnielsen
Long Time Member
Joined:
Posts:
February 2010
37
Great, that answers all my questions. Thanks Lyndel! Now I fully understand what can be done. Converting the object to a string (isn't this called serializing?) makes perfect sense!

I have the 1.3.9 dev. guide (is there a newer one?) and I have read those sections. The dev guide does not seem to directly touch the topic I brought up here though.

Thanks,
Peter
Post 8 made on Friday July 16, 2010 at 08:13
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
On July 16, 2010 at 06:22, pnnielsen said...
Great, that answers all my questions. Thanks Lyndel! Now I fully understand what can be done. Converting the object to a string (isn't this called serializing?) makes perfect sense!

Serializing/Deserializing
I have the 1.3.9 dev. guide (is there a newer one?) and I have read those sections. The dev guide does not seem to directly touch the topic I brought up here though.

Your topic is somewhat discussed in Section 6.2.3 (I still use early draft version so section # may not be correct), specifically in the section Levels, scope, and lifetime. The 'Global' scope was added as a mechanism to load common scripts prior to creating the Activity scope simply as a convenience. All scopes are destroyed upon exiting an activity and only System Globals persist across activities.

There was an older Dev Guide (Previous firmware) that had a different style of presenting the scope topic and would have also been more illustrative with regard to background/history of what was available before Global. However, upon further review, it is no longer available in the Files section.
Thanks,
Peter

Last edited by Lyndel McGee on July 16, 2010 08:43.
Lyndel McGee
Philips Pronto Addict/Beta Tester


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse