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 | */
|
| 19 |
|
| 20 | package org.apache.felix.upnp.sample.binaryLight;
|
| 21 |
|
Francesco Furfari | 63e117d | 2006-10-10 11:54:58 +0000 | [diff] [blame] | 22 | import java.net.InetAddress;
|
| 23 | import java.net.UnknownHostException;
|
Francesco Furfari | d1072b5 | 2006-05-03 07:44:48 +0000 | [diff] [blame] | 24 | import java.util.Dictionary;
|
| 25 | import java.util.Properties;
|
| 26 |
|
| 27 | import org.osgi.framework.BundleContext;
|
| 28 | import org.osgi.service.upnp.UPnPDevice;
|
| 29 | import org.osgi.service.upnp.UPnPIcon;
|
| 30 | import org.osgi.service.upnp.UPnPService;
|
| 31 |
|
| 32 | /*
|
Karl Pauls | d312acc | 2007-06-18 20:38:33 +0000 | [diff] [blame^] | 33 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
|
Francesco Furfari | d1072b5 | 2006-05-03 07:44:48 +0000 | [diff] [blame] | 34 | */
|
| 35 |
|
| 36 | public class LightDevice implements UPnPDevice {
|
| 37 |
|
| 38 | final private String DEVICE_ID = "uuid:Felix-BinaryLight";
|
| 39 | private BundleContext context;
|
| 40 | private LightModel model;
|
| 41 | private LightUI ui;
|
| 42 | private PowerSwitchService powerSwitch;
|
| 43 | private UPnPService[] services;
|
| 44 | private Dictionary dictionary;
|
| 45 | private UPnPEventNotifier notifier;
|
| 46 |
|
| 47 | public LightDevice(BundleContext context) {
|
| 48 | this.context=context;
|
| 49 | model = new LightModel();
|
| 50 | ui = new LightUI(model);
|
| 51 | powerSwitch = new PowerSwitchService(model);
|
| 52 | services = new UPnPService[]{powerSwitch};
|
| 53 | setupDeviceProperties();
|
| 54 | buildEventNotifyer();
|
| 55 | }
|
| 56 |
|
Francesco Furfari | 63e117d | 2006-10-10 11:54:58 +0000 | [diff] [blame] | 57 | public LightModel getModel(){
|
| 58 | return model;
|
| 59 | }
|
Francesco Furfari | d1072b5 | 2006-05-03 07:44:48 +0000 | [diff] [blame] | 60 | /**
|
| 61 | *
|
| 62 | */
|
| 63 | private void buildEventNotifyer() {
|
| 64 | notifier = new UPnPEventNotifier(context,DEVICE_ID,powerSwitch,model);
|
| 65 | }
|
| 66 |
|
| 67 | private void setupDeviceProperties(){
|
| 68 | dictionary = new Properties();
|
| 69 | dictionary.put(UPnPDevice.UPNP_EXPORT,"");
|
| 70 | dictionary.put(
|
| 71 | org.osgi.service
|
| 72 | .device.Constants.DEVICE_CATEGORY,
|
| 73 | new String[]{UPnPDevice.DEVICE_CATEGORY}
|
| 74 | );
|
| 75 | //dictionary.put(UPnPDevice.DEVICE_CATEGORY,new String[]{UPnPDevice.DEVICE_CATEGORY});
|
| 76 | dictionary.put(UPnPDevice.FRIENDLY_NAME,"Felix OSGi-UPnP BinaryLight");
|
| 77 | dictionary.put(UPnPDevice.MANUFACTURER,"Apache Software Foundation");
|
| 78 | dictionary.put(UPnPDevice.MANUFACTURER_URL,"http://incubator.apache.org/felix/");
|
| 79 | dictionary.put(UPnPDevice.MODEL_DESCRIPTION,"A BinaryLight device to test OSGi to UPnP service export");
|
| 80 | dictionary.put(UPnPDevice.MODEL_NAME,"Lucciola");
|
| 81 | dictionary.put(UPnPDevice.MODEL_NUMBER,"1.0");
|
| 82 | dictionary.put(UPnPDevice.MODEL_URL,"http://incubator.apache.org/felix/lucciola");
|
Francesco Furfari | 63e117d | 2006-10-10 11:54:58 +0000 | [diff] [blame] | 83 | String port = context.getProperty("org.osgi.service.http.port");
|
| 84 | InetAddress inet;
|
| 85 | try {
|
| 86 | inet = InetAddress.getLocalHost();
|
| 87 | String hostname = inet.getHostName();
|
| 88 | //String hostname = inet.getHostAddress();
|
| 89 | dictionary.put(UPnPDevice.PRESENTATION_URL,"http://"+hostname + ":"+port+"/upnp/binaryLight/");
|
| 90 | } catch (UnknownHostException e) {
|
| 91 | System.out.println("Warning: enable to cacth localhost name");
|
| 92 | }
|
Francesco Furfari | d1072b5 | 2006-05-03 07:44:48 +0000 | [diff] [blame] | 93 | dictionary.put(UPnPDevice.SERIAL_NUMBER,"123456789");
|
| 94 | dictionary.put(UPnPDevice.TYPE,"urn:schemas-upnp-org:device:BinaryLight:1");
|
| 95 | dictionary.put(UPnPDevice.UDN,DEVICE_ID);
|
| 96 | //dictionary.put(UPnPDevice.ID,dictionary.get(UPnPDevice.UDN));
|
| 97 | dictionary.put(UPnPDevice.UPC,"1213456789");
|
| 98 | }
|
| 99 |
|
| 100 |
|
| 101 | /* (non-Javadoc)
|
| 102 | * @see org.osgi.service.upnp.UPnPDevice#getService(java.lang.String)
|
| 103 | */
|
| 104 | public UPnPService getService(String serviceId) {
|
| 105 | if (serviceId.equals(powerSwitch.getId())) return powerSwitch;
|
| 106 | return null;
|
| 107 | }
|
| 108 |
|
| 109 | /* (non-Javadoc)
|
| 110 | * @see org.osgi.service.upnp.UPnPDevice#getServices()
|
| 111 | */
|
| 112 | public UPnPService[] getServices() {
|
| 113 | return services;
|
| 114 | }
|
| 115 |
|
| 116 | /* (non-Javadoc)
|
| 117 | * @see org.osgi.service.upnp.UPnPDevice#getIcons(java.lang.String)
|
| 118 | */
|
| 119 | public UPnPIcon[] getIcons(String locale) {
|
| 120 | UPnPIcon icon = new LightIcon();
|
| 121 | return new UPnPIcon[]{icon} ;
|
| 122 | }
|
| 123 |
|
| 124 | /* (non-Javadoc)
|
| 125 | * @see org.osgi.service.upnp.UPnPDevice#getDescriptions(java.lang.String)
|
| 126 | */
|
| 127 | public Dictionary getDescriptions(String locale) {
|
| 128 | return dictionary;
|
| 129 | }
|
| 130 |
|
| 131 | /**
|
| 132 | *
|
| 133 | */
|
| 134 | public void close() {
|
| 135 | ui.dispose();
|
| 136 | notifier.destroy();
|
| 137 | }
|
| 138 |
|
| 139 | }
|