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 02-07-2006, 07:59 AM
dflachbart dflachbart is offline
SageTVaholic
 
Join Date: Jan 2006
Location: Brookfield, CT
Posts: 2,743
Question Hook which gets called periodically ?

Is there a hook in SageTV which gets called periodically, e.g. every n minutes ? I need a way to execute code (check a status, and possibly perform an action) in regular intervals. I thougth about implementing the wait-loop in a separate java thread (started at server startup) which checks the status and performs the action by using the sage.SageTV.api interface, but if there was an appropriate hook in Sage I could use this one instead and don't have to mess with java at all ... Or could I implement this sleep-check-action thread by using "fork()" in Studio itself ? Any suggestions appreciated ...

Thanks,
Dirk
Reply With Quote
  #2  
Old 02-07-2006, 09:33 AM
malore's Avatar
malore malore is offline
Sage Fanatic
 
Join Date: Aug 2003
Location: Iowa
Posts: 877
The comskip background file processing code in my STV is done using Fork and Wait like you described. I added the code to BeforeMenuLoad of the Main Menu and use AddGlobalContext to set a variable which I check to insure the code is only started once.

Note: If SageTV is just running as a service, the service doesn't use an STV file so this type of background process won't run unless the client/gui is running.
Reply With Quote
  #3  
Old 02-08-2006, 08:49 PM
dflachbart dflachbart is offline
SageTVaholic
 
Join Date: Jan 2006
Location: Brookfield, CT
Posts: 2,743
Thanks malore !


The Fork() method works well, much easier than dealing with external java code. At first I couldnt figure out how to get the flag initialized only once - I added the AddGobalContext("flag", false) to the hook, but soon discovered that this got called every time I revisited the menu. Then I found a note in the manual that Studio will return null if a variable is accessed which has not been defined yet, so I changed it to

-if (flag == null)
-AddGobalContext("flag", false)

and then it worked . Please correct me if there is a better approach.

Studio is awesome, I am slowly but steadily getting the hang of it.


Currently I face two other problems:

1) my code implements a sleep timer and basically consists of an option menu which I successfully linked to the setup menu by adding it to the "customize" menu tree in Studio. As a next step I tried to move this code to a top level menu page so that I can link to it via nielm's dynamic menus.

I finally got it working, but only with a hitch: in my first version (hooked directly into the setup menu) it was sufficient to call '"CloseOptionsMenu()" to close the menu, but in the second one (linked to a dynamic menus) the options menu doesn't close any more. I had to add an explicit SageCommand("Home") to get it to close. Am I doing something wrong ? The structure is

Code:
- Menu
 - AfterMenuLoad
  - OptionMenu
   - Option1
    - ...
   - Option2
    - ...
   - OptionN
    - CloseOptionsMenu()
     - SageCommand("Home")    <-- without it it does not work
2) I tried to use nielm's new basic_importer to generate an importable STVi for it, but the import always hangs. Well, I guess I will ask nielm for help on this one.

Thanks again for any help,

Dirk
Reply With Quote
  #4  
Old 02-09-2006, 02:39 AM
nielm's Avatar
nielm nielm is offline
SageTVaholic
 
Join Date: Oct 2003
Location: Belgium
Posts: 4,496
have a look at my Exit Sage plugin to see how to handle poping up a popup from a dynamic menus menu...

You need a menu with a default theme (Album theme is good for this) so that the background is cleared, and you need a 'CloseOptionsMenu(); SageCommand("Back") (or "Home")' whenever the options menu is closed to go back to the dynamic menus -- this includes adding a listener for the Options command otherwise you can be left with a blank screen!...

I also have seen a hang on import once -- (or rather an endless loop) -- the delete widget tree code is apparantly not brilliant at handling loops, so if you are deleting some existing widgets (such as deleting an old version of your import), you may want to try not doing that for the moment!

BTW, one other way of making a periodic timer start only once is to add it to the ApplicationStarted hook -- which is called only once. But apparantly you have to be careful what you do there...
__________________
Check out my enhancements for Sage in the Sage Customisations and Sageplugins Wiki
Reply With Quote
  #5  
Old 02-09-2006, 06:57 AM
dflachbart dflachbart is offline
SageTVaholic
 
Join Date: Jan 2006
Location: Brookfield, CT
Posts: 2,743
Quote:
Originally Posted by nielm
have a look at my Exit Sage plugin to see how to handle poping up a popup from a dynamic menus menu...

You need a menu with a default theme (Album theme is good for this) so that the background is cleared, and you need a 'CloseOptionsMenu(); SageCommand("Back") (or "Home")' whenever the options menu is closed to go back to the dynamic menus -- this includes adding a listener for the Options command otherwise you can be left with a blank screen!...
Thanks nielm, I'll have a look at it. But good to know that the SageCommand is indeed necessary ...

Quote:
Originally Posted by nielm
I also have seen a hang on import once -- (or rather an endless loop) -- the delete widget tree code is apparantly not brilliant at handling loops, so if you are deleting some existing widgets (such as deleting an old version of your import), you may want to try not doing that for the moment!
Actually, I did not edit the delete widget code at all (the docs set it's optional, and since I am not familiar enough with Studio yet to understand what this code really does I thought I'd better not touch this ... ) Could there be anything wrong with the code of my menu itself, or does the importer simply insert the new menu tree with a plain copy ?

Quote:
Originally Posted by nielm
BTW, one other way of making a periodic timer start only once is to add it to the ApplicationStarted hook -- which is called only once. But apparantly you have to be careful what you do there...
Yeah, I tried this first, and it worked indeed. But as you pointed out, the docs said that you have to be careful with this, so I thought I better look for something else ...


Thanks for your help,

Dirk
Reply With Quote
  #6  
Old 02-10-2006, 12:58 PM
dflachbart dflachbart is offline
SageTVaholic
 
Join Date: Jan 2006
Location: Brookfield, CT
Posts: 2,743
Quote:
Originally Posted by nielm
I also have seen a hang on import once -- (or rather an endless loop) -- the delete widget tree code is apparantly not brilliant at handling loops, so if you are deleting some existing widgets (such as deleting an old version of your import), you may want to try not doing that for the moment!
I finally got the import working. It turned out that the second EDIT ME (where the Main Menu/Screen Saver/Server connection menus get deleted) causes the hang. After I deleted this action chain the import succeeded . The first deletion action chain seems to work, I added the name of my menu to the data union, and on a re-import it correctly blows away the old menu ...

Nielm, what is the difference between the two deletion action chains, and what is the second one supposed to do ?


Anyway, thanks so much for this tool, without it it would have taken a novice like me an eternity to figure out how to generate a simple import

Dirk
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


All times are GMT -6. The time now is 04:55 PM.


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