Search code examples
upnpcling

Cling: Looking for Opensource code for uPnp ContentDirectory


I'm trying to build a uPnP control point for controlling audio and I am using Java the cling library. To browse the music on the server requires the ContentDirectory service, cling provides the api to access this but doesnt provide any classes to represent the various actions and arguments requiring me to write lots of boilerplate code, I wonder does such a library exist ?

For example Ive create a Browse class for the Browse action of a Content Directory

import org.fourthline.cling.model.meta.Action;
import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;

public class Browse extends AbstractActionAndInvocation
{
    //INPUT
    public static final String OBJECT_ID        = "ObjectID";
    public static final String BROWSE_FLAG      = "BrowseFlag";
    public static final String FILTER           = "Filter";
    public static final String STARTING_INDEX   = "StartingIndex";
    public static final String REQUESTED_COUNMT = "RequestedCount";

    public void setObjectID(String objectID)
    {
        actionInvocation.setInput(OBJECT_ID, objectID);
    }

    public void setBrowseFlag(BrowseFlag browseFlag)
    {
        actionInvocation.setInput(BROWSE_FLAG, browseFlag.getParameterName());
    }

    public void setFilter(String filter)
    {
        actionInvocation.setInput(FILTER, filter);
    }

    public void setStartingIndex(int startingIndex)
    {
        actionInvocation.setInput(STARTING_INDEX, new UnsignedIntegerFourBytes(startingIndex));
    }

    public void setRequestedCount(int requestCount)
    {
        actionInvocation.setInput(REQUESTED_COUNMT, new UnsignedIntegerFourBytes(requestCount));
    }


    public Browse(Action action)
    {
        super(action);
    }
}

Since ContentDirectory only has a predefined list of Actions it seems weird that these don't already exist somewhere ?


Solution

  • Within the cling-support module there are useful classes such as callback classes for the main services

    e.g

    org.fourthline.cling.support.contentdirectory.callback.Browse.java;
    

    However I found them to be of limited usefulness and serve more as an example implementation rather than one that can be used as is.