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