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 | d8bdb64 | 2006-04-04 23:33:40 +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 | d8bdb64 | 2006-04-04 23:33:40 +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 | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | package org.apache.felix.upnp.basedriver.export; |
| 21 | |
| 22 | |
| 23 | |
| 24 | import java.util.Dictionary; |
| 25 | import java.util.Enumeration; |
| 26 | |
| 27 | import org.cybergarage.upnp.Device; |
| 28 | import org.cybergarage.upnp.Service; |
| 29 | import org.cybergarage.upnp.StateVariable; |
| 30 | |
| 31 | import org.osgi.service.upnp.UPnPEventListener; |
| 32 | |
| 33 | import org.apache.felix.upnp.extra.util.Converter; |
| 34 | |
Francesco Furfari | f2a6791 | 2006-07-17 17:08:02 +0000 | [diff] [blame] | 35 | /* |
| 36 | * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a> |
| 37 | */ |
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 38 | public class ExporterUPnPEventListener implements UPnPEventListener { |
| 39 | |
| 40 | private Device d; |
| 41 | |
| 42 | public ExporterUPnPEventListener(Device d){ |
| 43 | this.d=d; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @see org.osgi.service.upnp.UPnPEventListener#notifyUPnPEvent(java.lang.String, java.lang.String, java.util.Dictionary) |
| 48 | */ |
| 49 | public void notifyUPnPEvent(String deviceId, String serviceId,Dictionary events) { |
| 50 | Device dAux = null; |
| 51 | if(d.getUDN().equals(deviceId)){ |
| 52 | dAux=d; |
| 53 | }else{ |
| 54 | dAux= d.getDevice(deviceId); |
| 55 | } |
| 56 | Service s = dAux.getService(serviceId); |
| 57 | // fix 2/9/2004 francesco |
| 58 | Enumeration e = events.keys(); |
| 59 | StateVariable sv; |
| 60 | while (e.hasMoreElements()) { |
| 61 | String name = (String) e.nextElement(); |
| 62 | sv=s.getStateVariable(name); |
| 63 | //sv.setValue((String) events.get(name)); |
| 64 | try { |
| 65 | sv.setValue(Converter.toString(events.get(name),sv.getDataType())); |
| 66 | } catch (Exception ignored) { |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | } |