Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ui8 implementation introduced with UPnP 2.0 (needs Java 8) #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

package org.fourthline.cling.model.gena;

import java.util.LinkedHashMap;
import java.util.Map;

import org.fourthline.cling.model.UserConstants;
import org.fourthline.cling.model.meta.Service;
import org.fourthline.cling.model.state.StateVariableValue;
import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
import org.fourthline.cling.model.types.UnsignedIntegerEightBytes;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* An established subscription, with identifer, expiration duration, sequence handling, and state variable values.
Expand All @@ -38,8 +38,8 @@ public abstract class GENASubscription<S extends Service> {
protected S service;
protected String subscriptionId;
protected int requestedDurationSeconds = UserConstants.DEFAULT_SUBSCRIPTION_DURATION_SECONDS;
protected int actualDurationSeconds;
protected UnsignedIntegerFourBytes currentSequence;
protected int actualDurationSeconds;
protected UnsignedIntegerEightBytes currentSequence;
protected Map<String, StateVariableValue<S>> currentValues = new LinkedHashMap<>();

/**
Expand Down Expand Up @@ -78,7 +78,7 @@ synchronized public void setActualSubscriptionDurationSeconds(int seconds) {
this.actualDurationSeconds = seconds;
}

synchronized public UnsignedIntegerFourBytes getCurrentSequence() {
synchronized public UnsignedIntegerEightBytes getCurrentSequence() {
return currentSequence;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,13 @@
import org.fourthline.cling.model.meta.LocalService;
import org.fourthline.cling.model.meta.StateVariable;
import org.fourthline.cling.model.state.StateVariableValue;
import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
import org.fourthline.cling.model.types.UnsignedIntegerEightBytes;
import org.seamless.util.Exceptions;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.net.URL;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -97,7 +90,7 @@ public LocalGENASubscription(LocalService service,
}

this.subscriptionId = SubscriptionIdHeader.PREFIX + UUID.randomUUID();
this.currentSequence = new UnsignedIntegerFourBytes(0);
this.currentSequence = new UnsignedIntegerEightBytes(0);
this.callbackURLs = callbackURLs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import org.fourthline.cling.model.Location;
import org.fourthline.cling.model.Namespace;
import org.fourthline.cling.model.NetworkAddress;
import org.fourthline.cling.model.UnsupportedDataException;
import org.fourthline.cling.model.message.UpnpResponse;
import org.fourthline.cling.model.meta.RemoteService;
import org.fourthline.cling.model.state.StateVariableValue;
import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
import org.fourthline.cling.model.UnsupportedDataException;
import org.fourthline.cling.model.types.UnsignedIntegerEightBytes;

import java.beans.PropertyChangeSupport;
import java.net.URL;
Expand Down Expand Up @@ -83,7 +83,7 @@ synchronized public void end(CancelReason reason, UpnpResponse response) {
ended(reason, response);
}

synchronized public void receive(UnsignedIntegerFourBytes sequence, Collection<StateVariableValue> newValues) {
synchronized public void receive(UnsignedIntegerEightBytes sequence, Collection<StateVariableValue> newValues) {

if (this.currentSequence != null) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@

package org.fourthline.cling.model.message.gena;

import org.fourthline.cling.model.message.StreamRequestMessage;
import org.fourthline.cling.model.message.header.*;
import org.fourthline.cling.model.meta.RemoteService;
import org.fourthline.cling.model.state.StateVariableValue;
import org.fourthline.cling.model.message.StreamRequestMessage;
import org.fourthline.cling.model.message.header.UpnpHeader;
import org.fourthline.cling.model.message.header.SubscriptionIdHeader;
import org.fourthline.cling.model.message.header.NTEventHeader;
import org.fourthline.cling.model.message.header.NTSHeader;
import org.fourthline.cling.model.message.header.EventSequenceHeader;
import org.fourthline.cling.model.types.NotificationSubtype;
import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
import org.fourthline.cling.model.types.UnsignedIntegerEightBytes;

import java.util.List;
import java.util.ArrayList;
import java.util.List;

/**
* @author Christian Bauer
Expand Down Expand Up @@ -56,7 +52,7 @@ public String getSubscrptionId() {
return header != null ? header.getValue() : null;
}

public UnsignedIntegerFourBytes getSequence() {
public UnsignedIntegerEightBytes getSequence() {
EventSequenceHeader header = getHeaders().getFirstHeader(UpnpHeader.Type.SEQ, EventSequenceHeader.class);
return header != null ? header.getValue() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@

package org.fourthline.cling.model.message.gena;

import org.fourthline.cling.model.state.StateVariableValue;
import org.fourthline.cling.model.gena.GENASubscription;
import org.fourthline.cling.model.message.StreamRequestMessage;
import org.fourthline.cling.model.message.UpnpRequest;
import org.fourthline.cling.model.message.header.ContentTypeHeader;
import org.fourthline.cling.model.message.header.EventSequenceHeader;
import org.fourthline.cling.model.message.header.NTEventHeader;
import org.fourthline.cling.model.message.header.NTSHeader;
import org.fourthline.cling.model.message.header.SubscriptionIdHeader;
import org.fourthline.cling.model.message.header.UpnpHeader;
import org.fourthline.cling.model.message.header.*;
import org.fourthline.cling.model.state.StateVariableValue;
import org.fourthline.cling.model.types.NotificationSubtype;
import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
import org.fourthline.cling.model.gena.GENASubscription;
import org.fourthline.cling.model.types.UnsignedIntegerEightBytes;

import java.net.URL;
import java.util.Collection;
Expand All @@ -40,7 +35,7 @@ public class OutgoingEventRequestMessage extends StreamRequestMessage {

public OutgoingEventRequestMessage(GENASubscription subscription,
URL callbackURL,
UnsignedIntegerFourBytes sequence,
UnsignedIntegerEightBytes sequence,
Collection<StateVariableValue> values) {

super(new UpnpRequest(UpnpRequest.Method.NOTIFY, callbackURL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@

package org.fourthline.cling.model.message.header;

import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
import org.fourthline.cling.model.types.UnsignedIntegerEightBytes;

/**
* @author Christian Bauer
*/
public class EventSequenceHeader extends UpnpHeader<UnsignedIntegerFourBytes> {
public class EventSequenceHeader extends UpnpHeader<UnsignedIntegerEightBytes> {

public EventSequenceHeader() {
}

public EventSequenceHeader(long value) {
setValue(new UnsignedIntegerFourBytes(value));
setValue(new UnsignedIntegerEightBytes(value));
}

public void setString(String s) throws InvalidHeaderException {
Expand All @@ -39,7 +39,7 @@ public void setString(String s) throws InvalidHeaderException {
}

try {
setValue(new UnsignedIntegerFourBytes(s));
setValue(new UnsignedIntegerEightBytes(s));
} catch (NumberFormatException ex) {
throw new InvalidHeaderException("Invalid event sequence, " + ex.getMessage());
}
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/java/org/fourthline/cling/model/types/Datatype.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Locale;
import java.util.Map;

/**
* The type of a state variable value, able to convert to/from string representation.
Expand All @@ -39,7 +39,7 @@ public interface Datatype<V> {
* Java type.
* </p>
*/
public static enum Default {
enum Default {

BOOLEAN(Boolean.class, Builtin.BOOLEAN),
BOOLEAN_PRIMITIVE(Boolean.TYPE, Builtin.BOOLEAN),
Expand All @@ -49,7 +49,7 @@ public static enum Default {
INTEGER_PRIMITIVE(Integer.TYPE, Builtin.I4),
UNSIGNED_INTEGER_ONE_BYTE(UnsignedIntegerOneByte.class, Builtin.UI1),
UNSIGNED_INTEGER_TWO_BYTES(UnsignedIntegerTwoBytes.class, Builtin.UI2),
UNSIGNED_INTEGER_FOUR_BYTES(UnsignedIntegerFourBytes.class, Builtin.UI4),
UNSIGNED_INTEGER_FOUR_BYTES(UnsignedIntegerEightBytes.class, Builtin.UI4),
FLOAT(Float.class, Builtin.R4),
FLOAT_PRIMITIVE(Float.TYPE, Builtin.R4),
DOUBLE(Double.class, Builtin.FLOAT),
Expand Down Expand Up @@ -95,11 +95,11 @@ public String toString() {
/**
* Mapping from UPnP built-in standardized type to actual subtype of {@link Datatype}.
*/
public static enum Builtin {
enum Builtin {

UI1("ui1", new UnsignedIntegerOneByteDatatype()),
UI2("ui2", new UnsignedIntegerTwoBytesDatatype()),
UI4("ui4", new UnsignedIntegerFourBytesDatatype()),
UI4("ui4", new UnsignedIntegerEightBytesDatatype()),
I1("i1", new IntegerDatatype(1)),
I2("i2", new IntegerDatatype(2)),
I2_SHORT("i2", new ShortDatatype()),
Expand Down Expand Up @@ -187,19 +187,19 @@ public static boolean isNumeric(Builtin builtin) {
/**
* @return <code>true</code> if this datatype can handle values of the given Java type.
*/
public boolean isHandlingJavaType(Class type);
boolean isHandlingJavaType(Class type);

/**
* @return The built-in UPnP standardized type this datatype is mapped to or
* <code>null</code> if this is a custom datatype.
*/
public Builtin getBuiltin();
Builtin getBuiltin();

/**
* @param value The value to validate or <code>null</code>.
* @return Returns <code>true</code> if the value was <code>null</code>, validation result otherwise.
*/
public boolean isValid(V value);
boolean isValid(V value);

/**
* Transforms a value supported by this datatype into a string representation.
Expand All @@ -212,7 +212,7 @@ public static boolean isNumeric(Builtin builtin) {
* @return The transformed value as a string, or an empty string when the value is null, never returns <code>null</code>.
* @throws InvalidValueException
*/
public String getString(V value) throws InvalidValueException;
String getString(V value) throws InvalidValueException;

/**
* Transforms a string representation into a value of the supported type.
Expand All @@ -221,13 +221,13 @@ public static boolean isNumeric(Builtin builtin) {
* @return The converted value or <code>null</code> if the string was <code>null</code> or empty.
* @throws InvalidValueException If the string couldn't be parsed.
*/
public V valueOf(String s) throws InvalidValueException;
V valueOf(String s) throws InvalidValueException;

/**
* @return Metadata about this datatype, a nice string for display that describes
* this datatype (e.g. concrete class name).
*/
public String getDisplayString();
String getDisplayString();


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2013 4th Line GmbH, Switzerland
*
* The contents of this file are subject to the terms of either the GNU
* Lesser General Public License Version 2 or later ("LGPL") or the
* Common Development and Distribution License Version 1 or later
* ("CDDL") (collectively, the "License"). You may not use this file
* except in compliance with the License. See LICENSE.txt for more
* information.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

package org.fourthline.cling.model.types;

/**
* @author Christian Bauer
*/
final public class UnsignedIntegerEightBytes extends UnsignedVariableInteger {

public UnsignedIntegerEightBytes(long value) throws NumberFormatException {
super(value);
}

public UnsignedIntegerEightBytes(String s) throws NumberFormatException {
super(s);
}

public Bits getBits() {
return Bits.SIXTYFOUR;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2013 4th Line GmbH, Switzerland
*
* The contents of this file are subject to the terms of either the GNU
* Lesser General Public License Version 2 or later ("LGPL") or the
* Common Development and Distribution License Version 1 or later
* ("CDDL") (collectively, the "License"). You may not use this file
* except in compliance with the License. See LICENSE.txt for more
* information.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

package org.fourthline.cling.model.types;

/**
* @author Christian Bauer
*/
public class UnsignedIntegerEightBytesDatatype extends AbstractDatatype<UnsignedIntegerEightBytes> {

public UnsignedIntegerEightBytes valueOf(String s) throws InvalidValueException {
if (s.equals("")) return null;
try {
return new UnsignedIntegerEightBytes(s);
} catch (NumberFormatException ex) {
throw new InvalidValueException("Can't convert string to number or not in range: " + s, ex);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author Christian Bauer
*/
public class UnsignedIntegerFourBytesDatatype extends AbstractDatatype<UnsignedIntegerFourBytes> {
public class UnsignedIntegerFourDatatype extends AbstractDatatype<UnsignedIntegerFourBytes> {

public UnsignedIntegerFourBytes valueOf(String s) throws InvalidValueException {
if (s.equals("")) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public enum Bits {
EIGHT(0xffL),
SIXTEEN(0xffffL),
TWENTYFOUR(0xffffffL),
THIRTYTWO(0xffffffffL);
THIRTYTWO(0xffffffffL),
SIXTYFOUR(0x7fffffffffffffffL); //Long.toHexString(Long.MAX_VALUE)

private long maxValue;

Expand Down Expand Up @@ -100,9 +101,8 @@ public boolean equals(Object o) {

UnsignedVariableInteger that = (UnsignedVariableInteger) o;

if (value != that.value) return false;
return value == that.value;

return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package org.fourthline.cling.model.types.csv;

import org.fourthline.cling.model.types.InvalidValueException;
import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
import org.fourthline.cling.model.types.UnsignedIntegerEightBytes;

/**
* @author Christian Bauer
*/
public class CSVUnsignedIntegerFourBytes extends CSV<UnsignedIntegerFourBytes> {
public class CSVUnsignedIntegerFourBytes extends CSV<UnsignedIntegerEightBytes> {

public CSVUnsignedIntegerFourBytes() {
}
Expand Down
Loading