Custom Object

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom Object

Lucius9
Hey

I would like to know if I can use objects that I created as state variables of my service ? I read "4.1.1. Mapping state variables" and I understood that it works only with the Java types but I want to be sure.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Christian Bauer
Administrator
What UPnP value representation do you expect for "Object"? It has to be mapped to a UPnP type at some point…

Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Lucius9
I have created an object that contains several String and I would like to send an ArrayList of this kind of objects with my service.
Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Christian Bauer
Administrator
Read docs about CSV.
Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Lucius9
OK I tried and I got this exception in my service class :
Declared string-convertible type needs a public single-argument String constructor

I don't understand why I did the same as in the documentation
Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Christian Bauer
Administrator
No code, no help.

Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Lucius9
Ok there it is


@UpnpService(
        serviceId = @UpnpServiceId("VLCStreamote"),
        serviceType = @UpnpServiceType(value = "VLCStreamote", version = 1),
        stringConvertibleTypes=VLCRemote.class
)
public class VLCRemote
{
       
        private Informations Info=new Informations();
        private Playlist playlist=new Playlist();
       
        @UpnpStateVariable
    private VLCRemote vlcRemote;

        @UpnpStateVariable(defaultValue="0")
        private int time;
       
        @UpnpStateVariable(defaultValue="0")
        private int volume;
       
        @UpnpStateVariable(defaultValue="0")
        private int length;
       
        @UpnpStateVariable(defaultValue = "")
    private String command;

    @UpnpStateVariable(defaultValue = "")
    private String state;
    @UpnpStateVariable(datatype="string")
    private ArrayList<Media> media;
   
               
            @UpnpAction
            public void setCmd(@UpnpInputArgument(name = "NewCommandValue",stateVariable="command")
                                  String newCommandValue)
            {
           
            String url="http://127.0.0.1:8080/requests/status.xml";
            if(newCommandValue.equals("!PAUSE"))command="pl_pause";  
            else if(newCommandValue.equals("!PLAY"))command="pl_play";
            else if(newCommandValue.equals("!PREVIOUS"))command="pl_previous";
            else if(newCommandValue.equals("!NEXT"))command="pl_next";
            else if(newCommandValue.contains("!SEEK"))
            {
            String []temp=newCommandValue.split("!");    
            command="seek&val="+temp[2];
            }
            else if(newCommandValue.contains("!VOL"))
            {
            String []temp=newCommandValue.split("!");
            command="volume&val="+temp[2];
            }
           
           
    try
    {
   
   
                                String query=String.format("command="+command,URLEncoder.encode(command,"UTF-8"));
                               
                                URLConnection connection=new URL(url+"?"+query).openConnection();
                                InputStream response = connection.getInputStream();
                               
                        }
    catch (UnsupportedEncodingException e)
    {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
    catch (MalformedURLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
    catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
           
               
            }
            @UpnpAction(out=@UpnpOutputArgument(name="RetTimeValue"))
            public int getTime()
            {    
            Info.update();
            time=Info.getTime();
            System.out.println("time");
            return time;
            }
            @UpnpAction(out=@UpnpOutputArgument(name="RetVolValue"))
            public int getVolume()
            {    
            Info.update();
            volume=Info.getVolume();
            return volume;
            }
            @UpnpAction(out=@UpnpOutputArgument(name="RetLengthValue"))
            public int getLength()
            {  
            Info.update();
            length=Info.getLength();    
            return length;
            }
            @UpnpAction(out=@UpnpOutputArgument(name="RetStateValue"))
            public String getState()
            {
            Info.update();
            state=Info.getState();
            return state;
            }
            @UpnpAction(out=@UpnpOutputArgument(name="RetPlaylist"))
            public CSV getPlayList()
            {
            playlist.update();
            media=playlist.getList();
            CSV wrapper = null;
            if(playlist!=null)wrapper.addAll((Collection) playlist);
            return wrapper;
           
           
            }
            @UpnpAction(out = @UpnpOutputArgument(name = "Out"))
            public VLCRemote getVLCRemote()
            {
                return vlcRemote;
            }

            @UpnpAction
            public void setMyStringConvertible(@UpnpInputArgument(name = "In") VLCRemote vlcRemote)
            {
                this.vlcRemote= vlcRemote;
            }  
           
}
Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Christian Bauer
Administrator
So does VLCRemote have the right constructor or not? Cling has to instantiate that class and provide a String value somehow…

Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Lucius9
ok but a string value for what ?
Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Christian Bauer
Administrator
You give Cling a String representation of your value with VLCRemote#toString(). That's the value send over UPnP. When Cling receives the String representation it will give it back to you, by instantiating VLCRemote(String).

I'm now repeating the documentation.


Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Lucius9
Ok but what I want to do is to send my ArrayList<Media> over the Upnp
Reply | Threaded
Open this post in threaded view
|

Re: Custom Object

Lucius9
Am I forced to use the Comma Separated Values or is there another way to send my whole ArrayList of Media ?