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.meta.RemoteService;
19  import org.fourthline.cling.model.state.StateVariableValue;
20  import org.fourthline.cling.model.message.StreamRequestMessage;
21  import org.fourthline.cling.model.message.header.UpnpHeader;
22  import org.fourthline.cling.model.message.header.SubscriptionIdHeader;
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.EventSequenceHeader;
26  import org.fourthline.cling.model.types.NotificationSubtype;
27  import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
28  
29  import java.util.List;
30  import java.util.ArrayList;
31  
32  /**
33   * @author Christian Bauer
34   */
35  public class IncomingEventRequestMessage extends StreamRequestMessage {
36  
37      final private List<StateVariableValue> stateVariableValues = new ArrayList<>();
38      final private RemoteService service;
39  
40      public IncomingEventRequestMessage(StreamRequestMessage source, RemoteService service) {
41          super(source);
42          this.service = service;
43      }
44  
45      public RemoteService getService() {
46          return service;
47      }
48  
49      public List<StateVariableValue> getStateVariableValues() {
50          return stateVariableValues;
51      }
52  
53      public String getSubscrptionId() {
54          SubscriptionIdHeader header =
55                  getHeaders().getFirstHeader(UpnpHeader.Type.SID,SubscriptionIdHeader.class);
56          return header != null ? header.getValue() : null;
57      }
58  
59      public UnsignedIntegerFourBytes getSequence() {
60          EventSequenceHeader header = getHeaders().getFirstHeader(UpnpHeader.Type.SEQ, EventSequenceHeader.class);
61          return header != null ? header.getValue() : null;
62      }
63  
64      /**
65       * @return <code>true</code> if this message as an NT and NTS header.
66       */
67      public boolean hasNotificationHeaders() {
68          UpnpHeader ntHeader = getHeaders().getFirstHeader(UpnpHeader.Type.NT);
69          UpnpHeader ntsHeader = getHeaders().getFirstHeader(UpnpHeader.Type.NTS);
70          return ntHeader != null && ntHeader.getValue() != null
71                  && ntsHeader != null && ntsHeader.getValue() != null;
72      }
73  
74      /**
75       * @return <code>true</code> if this message has an NT header, and NTS header
76       *         with value {@link org.fourthline.cling.model.types.NotificationSubtype#PROPCHANGE}.
77       */
78      public boolean hasValidNotificationHeaders() {
79          NTEventHeader ntHeader = getHeaders().getFirstHeader(UpnpHeader.Type.NT, NTEventHeader.class);
80          NTSHeader ntsHeader = getHeaders().getFirstHeader(UpnpHeader.Type.NTS, NTSHeader.class);
81          return ntHeader != null && ntHeader.getValue() != null
82                  && ntsHeader != null && ntsHeader.getValue().equals(NotificationSubtype.PROPCHANGE);
83  
84      }
85  
86      @Override
87      public String toString() {
88          return super.toString() + " SEQUENCE: " + getSequence().getValue();
89      }
90  }