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-14-2006, 02:39 PM
Bohica's Avatar
Bohica Bohica is offline
Sage Advanced User
 
Join Date: Mar 2005
Posts: 218
Java very noob questions...

First -- sorry to post what probably are very noob questions... but I will anyway...

I am rewriting (for the first time no less) some programs I have written in .net in java -- specifically to see if I can integrate them into Sage.

After only a day or so with Java, I now am using sockets to connect to a remote server and gather and store a bunch of information that I now want to bring into sage. I figure the earlier I test this portion the better...

Lets say you have a package named foo. In foo, you have a class main, with a method main that simply initiates the connection mentioned earlier and grabs the data and stores it. Main has a public method called getData -- which for ease of the question simply returns a string value....

So from studio, I need to initiate the main class once, then use that function to get the string back...

Shouldn't I be able to do something like myTestFoo = new_foo()
or myTestFoo = new_foo_main()

and then use myTestString = myTestFoo_getData()

Obviously the package was copied to the jars directory...

And now - because I will want to use this later and might as well ask as many silly questions -- what happens if I want to create in Studio an array of a custom class which I am holding structured data in? Obviously this class is defined in the package as well....
Reply With Quote
  #2  
Old 03-14-2006, 02:54 PM
stanger89's Avatar
stanger89 stanger89 is offline
SageTVaholic
 
Join Date: May 2003
Location: Marion, IA
Posts: 15,188
Quote:
Originally Posted by Bohica
First -- sorry to post what probably are very noob questions... but I will anyway...
We've all been there

Quote:
I am rewriting (for the first time no less) some programs I have written in .net in java -- specifically to see if I can integrate them into Sage.

After only a day or so with Java, I now am using sockets to connect to a remote server and gather and store a bunch of information that I now want to bring into sage. I figure the earlier I test this portion the better...

Lets say you have a package named foo. In foo, you have a class main, with a method main that simply initiates the connection mentioned earlier and grabs the data and stores it. Main has a public method called getData -- which for ease of the question simply returns a string value....

So from studio, I need to initiate the main class once, then use that function to get the string back...

Shouldn't I be able to do something like myTestFoo = new_foo()
or myTestFoo = new_foo_main()
Close, I believe it's myTestFoo = new_foo_main_main()

Basically everything's of the form package_class_function
or new_package_class_function

It's the (I can't come up with the right terminology) non-class based, explicit calls, and in studio you use _ where you'd use . in java.

Quote:
and then use myTestString = myTestFoo_getData()
This would be:
myTestString = foo_main_getData(myTestFoo)

Quote:
Obviously the package was copied to the jars directory...
That one I'm not 100% on, in DVDPro2Sage I don't use a jar, I have the class file in a directory named the package name in the SageTV directory.

If you want an example of "Java in studio by dummies" take a look at something using DVDPro2Sage.
Reply With Quote
  #3  
Old 03-14-2006, 03:08 PM
Bohica's Avatar
Bohica Bohica is offline
Sage Advanced User
 
Join Date: Mar 2005
Posts: 218
Thanks! I will give this -- and the examples a shot!
Reply With Quote
  #4  
Old 03-14-2006, 03:50 PM
Bohica's Avatar
Bohica Bohica is offline
Sage Advanced User
 
Join Date: Mar 2005
Posts: 218
Maybe I am missing something...

Still doesn't work...

In my first post example... I want foo.Main to launch once -- and then be able to access it's data later.... The actual Main class -- through the main method does some collection of data and then goes into a wait loop checking a queue so other methods can be accessed... and it works fine from a command line...

It is really foo.Main.main -- where foo is the package, Main is the class, and main the method... but the main method should be run by default from what I have read...

if in Studio, I set a command that says myFoo = new_foo_Main_main() it evaluates null

if in Studio, I set a command that says myFoo = new_foo_Main() -- and evaluate the widget - I get Result: foo.Main@blahblah address I assume...

If I execute it is returns null -- is this because foo.Main.main does not return anything? What am I missing here? From what I can tell -- nothing actually executes....
Reply With Quote
  #5  
Old 03-14-2006, 04:35 PM
stanger89's Avatar
stanger89 stanger89 is offline
SageTVaholic
 
Join Date: May 2003
Location: Marion, IA
Posts: 15,188
Quote:
Originally Posted by Bohica
Still doesn't work...

In my first post example... I want foo.Main to launch once -- and then be able to access it's data later.... The actual Main class -- through the main method does some collection of data and then goes into a wait loop checking a queue so other methods can be accessed... and it works fine from a command line...

It is really foo.Main.main -- where foo is the package, Main is the class, and main the method... but the main method should be run by default from what I have read...
For interactive/command line programs yes, main will run automatically when you "run" your java file from the interpreter. But what you're doing for/from studio is a "library". Nothing is automatically run in that case. To use things, you first have to get an "instance" of the class (what the new_foo_Main() does, and then call things from that object.

Here's an example I'll leave out the nitty gritty since I think you can handle that
Code:
package DVDPro2Sage;
  public class DVDPro2Sage {
    
    
    public DVDPro2Sage(String f)
    {}
    
    public Vector getTitles()
    {}
    
    public void writeDVD(int i, String name)
    { }
    
    public void printDVD(Node node)
    {}
    
    public void writeAllDVDs(String path, boolean copy)
    { }

    public int findDVD(String name)
    {}
    
    public Vector searchDVD(String name)
    {}
    
    private boolean isEpisodic(String name)
    {}
}
That's part of DVDPro2Sage. What I do to use it is this:
oDVD = new_DVDPro2Sage_DVDPro2Sage(pathtofile)
Which gets an instance/object of DVDPro2Sage.

