SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-05-2011, 10:15 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Bad idea to modify Widgets from with STV?

I've been thinking about how to make my MultiUser plugin compatible with as many other plugins as possible. One possible way is to dynamically modify the STV widgets using SetWidgetName() during the ApplicationStarting hook (or even in the start() method in the Implementation class), but I'm wondering if this is a bad idea.

In the MultiUser plugin I've created an API that replaces many of the Sage core APIs. For example, instead of using GetFavorites() the STV invokes tmiranda_mus_API_getFavorites(). I did some experiments and it turns out to be very easy to scan all of the Widgets and replace all occurrences of the core API with my methods.

So is it a bad idea to do this? I hope not because if I can get this to work properly I can make the plugin compatible with practically all plugins

Tom
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #2  
Old 03-05-2011, 11:13 AM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
That sort of thing used to be considered perfectly legitimate for an STVI to do in its STVImported hook. People don't implement STVIs that way very much anymore, with all the new tools that have emerged. But in principle it would still be possible. The problem would be making sure your import happened last so you could catch any new widgets introduced by other STVIs.

Obviously that's why you'd rather do it in ApplicationStarted. But I think you'll find that if you do it there, you're going to leave the STV in a dirty state so that it will be constantly prompting the user to save it (which you definitely don't want them doing).

The other thing to consider is that a blanket replace of all uses of GetFavorites() might not be appropriate. There might be legitimate cases where a plugin wants access to all favorites, regardless of who they belong to or who's logged in. (A scheduling plugin might be an example of this.)

On the other hand, there might be calls in Java code that ought to be changed, but you won't be able to find them with a widget-based search-and-replace. This could result in inconsistent behavior in plugins that use a mix of widget and Java code.
__________________
-- Greg
Reply With Quote
  #3  
Old 03-05-2011, 03:11 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Greg,

Thanks for the insights.

If I should not put the code in the ApplicationStarting hook, where should it go? And how do I avoid leaving the STV dirty state or how do I suppress the "STV has been modified" message? If editing Widgets was the "old way" of importing, there must be a way to do it correctly, right?

To avoid "blanket replacements" I planned on using a .properties file with a simple grammar to specify what to replace and where NOT to do the replacement. Then as I find incompatibilities with plugins I can just update the .properties file rather than update the STVi and/or .jar. I'm not sure if this is possible, but it will make an interesting project.

If other plugins call the core API from within their own java code there is nothing I can do about it. I know my system will not be foolproof, but it will work with many plugins (I hope).
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #4  
Old 03-05-2011, 04:19 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Quote:
Originally Posted by tmiranda View Post
If I should not put the code in the ApplicationStarting hook, where should it go? And how do I avoid leaving the STV dirty state or how do I suppress the "STV has been modified" message? If editing Widgets was the "old way" of importing, there must be a way to do it correctly, right?
I believe the only "correct" place to do it without triggering the "save changes" prompt is in the STVImported hook. Under the V6 import model, the merged STV+STVIs did in fact get saved, clearing the dirty status. Under the new V7 model, there's presumably code in the core to clear the dirty status after all plugins have been loaded, but before ApplicationStarted fires. So really your only chance to do it without running afoul of the dirtiness issue is in STVImported. I know that's not a very satisfactory answer, but I think it's probably the best you can do right now without changes in the core.
__________________
-- Greg
Reply With Quote
  #5  
Old 03-05-2011, 07:00 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by GKusnick View Post
I know that's not a very satisfactory answer, but I think it's probably the best you can do right now without changes in the core.
I'd rather hear a correct unsatisfactory answer than an incorrect satisfactory answer
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #6  
Old 03-05-2011, 07:14 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
I took a look at the manual and it says the hook is triggered when an STVi has been imported using the ImportSTVFile() method. I'm going to assume that that's how the Plugin Manager loads STVi's.

I'm thinking I can use that hook to scan the STV each time an STVi is loaded as long as I'm careful not to edit the same widget multiple times. So each time the code is called it will first check the existing STV (to make the changes to the widgets that were loaded before my plugin) and then check the new widgets for things that need to be changed.

It's not real efficient but I think it's worth a shot.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #7  
Old 03-07-2011, 05:05 PM
Narflex's Avatar
Narflex Narflex is offline
Sage
 
Join Date: Feb 2003
Location: Redondo Beach, CA
Posts: 6,349
Quote:
Originally Posted by tmiranda View Post
I took a look at the manual and it says the hook is triggered when an STVi has been imported using the ImportSTVFile() method. I'm going to assume that that's how the Plugin Manager loads STVi's.

I'm thinking I can use that hook to scan the STV each time an STVi is loaded as long as I'm careful not to edit the same widget multiple times. So each time the code is called it will first check the existing STV (to make the changes to the widgets that were loaded before my plugin) and then check the new widgets for things that need to be changed.

It's not real efficient but I think it's worth a shot.
There's a call in the core that imports an STVi into an STV. As part of this call, it will execute the STVImported() hooks once the Widget import is done. The ImportSTVFile() API call is not used by the core at all (it's very rare for the core to actually use one of the API calls, it only ever does it for RPC purposes where the client needs to ask the server something). So if you're trying to replace that to modify the behvior, you will be out of luck.

