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.message.OutgoingDatagramMessage;
20  import org.fourthline.cling.model.message.UpnpRequest;
21  import org.fourthline.cling.model.message.header.HostHeader;
22  import org.fourthline.cling.model.message.header.MANHeader;
23  import org.fourthline.cling.model.message.header.MXHeader;
24  import org.fourthline.cling.model.message.header.UpnpHeader;
25  import org.fourthline.cling.model.types.NotificationSubtype;
26  import org.fourthline.cling.model.ModelUtil;
27  
28  /**
29   * @author Christian Bauer
30   */
31  public class OutgoingSearchRequest extends OutgoingDatagramMessage<UpnpRequest> {
32  
33      private UpnpHeader searchTarget;
34  
35      public OutgoingSearchRequest(UpnpHeader searchTarget, int mxSeconds) {
36          super(
37                  new UpnpRequest(UpnpRequest.Method.MSEARCH),
38                  ModelUtil.getInetAddressByName(Constants.IPV4_UPNP_MULTICAST_GROUP),
39                  Constants.UPNP_MULTICAST_PORT
40          );
41  
42          this.searchTarget = searchTarget;
43  
44          getHeaders().add(UpnpHeader.Type.MAN, new MANHeader(NotificationSubtype.DISCOVER.getHeaderString()));
45          getHeaders().add(UpnpHeader.Type.MX, new MXHeader(mxSeconds));
46          getHeaders().add(UpnpHeader.Type.ST, searchTarget);
47          getHeaders().add(UpnpHeader.Type.HOST, new HostHeader());
48      }
49  
50      public UpnpHeader getSearchTarget() {
51          return searchTarget;
52      }
53  }