From now on, to use something from there I do this:
iDVD = DVDPro2Sage_DVDPro2Sage_findDVD(oDVD, "SomeDVD")

Then, I have a test function with main in it that I use for debugging my class (it's easier/quicker outside Sage).

Code:
import DVDPro2Sage.*;

/*
 * Created on May 29, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author Chad
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Test {

    public static void main(String[] args) {
        
        DVDPro2Sage bob = new DVDPro2Sage("W:\\collection.xml");
        
        int i = bob.findDVD("The Slayers Try: DVD Collection: Disc A");
        
        System.out.println(bob.getTitle(i));
        
                
    }
}
Notice the differences in how you use stuff in native java vs Studio/Sage.

I don't know what IDE you're using, but if I'd strongly suggest you get Eclipse. 1) It's free, and 2) it's awesome for Java programming. If you've got eclipse I'd be happy to zip my DVDPro2Sage stuff for you, strait out of my workspace.

Quote:
if in Studio, I set a command that says myFoo = new_foo_Main_main() it evaluates null

if in Studio, I set a command that says myFoo = new_foo_Main() -- and evaluate the widget - I get Result: foo.Main@blahblah address I assume...
Exactly, it's the "foo" object/instance, you'll need to pass that reference (myFoo) into any function you call that's a member of that class.

Quote:
If I execute it is returns null -- is this because foo.Main.main does not return anything?
It's because (if I read your post right) the return of foo.Main.main is stored in myFoo. null is the result of the assignment of foo.Main.main to myFoo.

If you put "new_foo_Main()" in the Expression Evaluator, you'll get a foo.Main@blah result.

Seriously, if you haven't yet, take a look at DVDPro2Sage. I'm not saying it's the most shining example of Java or Studio coding, but it's the result of my journey through much of the pain you're feeling.

Here's DVDPro2Sage (the Java):
http://forums.sage.tv/forums/downloa...?do=file&id=46
And here's a usage example: http://forums.sage.tv/forums/downloa...?do=file&id=52

Last edited by stanger89; 03-14-2006 at 04:38 PM.
Reply With Quote
  #6  
Old 03-14-2006, 05:17 PM
Bohica's Avatar
Bohica Bohica is offline
Sage Advanced User
 
Join Date: Mar 2005
Posts: 218
Thanks again -- I was looking at your code just a bit ago. I will take a look at your response here too! Thanks!
Reply With Quote
  #7  
Old 03-15-2006, 04:25 AM
nielm's Avatar
nielm nielm is offline
SageTVaholic
 
Join Date: Oct 2003
Location: Belgium
Posts: 4,496
2 things that can help: Enable the Sage troubleshooting (logging) console (see here). Set the properties on the console to have a large scroll buffer. This will allow you to see exception traces from Sage, and from Java.

Secondly, enable 'notify on error' in Studio.

Quote:
myFoo = new_foo_Main_main() it evaluates null
This is because I imagine your main() expects some arguments? (usually String[] args), so Sage is unable to find a main() function with no arguments
try myFoo = new_foo_Main_main(null)
(and make sure that your main() func can handle a null argument list).
__________________
Check out my enhancements for Sage in the Sage Customisations and Sageplugins Wiki
Reply With Quote
  #8  
Old 03-16-2006, 07:45 PM
Bohica's Avatar
Bohica Bohica is offline
Sage Advanced User
 
Join Date: Mar 2005
Posts: 218
Hey guys,

I just got back to this after two days out of town -- and it of course did work for me. Let me give you a heads up on what I am doing and see if there is any guidance you guys have for me before I go too far down paths less traveled...

I have written a server app for HAL2000, that exposes HALi (the automatedliving com object) to a terminal service, making the object somewhat network aware. This way I can control X10 lighting and other features of home automation through the network using a simple protocol I have written. I now have a java app that can connect and obtain lists of all devices, macros, etc throughout the house. I have another java class that will catch events thrown by the server, and sent through the network...

Since I dont want to take 'control' of sage to wait for a response -- as it could be a couple of seconds... what do you consider the best way to catch these messages and act on them in studio? Consider that in a busy environment, you may have 10 to 20 messages a minute... in a slow -- less than 1...

What I see in my head is a sage subscreen that allows you to display all the devices, or all the groups, or macros, etc that you have configured in HAL. You select one, and based on the type you can simply turn it on, off, dim it, etc. If you wait for the HAL software to confirm the command - it could take 1 to 3 seconds in my testing. Nothing I can do about this -- as it is part them and part X10. Let's say I send the off command to some device. I can send it and immediately return to sage -- and then wait for the previously mentioned event that would kick off when HAL detects the change... no real difference in timing compared to waiting for the return, but does not hold onto the thread...

What my programs prior to sage (.net and now java) have done is held a state table for all devices and information, and upon these events - changed the state for that device... thus keeping the table in sync. Every once and a while it updates the table from the source to make sure...

It simply -- and really only -- comes into play if I want to make the sage plugin look and feel nice, like putting a light bulb next to the particular light and turning it off when I send off -- or on when I send on... you get the idea I am sure...

Couple of more considerations.... it would be nice to let the java class run permanently in the background of sage -- but not REALLY necessary. Some transactions over the network could take seconds to return information, so it would be nice to have that information saved in a state table. Do you think this would be the best method, or should I establish and tear down connections every time I need to....

Any design recommendations or warning before I begin in earnest??

Last edited by Bohica; 03-16-2006 at 07:50 PM.
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 02:28 AM.


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