blob: 76edcaaa22f211b5bbfb40588cc3cfb679927ab4 [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 Furfarid1072b52006-05-03 07:44:48 +00009 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Francesco Furfarid1072b52006-05-03 07:44:48 +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 Furfarid1072b52006-05-03 07:44:48 +000018 */
Francesco Furfariec7e1752006-10-02 13:37:04 +000019
Francesco Furfarid1072b52006-05-03 07:44:48 +000020package org.apache.felix.upnp.sample.clock;
21
22import java.util.HashMap;
23
24import org.osgi.service.upnp.UPnPAction;
25import org.osgi.service.upnp.UPnPService;
26import org.osgi.service.upnp.UPnPStateVariable;
27
28/*
Karl Paulsd312acc2007-06-18 20:38:33 +000029* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Francesco Furfarid1072b52006-05-03 07:44:48 +000030*/
31
32public class TimerService implements UPnPService {
33 final private String SERVICE_ID = "urn:schemas-upnp-org:serviceId:timer:1";
34 final private String SERVICE_TYPE = "urn:schemas-upnp-org:service:timer:1";
35 final private String VERSION ="1";
36
37 private UPnPStateVariable time,result;
38 private UPnPStateVariable[] states;
39 private HashMap actions = new HashMap();
40
41
42 public TimerService(){
43 time = new TimeStateVariable();
44 result = new ResultStateVariable();
45 this.states = new UPnPStateVariable[]{time,result};
46
47 UPnPAction setTime= new SetTimeAction(time,result);
48 UPnPAction getTime = new GetTimeAction((TimeStateVariable)time);
49 actions.put(setTime.getName(),setTime);
50 actions.put(getTime.getName(),getTime);
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("Time"))
101 return time;
102 else if (name.equals("Result"))
103 return result;
104 else return null;
105 }
106}