blob: 1157a05d462300355a3ce13c402b5be43d1bc696 [file] [log] [blame]
Francesco Furfarid1072b52006-05-03 07:44:48 +00001/*
2 * Copyright 2006 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.felix.upnp.sample.binaryLight;
19
20import java.util.Dictionary;
21import java.util.Properties;
22
23import org.osgi.framework.BundleContext;
24import org.osgi.service.upnp.UPnPDevice;
25import org.osgi.service.upnp.UPnPIcon;
26import org.osgi.service.upnp.UPnPService;
27
28/*
29* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
30*/
31
32public class LightDevice implements UPnPDevice {
33
34 final private String DEVICE_ID = "uuid:Felix-BinaryLight";
35 private BundleContext context;
36 private LightModel model;
37 private LightUI ui;
38 private PowerSwitchService powerSwitch;
39 private UPnPService[] services;
40 private Dictionary dictionary;
41 private UPnPEventNotifier notifier;
42
43 public LightDevice(BundleContext context) {
44 this.context=context;
45 model = new LightModel();
46 ui = new LightUI(model);
47 powerSwitch = new PowerSwitchService(model);
48 services = new UPnPService[]{powerSwitch};
49 setupDeviceProperties();
50 buildEventNotifyer();
51 }
52
53 /**
54 *
55 */
56 private void buildEventNotifyer() {
57 notifier = new UPnPEventNotifier(context,DEVICE_ID,powerSwitch,model);
58 }
59
60 private void setupDeviceProperties(){
61 dictionary = new Properties();
62 dictionary.put(UPnPDevice.UPNP_EXPORT,"");
63 dictionary.put(
64 org.osgi.service
65 .device.Constants.DEVICE_CATEGORY,
66 new String[]{UPnPDevice.DEVICE_CATEGORY}
67 );
68 //dictionary.put(UPnPDevice.DEVICE_CATEGORY,new String[]{UPnPDevice.DEVICE_CATEGORY});
69 dictionary.put(UPnPDevice.FRIENDLY_NAME,"Felix OSGi-UPnP BinaryLight");
70 dictionary.put(UPnPDevice.MANUFACTURER,"Apache Software Foundation");
71 dictionary.put(UPnPDevice.MANUFACTURER_URL,"http://incubator.apache.org/felix/");
72 dictionary.put(UPnPDevice.MODEL_DESCRIPTION,"A BinaryLight device to test OSGi to UPnP service export");
73 dictionary.put(UPnPDevice.MODEL_NAME,"Lucciola");
74 dictionary.put(UPnPDevice.MODEL_NUMBER,"1.0");
75 dictionary.put(UPnPDevice.MODEL_URL,"http://incubator.apache.org/felix/lucciola");
76 dictionary.put(UPnPDevice.PRESENTATION_URL,"http://incubator.apache.org/felix/lucciola/presentation");
77 dictionary.put(UPnPDevice.SERIAL_NUMBER,"123456789");
78 dictionary.put(UPnPDevice.TYPE,"urn:schemas-upnp-org:device:BinaryLight:1");
79 dictionary.put(UPnPDevice.UDN,DEVICE_ID);
80 //dictionary.put(UPnPDevice.ID,dictionary.get(UPnPDevice.UDN));
81 dictionary.put(UPnPDevice.UPC,"1213456789");
82 }
83
84
85 /* (non-Javadoc)
86 * @see org.osgi.service.upnp.UPnPDevice#getService(java.lang.String)
87 */
88 public UPnPService getService(String serviceId) {
89 if (serviceId.equals(powerSwitch.getId())) return powerSwitch;
90 return null;
91 }
92
93 /* (non-Javadoc)
94 * @see org.osgi.service.upnp.UPnPDevice#getServices()
95 */
96 public UPnPService[] getServices() {
97 return services;
98 }
99
100 /* (non-Javadoc)
101 * @see org.osgi.service.upnp.UPnPDevice#getIcons(java.lang.String)
102 */
103 public UPnPIcon[] getIcons(String locale) {
104 UPnPIcon icon = new LightIcon();
105 return new UPnPIcon[]{icon} ;
106 }
107
108 /* (non-Javadoc)
109 * @see org.osgi.service.upnp.UPnPDevice#getDescriptions(java.lang.String)
110 */
111 public Dictionary getDescriptions(String locale) {
112 return dictionary;
113 }
114
115 /**
116 *
117 */
118 public void close() {
119 ui.dispose();
120 notifier.destroy();
121 }
122
123}