]> git.basschouten.com Git - openhab-addons.git/blob
6071779fc6ca892b83028fc7f0da31f2aadaa17f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 /* This file is based on:
14  *
15  * LaunchSession
16  * Connect SDK
17  *
18  * Copyright (c) 2014 LG Electronics.
19  * Created by Jeffrey Glenn on 07 Mar 2014
20  *
21  * Licensed under the Apache License, Version 2.0 (the "License");
22  * you may not use this file except in compliance with the License.
23  * You may obtain a copy of the License at
24  *
25  *     http://www.apache.org/licenses/LICENSE-2.0
26  *
27  * Unless required by applicable law or agreed to in writing, software
28  * distributed under the License is distributed on an "AS IS" BASIS,
29  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30  * See the License for the specific language governing permissions and
31  * limitations under the License.
32  */
33
34 package org.openhab.binding.lgwebos.internal.handler.core;
35
36 import org.openhab.binding.lgwebos.internal.handler.LGWebOSTVSocket;
37
38 /**
39  * {@link LaunchSession} is a value object to describe a session with an application running on WebOSTV.
40  *
41  * Any time anything is launched onto a first screen device, there will be important session information that needs to
42  * be tracked. {@link LaunchSession} tracks this data, and must be retained to perform certain actions within the
43  * session.
44  *
45  * @author Jeffrey Glenn - Connect SDK initial contribution
46  * @author Sebastian Prehn - Adoption for openHAB
47  */
48 public class LaunchSession {
49
50     private String appId;
51     private String appName;
52     private String sessionId;
53
54     private transient LGWebOSTVSocket socket;
55     private transient LaunchSessionType sessionType;
56
57     /**
58      * LaunchSession type is used to help DeviceService's know how to close a LaunchSession.
59      *
60      */
61     public enum LaunchSessionType {
62         /** Unknown LaunchSession type, may be unable to close this launch session */
63         Unknown,
64         /** LaunchSession represents a launched app */
65         App,
66         /** LaunchSession represents an external input picker that was launched */
67         ExternalInputPicker,
68         /** LaunchSession represents a media app */
69         Media,
70         /** LaunchSession represents a web app */
71         WebApp
72     }
73
74     public LaunchSession() {
75     }
76
77     /**
78      * Instantiates a LaunchSession object for a given app ID.
79      *
80      * @param appId System-specific, unique ID of the app
81      * @return the launch session
82      */
83     public static LaunchSession launchSessionForAppId(String appId) {
84         LaunchSession launchSession = new LaunchSession();
85         launchSession.appId = appId;
86         return launchSession;
87     }
88
89     /** @return System-specific, unique ID of the app (ex. youtube.leanback.v4, 0000134, hulu) */
90     public String getAppId() {
91         return appId;
92     }
93
94     /**
95      * Sets the system-specific, unique ID of the app (ex. youtube.leanback.v4, 0000134, hulu)
96      *
97      * @param appId Id of the app
98      */
99     public void setAppId(String appId) {
100         this.appId = appId;
101     }
102
103     /** @return User-friendly name of the app (ex. YouTube, Browser, Hulu) */
104     public String getAppName() {
105         return appName;
106     }
107
108     /**
109      * Sets the user-friendly name of the app (ex. YouTube, Browser, Hulu)
110      *
111      * @param appName Name of the app
112      */
113     public void setAppName(String appName) {
114         this.appName = appName;
115     }
116
117     /** @return Unique ID for the session (only provided by certain protocols) */
118     public String getSessionId() {
119         return sessionId;
120     }
121
122     /**
123      * Sets the session id (only provided by certain protocols)
124      *
125      * @param sessionId Id of the current session
126      */
127     public void setSessionId(String sessionId) {
128         this.sessionId = sessionId;
129     }
130
131     /** @return WebOSTVSocket responsible for launching the session. */
132     public LGWebOSTVSocket getService() {
133         return socket;
134     }
135
136     /**
137      * DeviceService responsible for launching the session.
138      *
139      * @param service Sets the DeviceService
140      */
141     public void setService(LGWebOSTVSocket service) {
142         this.socket = service;
143     }
144
145     /**
146      * @return When closing a LaunchSession, the DeviceService relies on the sessionType to determine the method of
147      *         closing the session.
148      */
149     public LaunchSessionType getSessionType() {
150         return sessionType;
151     }
152
153     /**
154      * Sets the LaunchSessionType of this LaunchSession.
155      *
156      * @param sessionType The type of LaunchSession
157      */
158     public void setSessionType(LaunchSessionType sessionType) {
159         this.sessionType = sessionType;
160     }
161
162     /**
163      * Close the app/media associated with the session.
164      *
165      * @param listener the response listener
166      */
167     public void close(ResponseListener<CommandConfirmation> listener) {
168         socket.closeLaunchSession(this, listener);
169     }
170 }