View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.model.message.gena;
17  
18  import org.fourthline.cling.model.state.StateVariableValue;
19  import org.fourthline.cling.model.message.StreamRequestMessage;
20  import org.fourthline.cling.model.message.UpnpRequest;
21  import org.fourthline.cling.model.message.header.ContentTypeHeader;
22  import org.fourthline.cling.model.message.header.EventSequenceHeader;
23  import org.fourthline.cling.model.message.header.NTEventHeader;
24  import org.fourthline.cling.model.message.header.NTSHeader;
25  import org.fourthline.cling.model.message.header.SubscriptionIdHeader;
26  import org.fourthline.cling.model.message.header.UpnpHeader;
27  import org.fourthline.cling.model.types.NotificationSubtype;
28  import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
29  import org.fourthline.cling.model.gena.GENASubscription;
30  
31  import java.net.URL;
32  import java.util.Collection;
33  
34  /**
35   * @author Christian Bauer
36   */
37  public class OutgoingEventRequestMessage extends StreamRequestMessage {
38  
39      final private Collection<StateVariableValue> stateVariableValues;
40  
41      public OutgoingEventRequestMessage(GENASubscription subscription,
42                                         URL callbackURL,
43                                         UnsignedIntegerFourBytes sequence,
44                                         Collection<StateVariableValue> values) {
45  
46          super(new UpnpRequest(UpnpRequest.Method.NOTIFY, callbackURL));
47  
48          getHeaders().add(UpnpHeader.Type.CONTENT_TYPE, new ContentTypeHeader());
49          getHeaders().add(UpnpHeader.Type.NT, new NTEventHeader());
50          getHeaders().add(UpnpHeader.Type.NTS, new NTSHeader(NotificationSubtype.PROPCHANGE));
51          getHeaders().add(UpnpHeader.Type.SID, new SubscriptionIdHeader(subscription.getSubscriptionId()));
52  
53          // Important! Pass by value so that we can safely increment it afterwards and before this is send!
54          getHeaders().add(UpnpHeader.Type.SEQ, new EventSequenceHeader(sequence.getValue()));
55  
56          this.stateVariableValues = values;
57      }
58  
59      public OutgoingEventRequestMessage(GENASubscription subscription, URL callbackURL) {
60          this(subscription, callbackURL, subscription.getCurrentSequence(), subscription.getCurrentValues().values());
61      }
62  
63      public Collection<StateVariableValue> getStateVariableValues() {
64          return stateVariableValues;
65      }
66  }