Francesco Furfari | ec7e175 | 2006-10-02 13:37:04 +0000 | [diff] [blame] | 1 | /*
|
| 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 Furfari | d1072b5 | 2006-05-03 07:44:48 +0000 | [diff] [blame] | 9 | *
|
Francesco Furfari | ec7e175 | 2006-10-02 13:37:04 +0000 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0
|
Francesco Furfari | d1072b5 | 2006-05-03 07:44:48 +0000 | [diff] [blame] | 11 | *
|
Francesco Furfari | ec7e175 | 2006-10-02 13:37:04 +0000 | [diff] [blame] | 12 | * 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 Furfari | d1072b5 | 2006-05-03 07:44:48 +0000 | [diff] [blame] | 18 | */
|
Francesco Furfari | ec7e175 | 2006-10-02 13:37:04 +0000 | [diff] [blame] | 19 |
|
Francesco Furfari | d1072b5 | 2006-05-03 07:44:48 +0000 | [diff] [blame] | 20 | package org.apache.felix.upnp.sample.clock;
|
| 21 |
|
| 22 | import java.util.HashMap;
|
| 23 |
|
| 24 | import org.osgi.service.upnp.UPnPAction;
|
| 25 | import org.osgi.service.upnp.UPnPService;
|
| 26 | import org.osgi.service.upnp.UPnPStateVariable;
|
| 27 |
|
| 28 | /*
|
Karl Pauls | d312acc | 2007-06-18 20:38:33 +0000 | [diff] [blame^] | 29 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
|
Francesco Furfari | d1072b5 | 2006-05-03 07:44:48 +0000 | [diff] [blame] | 30 | */
|
| 31 |
|
| 32 | public 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 | }
|