blob: a21496576ffcbc0d659e2ea60d3503d6994592d4 [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 Furfarid8bdb642006-04-04 23:33:40 +00009 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Francesco Furfarid8bdb642006-04-04 23:33:40 +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 Furfarid8bdb642006-04-04 23:33:40 +000018 */
19
20package org.apache.felix.upnp.basedriver.export;
21
22
23
24import java.util.Dictionary;
25import java.util.Enumeration;
26
27import org.cybergarage.upnp.Device;
28import org.cybergarage.upnp.Service;
29import org.cybergarage.upnp.StateVariable;
30
31import org.osgi.service.upnp.UPnPEventListener;
32
33import org.apache.felix.upnp.extra.util.Converter;
34
Francesco Furfarif2a67912006-07-17 17:08:02 +000035/*
36* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
37*/
Francesco Furfarid8bdb642006-04-04 23:33:40 +000038public 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}