The mechanism that clears the dirty flag is in the code that loads the STV, then imports any enabled STVI plugins, and then clears the dirty state of the STV. There is no other way currently to clear that dirty state.

The biggest problem you'll run into doing what you outline here is what Greg mentioned where Java calls into the API would not get replaced by your logic (and there's really no way to replace those). So weird inconsistencies may result from your modifications.
__________________
Jeffrey Kardatzke
Google
Founder of SageTV
Reply With Quote
  #8  
Old 03-07-2011, 05:57 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Jeff,

Thanks for the clarification. I have no intention of modifying the ImportSTVFile() API, I was just trying to understand how things are done to see if what I do want to do will have any adverse consequences.

Two questions:

1. If I modify the STV during a STVImported() hook, will that cause the dirty flag to get set or not?

2. When the ImportedWidgets are passed to the STVImported() hook have they already been merged into the STV or will they be merged after the STVImported() hook is complete? I'm assuming it's the former but hoping it's the latter, because if it's the latter I can (hopefully) modify the Widgets BEFORE they get merged into the STV and that should solve my "dirty flag" problem.

Tom
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #9  
Old 03-07-2011, 07:08 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Quote:
Originally Posted by tmiranda View Post
1. If I modify the STV during a STVImported() hook, will that cause the dirty flag to get set or not?
Jeff already answered this in his second paragraph above:

Quote:
Originally Posted by Narflex View Post
The mechanism that clears the dirty flag is in the code that loads the STV, then imports any enabled STVI plugins, and then clears the dirty state of the STV.
Any dirtiness that happens during STVImported is cleared after all the imports are done.

Quote:
Originally Posted by tmiranda View Post
2. When the ImportedWidgets are passed to the STVImported() hook have they already been merged into the STV or will they be merged after the STVImported() hook is complete?
If by "merged into" you mean linked into the widget tree, then the answer is neither. The whole purpose of STVImported is to run the STVI code that links them in. So no, they are not yet linked in when the hook fires, and no, they will not get linked in by some other code after the hook returns. It's up to your hook code to do the linking, or it won't get done. Obviously the widgets themselves have already been instantiated in that STV before STVImport fires, and that's enough to dirty the STV. But it's moot since the flag gets cleared anyway per Jeff's post.

I think the real sticking point is that you seem to be assuming that the STVImported hook in your STVI will fire when some other STVI is imported. I don't think that's the case. I think (but can't swear) that yours fires just once, when your STVI is imported, and then the hook and the code underneath it are deleted before the next STVI is imported. At least I don't see any evidence of STVImported hooks persisting in the STV beyond the initial import.
__________________
-- Greg
Reply With Quote
  #10  
Old 03-07-2011, 07:48 PM
Narflex's Avatar
Narflex Narflex is offline
Sage
 
Join Date: Feb 2003
Location: Redondo Beach, CA
Posts: 6,349
Quote:
Originally Posted by GKusnick View Post
I think the real sticking point is that you seem to be assuming that the STVImported hook in your STVI will fire when some other STVI is imported. I don't think that's the case. I think (but can't swear) that yours fires just once, when your STVI is imported, and then the hook and the code underneath it are deleted before the next STVI is imported. At least I don't see any evidence of STVImported hooks persisting in the STV beyond the initial import.
Greg is correct here. When an STVI is imported; the core instantiates all of the Widgets in the STVI and then adds them to the Widget set in the currently loaded STV. Then it searches through all of the NEWLY imported Widgets, looking for any Hook type Widgets named STVImported(). Then it invokes each of those that it finds. Because of this, there is no way to intercept the STVImported hook unless you actually modify the STVI that is being imported itself.
__________________
Jeffrey Kardatzke
Google
Founder of SageTV
Reply With Quote
  #11  
Old 03-08-2011, 06:57 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by Narflex View Post
Greg is correct here. When an STVI is imported; the core instantiates all of the Widgets in the STVI and then adds them to the Widget set in the currently loaded STV. Then it searches through all of the NEWLY imported Widgets, looking for any Hook type Widgets named STVImported(). Then it invokes each of those that it finds. Because of this, there is no way to intercept the STVImported hook unless you actually modify the STVI that is being imported itself.
Thanks Jeff and Greg. I was misunderstanding how the mechanism worked.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Are 64K Blocks Ever A Bad Idea? Savage1701 Hardware Support 7 05-10-2010 11:33 AM
HD PVR to record Blue ray movies...bad idea tvconfuse Hardware Support 12 10-03-2008 08:17 AM
Bad idea? utekineir Hardware Support 5 01-13-2007 01:29 PM
Removing garbage widgets from STV dflachbart SageTV Studio 11 05-10-2006 09:10 AM
STV feature idea evilpenguin SageTV Customizations 15 12-08-2004 05:00 AM


All times are GMT -6. The time now is 05:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.