001package ball.upnp; 002/*- 003 * ########################################################################## 004 * UPnP/SSDP Implementation Classes 005 * $Id: Service.java 7215 2021-01-03 18:39:51Z ball $ 006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/ball-upnp/trunk/src/main/java/ball/upnp/Service.java $ 007 * %% 008 * Copyright (C) 2013 - 2021 Allen D. Ball 009 * %% 010 * Licensed under the Apache License, Version 2.0 (the "License"); 011 * you may not use this file except in compliance with the License. 012 * You may obtain a copy of the License at 013 * 014 * http://www.apache.org/licenses/LICENSE-2.0 015 * 016 * Unless required by applicable law or agreed to in writing, software 017 * distributed under the License is distributed on an "AS IS" BASIS, 018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 019 * See the License for the specific language governing permissions and 020 * limitations under the License. 021 * ########################################################################## 022 */ 023import ball.upnp.annotation.XmlNs; 024import java.net.URI; 025import java.util.LinkedHashMap; 026import java.util.LinkedHashSet; 027import java.util.List; 028import java.util.Map; 029import java.util.Objects; 030import java.util.Set; 031import java.util.function.Function; 032 033/** 034 * {@link.uri http://www.upnp.org/ UPnP} service interface. 035 * 036 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball} 037 * @version $Revision: 7215 $ 038 */ 039@XmlNs("urn:schemas-upnp-org:service-1-0") 040public interface Service extends Description, SSDP { 041 042 /** 043 * Method to get the {@link Device} hosting {@link.this} 044 * {@link Service}. 045 * 046 * @return The {@link Device}. 047 */ 048 public Device getDevice(); 049 050 /** 051 * Method to get the URN ({@link URI}) describing {@link.this} 052 * {@link Service}'s service type. 053 * 054 * @return The service type. 055 */ 056 public URI getServiceType(); 057 058 /** 059 * Method to get the URN ({@link URI}) describing {@link.this} 060 * {@link Service}'s service ID. 061 * 062 * @return The service type. 063 */ 064 public URI getServiceId(); 065 066 /** 067 * Method to get {@link.this} {@link Service}'s description (SCPD) 068 * {@code URL} (as an {@link URI}). 069 * 070 * @return The presentation {@link URI}. 071 */ 072 public URI getSCPDURL(); 073 074 /** 075 * Method to get {@link.this} {@link Service}'s control {@code URL} (as 076 * an {@link URI}). 077 * 078 * @return The presentation {@link URI}. 079 */ 080 public URI getControlURL(); 081 082 /** 083 * Method to get {@link.this} {@link Service}'s event subscription 084 * {@code URL} (as an {@link URI}). 085 * 086 * @return The presentation {@link URI}. 087 */ 088 public URI getEventSubURL(); 089 090 /** 091 * Method to get {@link.this} {@link Service}'s {@link Action}s. 092 * 093 * @return The {@link List} of {@link Action}s. 094 */ 095 public List<? extends Action> getActionList(); 096 097 /** 098 * Method to get {@link.this} {@link Service}'s {@link StateVariable}s. 099 * 100 * @return The {@link List} of {@link StateVariable}s. 101 */ 102 public List<? extends StateVariable> getServiceStateTable(); 103 104 @Override 105 default Map<URI,Set<URI>> getUSNMap() { 106 LinkedHashMap<URI,Set<URI>> map = new LinkedHashMap<>(); 107 Function<URI,Set<URI>> mapper = k -> new LinkedHashSet<>(); 108 109 map.computeIfAbsent(getUSN(getServiceType()), mapper) 110 .add(getServiceType()); 111 112 return map; 113 } 114 115 @Override 116 default URI getUSN(URI urn) { 117 return getDevice().getUSN(Objects.requireNonNull(urn)); 118 } 119}