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-02-2011, 08:41 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Setting "this" in Java

Next silly question for the night. If I have a Java method that is called from the STV, how do I set the STV variable "this"?

I tried searching but "this" is just too common a word!
__________________

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-02-2011, 08:52 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
This is called directly in the stv after doing something but not setting it to a variable ie

Code:
GroupByMethod(mycoolfiles,mycoolmethod)
Sortlexical(this,false,mycoolsorting)
Basically this is refering to whatever you just did above it.
Reply With Quote
  #3  
Old 03-02-2011, 09:09 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by PLUCKYHD View Post
This is called directly in the stv after doing something but not setting it to a variable ie

Code:
GroupByMethod(mycoolfiles,mycoolmethod)
Sortlexical(this,false,mycoolsorting)
Basically this is refering to whatever you just did above it.
Yes, I know that part. How do I set "this" in Java so that I can do:

Code:
myclass_myMethod()
SortLexical(this, false, 'AnotherMethod")
How do I set "this" in myMethod() so it's accessible in the STV?
__________________

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-03-2011, 12:12 AM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Just return it as the return value of the method. As Plucky said, "this" is just the final result of evaluating the previous expression. If that expression happens to consist of a Java method call that returns a value, that returned value becomes "this".

Or to say it a different way, it's like every Action widget has an invisible "this = " in front of it. So if your widget says

Code:
myclass_myMethod()
that's exactly equivalent to

Code:
this = myclass_myMethod()
That's the only way "this" ever gets set. There is no other way to do it.
__________________
-- Greg
Reply With Quote
  #5  
Old 03-03-2011, 07:24 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Something is not right with this. In my MultiUser Plugin I created methods that replace the core methods but I could not do thie with Watch() because "this" was not getting set properly. My Java code looks like this:

Code:
public static Object watch(Object content) {

   .... do some things ...

   return MediaPlayerAPI.Watch(content);
}
This did not work and I assumed it was because "this" was not getting set properly (the STV checks "this" right after Watch()) but maybe something else funky is going on?

I fixed the problem but I am not 100% satisfied with what I had to do to correct it.

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
  #6  
Old 03-03-2011, 07:30 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
Something is not right with this. In my MultiUser Plugin I created methods that replace the core methods but I could not do thie with Watch() because "this" was not getting set properly. My Java code looks like this:

Code:
public static Object watch(Object content) {

   .... do some things ...

   return MediaPlayerAPI.Watch(content);
}
This did not work and I assumed it was because "this" was not getting set properly (the STV checks "this" right after Watch()) but maybe something else funky is going on?

I fixed the problem but I am not 100% satisfied with what I had to do to correct it.

Tom
if you call Watch... you will need to set the UIContext... otherwise, sagetv will not know which UI to play it on... I do this in phoenix... To be really sure, my Watch method requires that the ui context be passed from the stv, so there's no guess work.
Reply With Quote
  #7  
Old 03-03-2011, 08:14 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post
if you call Watch... you will need to set the UIContext... otherwise, sagetv will not know which UI to play it on... I do this in phoenix... To be really sure, my Watch method requires that the ui context be passed from the stv, so there's no guess work.
I get the UIContext and call watch for all SMM direct from Java. But I call onto the widget chain using the widget api directly to the defaults so all the variables get passed correctly as well as I add static context from java for airing and such variables before executing the widget chain. I haven't had any issues relying on the UIContext from sagex doing this.
Reply With Quote
  #8  
Old 03-03-2011, 08:22 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by PLUCKYHD View Post
I get the UIContext and call watch for all SMM direct from Java. But I call onto the widget chain using the widget api directly to the defaults so all the variables get passed correctly as well as I add static context from java for airing and such variables before executing the widget chain. I haven't had any issues relying on the UIContext from sagex doing this.
That's good to know I haven't had any issues with the UIcontext stuff myself... but I just wanted to be sure, in phoenix, that when watch is called, then it has the right context from the start
Reply With Quote
  #9  
Old 03-03-2011, 08:29 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post
That's good to know I haven't had any issues with the UIcontext stuff myself... but I just wanted to be sure, in phoenix, that when watch is called, then it has the right context from the start
Yeah as long as a create a new context like I mentioned in the other thread I have had 0 reports of it not working.

On that subject I am getting some issues with SetProperty Setting the Server property instead of the extender/local desktop property lately but haven't had a chance to track it down. I don't pass a UIContext but am tempted to start

And believe me MyMovies relies on UIContext from top to bottom from reading the custom properties to playing a file and has been spot on so thanks for that
Reply With Quote
  #10  
Old 03-03-2011, 12:57 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Quote:
Originally Posted by tmiranda View Post
This did not work and I assumed it was because "this" was not getting set properly (the STV checks "this" right after Watch()) but maybe something else funky is going on?
Did you check your logs for errors? If your method throws an exception (and fails to catch it internally), then obviously its return statement won't be executed and "this" will not be set properly.
__________________
-- Greg
Reply With Quote
  #11  
Old 03-03-2011, 12:59 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
Did you check your logs for errors? If your method throws an exception (and fails to catch it internally), then obviously its return statement won't be executed and "this" will not be set properly.
No, but I will. I'll also check the UIContext issue that Sean and Skye pointed out to see if that's the problem.
__________________

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
  #12  
Old 03-03-2011, 01:13 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by GKusnick View Post
Did you check your logs for errors? If your method throws an exception (and fails to catch it internally), then obviously its return statement won't be executed and "this" will not be set properly.
Quote:
Originally Posted by tmiranda View Post
No, but I will. I'll also check the UIContext issue that Sean and Skye pointed out to see if that's the problem.
you can check the sagex-apis to see if failed badly... but the Watch() api is kind of odd from what I can recall. It's suposed to return True, i think if it succeeded, or a string if it failed. The string should contain the error message. In some of my cases, it actually returns an obfuscated sagetv object, which is also a normal reply. (I spoke to Jeff to about this behaviour and he did explain it to me, but I sort of forget why.)
Reply With Quote
  #13  
Old 03-03-2011, 02:27 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by stuckless View Post
you can check the sagex-apis to see if failed badly... but the Watch() api is kind of odd from what I can recall. It's suposed to return True, i think if it succeeded, or a string if it failed. The string should contain the error message. In some of my cases, it actually returns an obfuscated sagetv object, which is also a normal reply. (I spoke to Jeff to about this behaviour and he did explain it to me, but I sort of forget why.)
Thanks. OT, but something I always wanted to ask. What's an "obfuscated" Object, why are they used, and where can I read more about them?

Thanks
__________________

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
  #14  
Old 03-03-2011, 02:36 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
Thanks. OT, but something I always wanted to ask. What's an "obfuscated" Object, why are they used, and where can I read more about them?

Thanks
There are many reasons to obfuscate... but I suspect that sagetv does it to prevent people from de-compiling their code and potentially stealing code or ideas. The process of obfuscating basically rewrites all the bytecode so that the classname, methods, etc, are all very short (like one or two characters) names.

The other reasons run an obfuscator on your code is to simple reduce the physical size of the jar file. Since java has to load all the classes into memory which includes things like classname, method name, etc, then by obfuscating the code, you end up with slightly smaller jar files that consume less memory when loaded.

The other reason to use an obfuscator is to run post processing actions against the code to do optimizations like remove private methods that are never used. Or, remove public methods that are never called (can be dangerous). You can alog create rules that will entirely strip logging from a jar file.

I don't know what sage uses, but I suspect it is either ProGuard or something similar.

Keep in mind, when you obfuscate the code, it will give you a set of files that you can be used to "decipher" stack traces. So, when you see an obfuscated strack trace in the code that is a sage error... when you send it to them... they know exactly where in the code it died... even though you don't
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
setting new source, won't load any "local market" EPG choices matt91 SageTV Beta Test Software 5 02-09-2011 07:36 PM
"Backdrops" "SageTV" "Covers" folders - what's creating them mp328 Sage My Movies 4 09-20-2010 05:31 PM
JAVA "MainMsg"" error help Graygeek SageTV Software 0 09-01-2009 04:04 PM
"Set defaults" for Series forgets "Keep"/"Auto-delete" setting maxpower SageMC Custom Interface 9 05-14-2008 09:44 PM
Java Error? "unexpected error" "exception_access_violation" gotuitdan SageTV Software 1 11-21-2006 10:49 PM


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


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