2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.samsungtv.internal.service;
15 import java.util.Collections;
16 import java.util.HashMap;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.samsungtv.internal.service.api.SamsungTvService;
22 import org.openhab.core.io.transport.upnp.UpnpIOService;
25 * The {@link ServiceFactory} is helper class for creating Samsung TV related
28 * @author Pauli Anttila - Initial contribution
31 public class ServiceFactory {
33 @SuppressWarnings("serial")
34 private static final Map<String, Class<? extends SamsungTvService>> SERVICEMAP = Collections
35 .unmodifiableMap(new HashMap<String, Class<? extends SamsungTvService>>() {
37 put(MainTVServerService.SERVICE_NAME, MainTVServerService.class);
38 put(MediaRendererService.SERVICE_NAME, MediaRendererService.class);
39 put(RemoteControllerService.SERVICE_NAME, RemoteControllerService.class);
44 * Create Samsung TV service.
47 * @param upnpIOService
53 public static @Nullable SamsungTvService createService(String type, UpnpIOService upnpIOService, String udn,
54 String host, int port) {
55 SamsungTvService service = null;
58 case MainTVServerService.SERVICE_NAME:
59 service = new MainTVServerService(upnpIOService, udn);
61 case MediaRendererService.SERVICE_NAME:
62 service = new MediaRendererService(upnpIOService, udn);
64 // will not be created automatically
65 case RemoteControllerService.SERVICE_NAME:
66 service = RemoteControllerService.createUpnpService(host, port);
75 * Procedure to query amount of supported services.
77 * @return Amount of supported services
79 public static int getServiceCount() {
80 return SERVICEMAP.size();
84 * Procedure to get service class by service name.
86 * @param serviceName Name of the service
87 * @return Class of the service
89 public static @Nullable Class<? extends SamsungTvService> getClassByServiceName(String serviceName) {
90 return SERVICEMAP.get(serviceName);