FileDocCategorySizeDatePackage
WifiP2pUpnpServiceResponse.javaAPI DocAndroid 5.1 API4780Thu Mar 12 22:22:44 GMT 2015android.net.wifi.p2p.nsd

WifiP2pUpnpServiceResponse

public class WifiP2pUpnpServiceResponse extends WifiP2pServiceResponse
A class for a response of upnp service discovery.
hide

Fields Summary
private int
mVersion
UPnP version. should be {@link WifiP2pUpnpServiceInfo#VERSION_1_0}
private List
mUniqueServiceNames
The list of Unique Service Name. e.g) {"uuid:6859dede-8574-59ab-9332-123456789012", "uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice"}
Constructors Summary
protected WifiP2pUpnpServiceResponse(int status, int transId, android.net.wifi.p2p.WifiP2pDevice dev, byte[] data)
hidden constructor.

param
status status code
param
transId transaction id
param
dev source device
param
data UPnP response data.

        super(WifiP2pServiceInfo.SERVICE_TYPE_UPNP,
                status, transId, dev, data);
        if (!parse()) {
            throw new IllegalArgumentException("Malformed upnp service response");
        }
    
Methods Summary
public java.util.ListgetUniqueServiceNames()
Return Unique Service Name strings.

return
Unique Service Name.
e.g )
  • "uuid:6859dede-8574-59ab-9332-123456789012"
  • "uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice"
  • "uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp-org:device: MediaServer:2"
  • "uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp-org:service: ContentDirectory:2"

        return mUniqueServiceNames;
    
public intgetVersion()
Return UPnP version number.

return
version number.
see
WifiP2pUpnpServiceInfo#VERSION_1_0

        return mVersion;
    
static android.net.wifi.p2p.nsd.WifiP2pUpnpServiceResponsenewInstance(int status, int transId, android.net.wifi.p2p.WifiP2pDevice device, byte[] data)
Create upnp service response.
This is only used in{@link WifiP2pServiceResponse}

param
status status code.
param
transId transaction id.
param
device source device.
param
data UPnP response data.
return
UPnP service response data.
hide

        if (status != WifiP2pServiceResponse.Status.SUCCESS) {
            return new WifiP2pUpnpServiceResponse(status, transId, device, null);
        }

        try {
            return new WifiP2pUpnpServiceResponse(status, transId, device, data);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
        return null;
    
private booleanparse()
Parse UPnP service discovery response

return
{@code true} if the operation succeeded

        /*
         * The data format is as follows.
         *
         * ______________________________________________________
         * |  Version (1)  |          USN (Variable)            |
         */
        if (mData == null) {
            // the empty is OK.
            return true;
        }

        if (mData.length < 1) {
            return false;
        }

        mVersion = mData[0] & 0xff;
        String[] names = new String(mData, 1, mData.length-1).split(",");
        mUniqueServiceNames = new ArrayList<String>();
        for (String name : names) {
            mUniqueServiceNames.add(name);
        }
        return true;
    
public java.lang.StringtoString()

        StringBuffer sbuf = new StringBuffer();
        sbuf.append("serviceType:UPnP(").append(mServiceType).append(")");
        sbuf.append(" status:").append(Status.toString(mStatus));
        sbuf.append(" srcAddr:").append(mDevice.deviceAddress);
        sbuf.append(" version:").append(String.format("%02x", mVersion));
        if (mUniqueServiceNames != null) {
            for (String name : mUniqueServiceNames) {
                sbuf.append(" usn:").append(name);
            }
        }
        return sbuf.toString();