blob: 2931f9acf853d27daa840aa0b606c6276e0c8873 [file] [log] [blame]
Francesco Furfariec7e1752006-10-02 13:37:04 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
Francesco Furfaric37181b2006-04-04 23:50:50 +00009 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Francesco Furfaric37181b2006-04-04 23:50:50 +000011 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000012 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
Francesco Furfaric37181b2006-04-04 23:50:50 +000018 */
19
20package org.apache.felix.upnp.sample.tv;
21
22import java.util.HashMap;
23
24import org.osgi.service.upnp.UPnPAction;
25import org.osgi.service.upnp.UPnPService;
26import org.osgi.service.upnp.UPnPStateVariable;
Francesco Furfarif2a67912006-07-17 17:08:02 +000027/*
Karl Paulsd312acc2007-06-18 20:38:33 +000028* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Francesco Furfarif2a67912006-07-17 17:08:02 +000029*/
Francesco Furfaric37181b2006-04-04 23:50:50 +000030
31public class PowerService implements UPnPService {
32 final private String SERVICE_ID = "urn:schemas-upnp-org:serviceId:power:1";
33 final private String SERVICE_TYPE = "urn:schemas-upnp-org:service:power:1";
34 final private String VERSION ="1";
35
36 private PowerStateVariable power;
37 private ResultStateVariable result;
38 private UPnPStateVariable[] states;
39 private HashMap actions = new HashMap();
40
41
42 public PowerService(){
43 power = new PowerStateVariable();
44 result = new ResultStateVariable();
45 this.states = new UPnPStateVariable[]{power,result};
46
47 UPnPAction setPower= new SetPowerAction(power,result);
48 UPnPAction getPower = new GetPowerAction(power);
49 actions.put(setPower.getName(),setPower);
50 actions.put(getPower.getName(),getPower);
51
52 }
53
54 /* (non-Javadoc)
55 * @see org.osgi.service.upnp.UPnPService#getId()
56 */
57 public String getId() {
58 return SERVICE_ID;
59 }
60
61 /* (non-Javadoc)
62 * @see org.osgi.service.upnp.UPnPService#getType()
63 */
64 public String getType() {
65 return SERVICE_TYPE;
66 }
67
68 /* (non-Javadoc)
69 * @see org.osgi.service.upnp.UPnPService#getVersion()
70 */
71 public String getVersion() {
72 return VERSION;
73 }
74
75 /* (non-Javadoc)
76 * @see org.osgi.service.upnp.UPnPService#getAction(java.lang.String)
77 */
78 public UPnPAction getAction(String name) {
79 return (UPnPAction)actions.get(name);
80 }
81
82 /* (non-Javadoc)
83 * @see org.osgi.service.upnp.UPnPService#getActions()
84 */
85 public UPnPAction[] getActions() {
86 return (UPnPAction[])(actions.values()).toArray(new UPnPAction[]{});
87 }
88
89 /* (non-Javadoc)
90 * @see org.osgi.service.upnp.UPnPService#getStateVariables()
91 */
92 public UPnPStateVariable[] getStateVariables() {
93 return states;
94 }
95
96 /* (non-Javadoc)
97 * @see org.osgi.service.upnp.UPnPService#getStateVariable(java.lang.String)
98 */
99 public UPnPStateVariable getStateVariable(String name) {
100 if (name.equals("Power"))
101 return power;
102 else if (name.equals("Result"))
103 return result;
104 else return null;
105 }
106}