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.discovery;
17  
18  import org.fourthline.cling.model.Constants;
19  import org.fourthline.cling.model.Location;
20  import org.fourthline.cling.model.message.header.LocationHeader;
21  import org.fourthline.cling.model.meta.LocalDevice;
22  import org.fourthline.cling.model.ModelUtil;
23  import org.fourthline.cling.model.message.OutgoingDatagramMessage;
24  import org.fourthline.cling.model.message.UpnpRequest;
25  import org.fourthline.cling.model.message.header.HostHeader;
26  import org.fourthline.cling.model.message.header.NTSHeader;
27  import org.fourthline.cling.model.message.header.ServerHeader;
28  import org.fourthline.cling.model.message.header.UpnpHeader;
29  import org.fourthline.cling.model.message.header.MaxAgeHeader;
30  import org.fourthline.cling.model.types.NotificationSubtype;
31  
32  /**
33   * @author Christian Bauer
34   */
35  public abstract class OutgoingNotificationRequest extends OutgoingDatagramMessage<UpnpRequest> {
36  
37      private NotificationSubtype type;
38  
39      protected OutgoingNotificationRequest(Location location, LocalDevice device, NotificationSubtype type) {
40          super(
41                  new UpnpRequest(UpnpRequest.Method.NOTIFY),
42                  ModelUtil.getInetAddressByName(Constants.IPV4_UPNP_MULTICAST_GROUP),
43                  Constants.UPNP_MULTICAST_PORT
44          );
45  
46          this.type = type;
47  
48          getHeaders().add(UpnpHeader.Type.MAX_AGE, new MaxAgeHeader(device.getIdentity().getMaxAgeSeconds()));
49          getHeaders().add(UpnpHeader.Type.LOCATION, new LocationHeader(location.getURL()));
50  
51          getHeaders().add(UpnpHeader.Type.SERVER, new ServerHeader());
52          getHeaders().add(UpnpHeader.Type.HOST, new HostHeader());
53          getHeaders().add(UpnpHeader.Type.NTS, new NTSHeader(type));
54      }
55  
56      public NotificationSubtype getType() {
57          return type;
58      }
59  
60  }