You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by le...@apache.org on 2008/07/08 18:59:57 UTC
svn commit: r674879 [9/12] - in /felix/trunk/upnp: ./ basedriver/
basedriver/src/main/java/org/apache/felix/upnp/basedriver/
basedriver/src/main/java/org/apache/felix/upnp/basedriver/controller/
basedriver/src/main/java/org/apache/felix/upnp/basedriver...
Modified: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/SetPowerAction.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/SetPowerAction.java?rev=674879&r1=674878&r2=674879&view=diff
==============================================================================
--- felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/SetPowerAction.java (original)
+++ felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/SetPowerAction.java Tue Jul 8 09:59:54 2008
@@ -1,91 +1,91 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.felix.upnp.sample.tv;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.osgi.service.upnp.UPnPAction;
-import org.osgi.service.upnp.UPnPStateVariable;
-
-public class SetPowerAction implements UPnPAction {
-
- final private String NAME = "SetPower";
- final private String NEW_TIME_VALUE = "Power";
- final private String NEW_RESULT_VALUE = "Result";
- final private String[] IN_ARG_NAMES = new String[]{NEW_TIME_VALUE};
- final private String[] OUT_ARG_NAMES = new String[]{NEW_RESULT_VALUE};
- private PowerStateVariable power;
- private ResultStateVariable result;
-
-
- public SetPowerAction(PowerStateVariable power,ResultStateVariable result){
- this.power = power;
- this.result=result;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPAction#getName()
- */
- public String getName() {
- return NAME;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPAction#getReturnArgumentName()
- */
- public String getReturnArgumentName() {
- return "Result";
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPAction#getInputArgumentNames()
- */
- public String[] getInputArgumentNames() {
- return IN_ARG_NAMES;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPAction#getOutputArgumentNames()
- */
- public String[] getOutputArgumentNames() {
- return OUT_ARG_NAMES;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPAction#getStateVariable(java.lang.String)
- */
- public UPnPStateVariable getStateVariable(String argumentName) {
- if (argumentName.equals("Power")) return power;
- else if (argumentName.equals("Result")) return result;
- else return null;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary)
- */
- public Dictionary invoke(Dictionary args) throws Exception {
- Boolean value = (Boolean) args.get(NEW_TIME_VALUE);
- power.setPower(value);
- Hashtable result = new Hashtable();
- result.put(NEW_RESULT_VALUE,Boolean.TRUE);
- return result;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.upnp.sample.tv;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.service.upnp.UPnPAction;
+import org.osgi.service.upnp.UPnPStateVariable;
+
+public class SetPowerAction implements UPnPAction {
+
+ final private String NAME = "SetPower";
+ final private String NEW_TIME_VALUE = "Power";
+ final private String NEW_RESULT_VALUE = "Result";
+ final private String[] IN_ARG_NAMES = new String[]{NEW_TIME_VALUE};
+ final private String[] OUT_ARG_NAMES = new String[]{NEW_RESULT_VALUE};
+ private PowerStateVariable power;
+ private ResultStateVariable result;
+
+
+ public SetPowerAction(PowerStateVariable power,ResultStateVariable result){
+ this.power = power;
+ this.result=result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPAction#getName()
+ */
+ public String getName() {
+ return NAME;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPAction#getReturnArgumentName()
+ */
+ public String getReturnArgumentName() {
+ return "Result";
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPAction#getInputArgumentNames()
+ */
+ public String[] getInputArgumentNames() {
+ return IN_ARG_NAMES;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPAction#getOutputArgumentNames()
+ */
+ public String[] getOutputArgumentNames() {
+ return OUT_ARG_NAMES;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPAction#getStateVariable(java.lang.String)
+ */
+ public UPnPStateVariable getStateVariable(String argumentName) {
+ if (argumentName.equals("Power")) return power;
+ else if (argumentName.equals("Result")) return result;
+ else return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary)
+ */
+ public Dictionary invoke(Dictionary args) throws Exception {
+ Boolean value = (Boolean) args.get(NEW_TIME_VALUE);
+ power.setPower(value);
+ Hashtable result = new Hashtable();
+ result.put(NEW_RESULT_VALUE,Boolean.TRUE);
+ return result;
+ }
+}
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/SetPowerAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/SetPowerAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/SetPowerAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvDevice.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvDevice.java?rev=674879&r1=674878&r2=674879&view=diff
==============================================================================
--- felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvDevice.java (original)
+++ felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvDevice.java Tue Jul 8 09:59:54 2008
@@ -1,319 +1,319 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.felix.upnp.sample.tv;
-
-import java.awt.Component;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Dictionary;
-import java.util.Properties;
-import java.util.Random;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.upnp.UPnPDevice;
-import org.osgi.service.upnp.UPnPEventListener;
-import org.osgi.service.upnp.UPnPIcon;
-import org.osgi.service.upnp.UPnPService;
-
-import org.apache.felix.upnp.extra.util.UPnPEventNotifier;
-import org.apache.felix.upnp.extra.util.UPnPSubscriber;
-
-public class TvDevice implements UPnPDevice,UPnPEventListener,ServiceListener {
-
- final private String DEVICE_ID = "uuid:Felix-TV+" +Integer.toHexString(new Random(System.currentTimeMillis()).nextInt());
- private final static String CLOCK_DEVICE_TYPE = "urn:schemas-upnp-org:device:clock:1";
- private final static String TIME_SERVICE_TYPE = "urn:schemas-upnp-org:service:timer:1";
-
- private final static String LIGHT_DEVICE_TYPE = "urn:schemas-upnp-org:device:light:1";
- private final static String POWER_SERVICE_TYPE = "urn:schemas-upnp-org:service:power:1";
-
- private final static String AIRCON_DEVICE_TYPE = "urn:schemas-upnp-org:device:aircon:1";
- private final static String TEMP_SERVICE_TYPE = "urn:schemas-upnp-org:service:temp:1";
-
- private final static String WASHER_DEVICE_TYPE = "urn:schemas-upnp-org:device:washer:1";
- private final static String STATUS_SERVICE_TYPE = "urn:schemas-upnp-org:service:state:1";
-
- private final String devicesFilter =
- "(&"+
- "("+Constants.OBJECTCLASS+"="+UPnPDevice.class.getName()+"))";
- /*"(|("+UPnPDevice.TYPE+"="+ CLOCK_SERVICE_TYPE+")"+
- "("+UPnPDevice.TYPE+"="+ LIGHT_SERVICE_TYPE+")"+
- "("+UPnPDevice.TYPE+"="+ AIRCON_SERVICE_TYPE+")"+
- "("+UPnPDevice.TYPE+"="+ WASHER_SERVICE_TYPE+")))";*/
-
- private BundleContext context;
- private PowerService powerService;
- private UPnPService[] services;
- private Dictionary dictionary;
- private UPnPEventNotifier notifier;
- private PowerStateVariable powerState;
-
- public TvDevice() {
- powerService = new PowerService();
- services = new UPnPService[]{powerService};
- powerState = (PowerStateVariable) powerService.getStateVariable("Power");
- setupDeviceProperties();
- buildEventNotifyer();
- try {
- Activator.context.addServiceListener(this,devicesFilter);
- } catch (InvalidSyntaxException e) {
- System.out.println(e);
- }
- }
-
- /**
- *
- */
- private void buildEventNotifyer() {
- notifier = new UPnPEventNotifier(Activator.context,this,powerService);
- powerState.setNotifier(notifier);
- }
-
- private void setupDeviceProperties(){
- dictionary = new Properties();
- dictionary.put(UPnPDevice.UPNP_EXPORT,"");
- //org.osgi.service.device.Constants.DEVICE_CATEGORY
- //dictionary.put("DEVICE_CATEGORY","UPnP");
- dictionary.put(
- org.osgi.service
- .device.Constants.DEVICE_CATEGORY,
- new String[]{UPnPDevice.DEVICE_CATEGORY}
- );
- dictionary.put(UPnPDevice.FRIENDLY_NAME,"Felix Sample Tv");
- dictionary.put(UPnPDevice.MANUFACTURER,"Apache Software Foundation");
- dictionary.put(UPnPDevice.MANUFACTURER_URL,"http://felix.apache.org");
- dictionary.put(UPnPDevice.MODEL_DESCRIPTION,"A CyberLink Tv device clone to test OSGi to UPnP service import");
- dictionary.put(UPnPDevice.MODEL_NAME,"BimbiTv");
- dictionary.put(UPnPDevice.MODEL_NUMBER,"1.0");
- dictionary.put(UPnPDevice.MODEL_URL,"http://felix.apache.org/site/upnp-examples.html");
- //dictionary.put(UPnPDevice.PRESENTATION_URL,"http://felix.apache.org/BimbiTv/presentation");
- dictionary.put(UPnPDevice.SERIAL_NUMBER,"123456789");
- dictionary.put(UPnPDevice.TYPE,"urn:schemas-upnp-org:device:tv:1");
- dictionary.put(UPnPDevice.UDN,DEVICE_ID);
- //dictionary.put(UPnPDevice.ID,dictionary.get(UPnPDevice.UDN));
- dictionary.put(UPnPDevice.UPC,"1213456789");
- }
-
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPDevice#getService(java.lang.String)
- */
- public UPnPService getService(String serviceId) {
- if (serviceId.equals(powerService.getId())) return powerService;
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPDevice#getServices()
- */
- public UPnPService[] getServices() {
- return services;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPDevice#getIcons(java.lang.String)
- */
- public UPnPIcon[] getIcons(String locale) {
- UPnPIcon icon = new TvIcon();
- return new UPnPIcon[]{icon} ;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPDevice#getDescriptions(java.lang.String)
- */
- public Dictionary getDescriptions(String locale) {
- return dictionary;
- }
-
-
-
- ////////////////////////////////////////////////
- // Component
- ////////////////////////////////////////////////
-
- private Component comp;
-
- public void setComponent(Component comp)
- {
- this.comp = comp;
- }
-
- public Component getComponent()
- {
- return comp;
- }
-
- ////////////////////////////////////////////////
- // on/off
- ////////////////////////////////////////////////
-
- private boolean onFlag = false;
-
- public void on()
- {
- powerState.setPower(Boolean.TRUE);
- doSubscribe();
- }
-
- public boolean isOn()
- {
- return powerState.getCurrentPower().booleanValue();
- }
- public void off()
- {
- powerState.setPower(Boolean.FALSE);
- undoSubscribe();
- }
-
-
- ////////////////////////////////////////////////
- // Clock
- ////////////////////////////////////////////////
-
- private String clockTime = "";
-
- public String getClockTime()
- {
- return clockTime;
- }
-
- ////////////////////////////////////////////////
- // Aircon
- ////////////////////////////////////////////////
-
- private String airconTemp = "";
-
- public String getAirconTempture()
- {
- return airconTemp;
- }
-
- ////////////////////////////////////////////////
- // Message
- ////////////////////////////////////////////////
-
- private String message = "";
-
- public void setMessage(String msg)
- {
- message = msg;
- }
-
- public String getMessage()
- {
- return message;
- }
-
-
- ////////////////////////////////////////////////
- // Subscribe
- ////////////////////////////////////////////////
-
- private UPnPSubscriber subscriber;
-
- public void doSubscribe()
- {
- subscriber = new UPnPSubscriber(Activator.context,this);
- subscriber.subscribeEveryServiceType(CLOCK_DEVICE_TYPE, TIME_SERVICE_TYPE);
- subscriber.subscribeEveryServiceType(AIRCON_DEVICE_TYPE, TEMP_SERVICE_TYPE);
- subscriber.subscribeEveryServiceType(LIGHT_DEVICE_TYPE, POWER_SERVICE_TYPE);
- subscriber.subscribeEveryServiceType(WASHER_DEVICE_TYPE, STATUS_SERVICE_TYPE);
- }
-
- public void undoSubscribe(){
- subscriber.unsubscribeAll();
- }
-
- ArrayList LinkedDevices = new ArrayList();
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPEventListener#notifyUPnPEvent(java.lang.String, java.lang.String, java.util.Dictionary)
- */
- public void notifyUPnPEvent(String deviceId, String serviceId, Dictionary events) {
- if( !LinkedDevices.contains(deviceId))
- LinkedDevices.add(deviceId);
- if (deviceId.indexOf("Clock") != -1){
- Long time = (Long) events.get("Time");
- clockTime = new Date(time.longValue()).toString();
- }
- else if (deviceId.indexOf("AirCon") != -1)
- airconTemp = (String) events.get("Temp");
- else if (deviceId.indexOf("Washer") != -1)
- message = (String) events.get("State");
- else if (deviceId.indexOf("Light") != -1)
- message = (String) events.get("Power");
-
- comp.repaint();
- }
-
-
- ////////////////////////////////////////////////
- // start/stop
- ////////////////////////////////////////////////
-
- public void start()
- {
- on();
- }
-
- public void stop()
- {
- ((PowerStateVariable) powerService.getStateVariable("Power")).setNotifier(null);
- notifier.destroy();
- off();
- }
-
- /* (non-Javadoc)
- * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
- */
- public void serviceChanged(ServiceEvent event) {
- switch(event.getType()){
- case ServiceEvent.REGISTERED:{
- };break;
-
- case ServiceEvent.MODIFIED:{
- };break;
-
- case ServiceEvent.UNREGISTERING:{
- ServiceReference sr = event.getServiceReference();
- String UDN = (String)sr.getProperty(UPnPDevice.ID);
- if (UDN != null){
- if (LinkedDevices.contains(UDN)) {
- if (UDN.indexOf("Clock") != -1)
- clockTime = "";
- else if (UDN.indexOf("AirCon") != -1)
- airconTemp = "";
- else if (UDN.indexOf("Washer") != -1)
- message = "";
- else if (UDN.indexOf("Light") != -1)
- message = "";
- }
- }
- comp.repaint();
- };break;
- }
- }
-
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.upnp.sample.tv;
+
+import java.awt.Component;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Dictionary;
+import java.util.Properties;
+import java.util.Random;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPEventListener;
+import org.osgi.service.upnp.UPnPIcon;
+import org.osgi.service.upnp.UPnPService;
+
+import org.apache.felix.upnp.extra.util.UPnPEventNotifier;
+import org.apache.felix.upnp.extra.util.UPnPSubscriber;
+
+public class TvDevice implements UPnPDevice,UPnPEventListener,ServiceListener {
+
+ final private String DEVICE_ID = "uuid:Felix-TV+" +Integer.toHexString(new Random(System.currentTimeMillis()).nextInt());
+ private final static String CLOCK_DEVICE_TYPE = "urn:schemas-upnp-org:device:clock:1";
+ private final static String TIME_SERVICE_TYPE = "urn:schemas-upnp-org:service:timer:1";
+
+ private final static String LIGHT_DEVICE_TYPE = "urn:schemas-upnp-org:device:light:1";
+ private final static String POWER_SERVICE_TYPE = "urn:schemas-upnp-org:service:power:1";
+
+ private final static String AIRCON_DEVICE_TYPE = "urn:schemas-upnp-org:device:aircon:1";
+ private final static String TEMP_SERVICE_TYPE = "urn:schemas-upnp-org:service:temp:1";
+
+ private final static String WASHER_DEVICE_TYPE = "urn:schemas-upnp-org:device:washer:1";
+ private final static String STATUS_SERVICE_TYPE = "urn:schemas-upnp-org:service:state:1";
+
+ private final String devicesFilter =
+ "(&"+
+ "("+Constants.OBJECTCLASS+"="+UPnPDevice.class.getName()+"))";
+ /*"(|("+UPnPDevice.TYPE+"="+ CLOCK_SERVICE_TYPE+")"+
+ "("+UPnPDevice.TYPE+"="+ LIGHT_SERVICE_TYPE+")"+
+ "("+UPnPDevice.TYPE+"="+ AIRCON_SERVICE_TYPE+")"+
+ "("+UPnPDevice.TYPE+"="+ WASHER_SERVICE_TYPE+")))";*/
+
+ private BundleContext context;
+ private PowerService powerService;
+ private UPnPService[] services;
+ private Dictionary dictionary;
+ private UPnPEventNotifier notifier;
+ private PowerStateVariable powerState;
+
+ public TvDevice() {
+ powerService = new PowerService();
+ services = new UPnPService[]{powerService};
+ powerState = (PowerStateVariable) powerService.getStateVariable("Power");
+ setupDeviceProperties();
+ buildEventNotifyer();
+ try {
+ Activator.context.addServiceListener(this,devicesFilter);
+ } catch (InvalidSyntaxException e) {
+ System.out.println(e);
+ }
+ }
+
+ /**
+ *
+ */
+ private void buildEventNotifyer() {
+ notifier = new UPnPEventNotifier(Activator.context,this,powerService);
+ powerState.setNotifier(notifier);
+ }
+
+ private void setupDeviceProperties(){
+ dictionary = new Properties();
+ dictionary.put(UPnPDevice.UPNP_EXPORT,"");
+ //org.osgi.service.device.Constants.DEVICE_CATEGORY
+ //dictionary.put("DEVICE_CATEGORY","UPnP");
+ dictionary.put(
+ org.osgi.service
+ .device.Constants.DEVICE_CATEGORY,
+ new String[]{UPnPDevice.DEVICE_CATEGORY}
+ );
+ dictionary.put(UPnPDevice.FRIENDLY_NAME,"Felix Sample Tv");
+ dictionary.put(UPnPDevice.MANUFACTURER,"Apache Software Foundation");
+ dictionary.put(UPnPDevice.MANUFACTURER_URL,"http://felix.apache.org");
+ dictionary.put(UPnPDevice.MODEL_DESCRIPTION,"A CyberLink Tv device clone to test OSGi to UPnP service import");
+ dictionary.put(UPnPDevice.MODEL_NAME,"BimbiTv");
+ dictionary.put(UPnPDevice.MODEL_NUMBER,"1.0");
+ dictionary.put(UPnPDevice.MODEL_URL,"http://felix.apache.org/site/upnp-examples.html");
+ //dictionary.put(UPnPDevice.PRESENTATION_URL,"http://felix.apache.org/BimbiTv/presentation");
+ dictionary.put(UPnPDevice.SERIAL_NUMBER,"123456789");
+ dictionary.put(UPnPDevice.TYPE,"urn:schemas-upnp-org:device:tv:1");
+ dictionary.put(UPnPDevice.UDN,DEVICE_ID);
+ //dictionary.put(UPnPDevice.ID,dictionary.get(UPnPDevice.UDN));
+ dictionary.put(UPnPDevice.UPC,"1213456789");
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPDevice#getService(java.lang.String)
+ */
+ public UPnPService getService(String serviceId) {
+ if (serviceId.equals(powerService.getId())) return powerService;
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPDevice#getServices()
+ */
+ public UPnPService[] getServices() {
+ return services;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPDevice#getIcons(java.lang.String)
+ */
+ public UPnPIcon[] getIcons(String locale) {
+ UPnPIcon icon = new TvIcon();
+ return new UPnPIcon[]{icon} ;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPDevice#getDescriptions(java.lang.String)
+ */
+ public Dictionary getDescriptions(String locale) {
+ return dictionary;
+ }
+
+
+
+ ////////////////////////////////////////////////
+ // Component
+ ////////////////////////////////////////////////
+
+ private Component comp;
+
+ public void setComponent(Component comp)
+ {
+ this.comp = comp;
+ }
+
+ public Component getComponent()
+ {
+ return comp;
+ }
+
+ ////////////////////////////////////////////////
+ // on/off
+ ////////////////////////////////////////////////
+
+ private boolean onFlag = false;
+
+ public void on()
+ {
+ powerState.setPower(Boolean.TRUE);
+ doSubscribe();
+ }
+
+ public boolean isOn()
+ {
+ return powerState.getCurrentPower().booleanValue();
+ }
+ public void off()
+ {
+ powerState.setPower(Boolean.FALSE);
+ undoSubscribe();
+ }
+
+
+ ////////////////////////////////////////////////
+ // Clock
+ ////////////////////////////////////////////////
+
+ private String clockTime = "";
+
+ public String getClockTime()
+ {
+ return clockTime;
+ }
+
+ ////////////////////////////////////////////////
+ // Aircon
+ ////////////////////////////////////////////////
+
+ private String airconTemp = "";
+
+ public String getAirconTempture()
+ {
+ return airconTemp;
+ }
+
+ ////////////////////////////////////////////////
+ // Message
+ ////////////////////////////////////////////////
+
+ private String message = "";
+
+ public void setMessage(String msg)
+ {
+ message = msg;
+ }
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+
+ ////////////////////////////////////////////////
+ // Subscribe
+ ////////////////////////////////////////////////
+
+ private UPnPSubscriber subscriber;
+
+ public void doSubscribe()
+ {
+ subscriber = new UPnPSubscriber(Activator.context,this);
+ subscriber.subscribeEveryServiceType(CLOCK_DEVICE_TYPE, TIME_SERVICE_TYPE);
+ subscriber.subscribeEveryServiceType(AIRCON_DEVICE_TYPE, TEMP_SERVICE_TYPE);
+ subscriber.subscribeEveryServiceType(LIGHT_DEVICE_TYPE, POWER_SERVICE_TYPE);
+ subscriber.subscribeEveryServiceType(WASHER_DEVICE_TYPE, STATUS_SERVICE_TYPE);
+ }
+
+ public void undoSubscribe(){
+ subscriber.unsubscribeAll();
+ }
+
+ ArrayList LinkedDevices = new ArrayList();
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPEventListener#notifyUPnPEvent(java.lang.String, java.lang.String, java.util.Dictionary)
+ */
+ public void notifyUPnPEvent(String deviceId, String serviceId, Dictionary events) {
+ if( !LinkedDevices.contains(deviceId))
+ LinkedDevices.add(deviceId);
+ if (deviceId.indexOf("Clock") != -1){
+ Long time = (Long) events.get("Time");
+ clockTime = new Date(time.longValue()).toString();
+ }
+ else if (deviceId.indexOf("AirCon") != -1)
+ airconTemp = (String) events.get("Temp");
+ else if (deviceId.indexOf("Washer") != -1)
+ message = (String) events.get("State");
+ else if (deviceId.indexOf("Light") != -1)
+ message = (String) events.get("Power");
+
+ comp.repaint();
+ }
+
+
+ ////////////////////////////////////////////////
+ // start/stop
+ ////////////////////////////////////////////////
+
+ public void start()
+ {
+ on();
+ }
+
+ public void stop()
+ {
+ ((PowerStateVariable) powerService.getStateVariable("Power")).setNotifier(null);
+ notifier.destroy();
+ off();
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+ */
+ public void serviceChanged(ServiceEvent event) {
+ switch(event.getType()){
+ case ServiceEvent.REGISTERED:{
+ };break;
+
+ case ServiceEvent.MODIFIED:{
+ };break;
+
+ case ServiceEvent.UNREGISTERING:{
+ ServiceReference sr = event.getServiceReference();
+ String UDN = (String)sr.getProperty(UPnPDevice.ID);
+ if (UDN != null){
+ if (LinkedDevices.contains(UDN)) {
+ if (UDN.indexOf("Clock") != -1)
+ clockTime = "";
+ else if (UDN.indexOf("AirCon") != -1)
+ airconTemp = "";
+ else if (UDN.indexOf("Washer") != -1)
+ message = "";
+ else if (UDN.indexOf("Light") != -1)
+ message = "";
+ }
+ }
+ comp.repaint();
+ };break;
+ }
+ }
+
+}
+
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvDevice.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvDevice.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvDevice.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvFrame.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvFrame.java?rev=674879&r1=674878&r2=674879&view=diff
==============================================================================
--- felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvFrame.java (original)
+++ felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvFrame.java Tue Jul 8 09:59:54 2008
@@ -1,123 +1,123 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.felix.upnp.sample.tv;
-
-import java.awt.BorderLayout;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.net.URL;
-
-import javax.swing.ImageIcon;
-import javax.swing.JFrame;
-
-import org.osgi.framework.BundleException;
-
-public class TvFrame extends JFrame implements Runnable
-{
- private final static String TITLE = "Felix UpnP TV";
-
- private TvDevice tvDev;
- private TvPane tvPane;
-
- public TvFrame()
- {
- super(TITLE);
-
- tvDev = new TvDevice();
-
- getContentPane().setLayout(new BorderLayout());
-
- tvPane = new TvPane();
- tvDev.setComponent(tvPane);
- tvPane.setDevice(tvDev);
- getContentPane().add(tvPane, BorderLayout.CENTER);
-
- addWindowListener(new WindowAdapter(){
- public void windowClosing(WindowEvent e)
- {
- try {
- Activator.context.getBundle().stop();
- } catch (BundleException ex) {
- ex.printStackTrace();
- }
- }
- });
-
- try {
- URL eventIconUrl = TvFrame.class.getResource("images/logo.gif");
- ImageIcon icon= new ImageIcon(eventIconUrl,"logo");
- setIconImage(icon.getImage());
- }
- catch (Exception ex){
- System.out.println("Resource: IMAGES/logo.gif not found : " + ex.toString());
- }
-
- pack();
- setVisible(true);
- }
-
- public TvPane getTvPanel()
- {
- return tvPane;
- }
-
- public TvDevice getTvDevice()
- {
- return tvDev;
- }
-
- ////////////////////////////////////////////////
- // run
- ////////////////////////////////////////////////
-
- private Thread timerThread = null;
-
- public void run()
- {
- Thread thisThread = Thread.currentThread();
-
- while (timerThread == thisThread) {
- tvDev.setMessage("");
- tvPane.repaint();
- try {
- Thread.sleep(1000*5);
- }
- catch(InterruptedException e) {}
- }
- }
-
- public void start()
- {
- tvDev.start();
-
- timerThread = new Thread(this,"upnp.sample.tv.TVFrame");
- timerThread.start();
- }
-
- public void stop()
- {
- tvDev.stop();
- timerThread = null;
- dispose();
- }
-
-
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.upnp.sample.tv;
+
+import java.awt.BorderLayout;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+import javax.swing.JFrame;
+
+import org.osgi.framework.BundleException;
+
+public class TvFrame extends JFrame implements Runnable
+{
+ private final static String TITLE = "Felix UpnP TV";
+
+ private TvDevice tvDev;
+ private TvPane tvPane;
+
+ public TvFrame()
+ {
+ super(TITLE);
+
+ tvDev = new TvDevice();
+
+ getContentPane().setLayout(new BorderLayout());
+
+ tvPane = new TvPane();
+ tvDev.setComponent(tvPane);
+ tvPane.setDevice(tvDev);
+ getContentPane().add(tvPane, BorderLayout.CENTER);
+
+ addWindowListener(new WindowAdapter(){
+ public void windowClosing(WindowEvent e)
+ {
+ try {
+ Activator.context.getBundle().stop();
+ } catch (BundleException ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+
+ try {
+ URL eventIconUrl = TvFrame.class.getResource("images/logo.gif");
+ ImageIcon icon= new ImageIcon(eventIconUrl,"logo");
+ setIconImage(icon.getImage());
+ }
+ catch (Exception ex){
+ System.out.println("Resource: IMAGES/logo.gif not found : " + ex.toString());
+ }
+
+ pack();
+ setVisible(true);
+ }
+
+ public TvPane getTvPanel()
+ {
+ return tvPane;
+ }
+
+ public TvDevice getTvDevice()
+ {
+ return tvDev;
+ }
+
+ ////////////////////////////////////////////////
+ // run
+ ////////////////////////////////////////////////
+
+ private Thread timerThread = null;
+
+ public void run()
+ {
+ Thread thisThread = Thread.currentThread();
+
+ while (timerThread == thisThread) {
+ tvDev.setMessage("");
+ tvPane.repaint();
+ try {
+ Thread.sleep(1000*5);
+ }
+ catch(InterruptedException e) {}
+ }
+ }
+
+ public void start()
+ {
+ tvDev.start();
+
+ timerThread = new Thread(this,"upnp.sample.tv.TVFrame");
+ timerThread.start();
+ }
+
+ public void stop()
+ {
+ tvDev.stop();
+ timerThread = null;
+ dispose();
+ }
+
+
+}
+
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvFrame.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvFrame.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvFrame.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvIcon.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvIcon.java?rev=674879&r1=674878&r2=674879&view=diff
==============================================================================
--- felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvIcon.java (original)
+++ felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvIcon.java Tue Jul 8 09:59:54 2008
@@ -1,69 +1,69 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.felix.upnp.sample.tv;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.osgi.service.upnp.UPnPIcon;
-
-public class TvIcon implements UPnPIcon {
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPIcon#getMimeType()
- */
- public String getMimeType() {
- return "image/gif";
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPIcon#getWidth()
- */
- public int getWidth() {
- return 32;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPIcon#getHeight()
- */
- public int getHeight() {
- return 32;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPIcon#getSize()
- */
- public int getSize() {
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPIcon#getDepth()
- */
- public int getDepth() {
- return 16;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.service.upnp.UPnPIcon#getInputStream()
- */
- public InputStream getInputStream() throws IOException {
- return TvIcon.class.getResourceAsStream("images/tv.gif");
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.upnp.sample.tv;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.osgi.service.upnp.UPnPIcon;
+
+public class TvIcon implements UPnPIcon {
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPIcon#getMimeType()
+ */
+ public String getMimeType() {
+ return "image/gif";
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPIcon#getWidth()
+ */
+ public int getWidth() {
+ return 32;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPIcon#getHeight()
+ */
+ public int getHeight() {
+ return 32;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPIcon#getSize()
+ */
+ public int getSize() {
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPIcon#getDepth()
+ */
+ public int getDepth() {
+ return 16;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.upnp.UPnPIcon#getInputStream()
+ */
+ public InputStream getInputStream() throws IOException {
+ return TvIcon.class.getResourceAsStream("images/tv.gif");
+ }
+}
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvIcon.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvIcon.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvIcon.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvPane.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvPane.java?rev=674879&r1=674878&r2=674879&view=diff
==============================================================================
--- felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvPane.java (original)
+++ felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvPane.java Tue Jul 8 09:59:54 2008
@@ -1,214 +1,214 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.felix.upnp.sample.tv;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Graphics;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-
-import javax.imageio.ImageIO;
-import javax.swing.JPanel;
-
-public class TvPane extends JPanel // MouseListener
-{
- private final static int IMAGE_BORDER_SIZE = 20;
- private final static int IMAGE_BOTTOM_BORDER_SIZE = 30;
-
- ////////////////////////////////////////////////
- // Constructor
- ////////////////////////////////////////////////
-
- public TvPane()
- {
- loadImage();
- initPanel();
- }
-
- ////////////////////////////////////////////////
- // TvDevice
- ////////////////////////////////////////////////
-
- private TvDevice tvDev = null;
-
- public void setDevice(TvDevice dev)
- {
- tvDev = dev;
- }
-
- public TvDevice getDevice()
- {
- return tvDev;
- }
-
- ////////////////////////////////////////////////
- // Background
- ////////////////////////////////////////////////
-
- private BufferedImage panelmage;
- private BufferedImage tvOnImage;
-
- private void loadImage()
- {
- try {
- panelmage = ImageIO.read(TvPane.class.getResourceAsStream("images/tv.jpg"));
- tvOnImage = ImageIO.read(TvPane.class.getResourceAsStream("images/tvon.jpg"));
- }
- catch (Exception e) {
- System.out.println(e);
- }
- }
-
- ////////////////////////////////////////////////
- // Background
- ////////////////////////////////////////////////
-
- private void initPanel()
- {
- setPreferredSize(new Dimension(panelmage.getWidth(), panelmage.getHeight()));
- }
-
- ////////////////////////////////////////////////
- // Font
- ////////////////////////////////////////////////
-
- private final static String DEFAULT_FONT_NAME = "Lucida Console";
- private final static int DEFAULT_TIME_FONT_SIZE = 10;
-
- private Font timeFont = null;
-
- private Font getFont(Graphics g, int size)
- {
- Font font = new Font(DEFAULT_FONT_NAME, Font.BOLD, size);
- if (font != null)
- return font;
- return g.getFont();
- }
-
- private Font getFont(Graphics g)
- {
- if (timeFont == null)
- timeFont = getFont(g, DEFAULT_TIME_FONT_SIZE);
- return timeFont;
- }
-
- ////////////////////////////////////////////////
- // paint
- ////////////////////////////////////////////////
-
- private void drawClockInfo(Graphics g)
- {
- TvDevice tvDev = getDevice();
-
- int winWidth = getWidth();
- int winHeight = getHeight();
-
- Font font = getFont(g);
- g.setFont(font);
- FontMetrics fontMetric = g.getFontMetrics();
- g.setColor(Color.RED);
-
- Rectangle2D strBounds;
- int strWidth;
- int strHeight;
- int strX;
- int strY;
-
- //// Time String ////
-
- String timeStr = tvDev.getClockTime();
- if (timeStr != null && 0 < timeStr.length()) {
- strBounds = fontMetric.getStringBounds(timeStr, g);
- strWidth = (int)strBounds.getWidth();
- strHeight = (int)strBounds.getHeight();
- strX = IMAGE_BORDER_SIZE;
- strY = IMAGE_BORDER_SIZE + strHeight;
- g.drawString(
- timeStr,
- strX,
- strY);
- }
-
- //// Tempture String ////
-
- String tempStr = tvDev.getAirconTempture();
- if (tempStr != null && 0 < tempStr.length()) {
- tempStr += "C";
- strBounds = fontMetric.getStringBounds(tempStr, g);
- strWidth = (int)strBounds.getWidth();
- strHeight = (int)strBounds.getHeight();
- strX = winWidth - IMAGE_BORDER_SIZE - strWidth;
- strY = IMAGE_BORDER_SIZE + strHeight;
- g.drawString(
- tempStr,
- strX,
- strY);
- }
-
- //// Message String ////
-
- String msgStr = tvDev.getMessage();
- if (msgStr != null && 0 < msgStr.length()) {
- strBounds = fontMetric.getStringBounds(msgStr, g);
- strWidth = (int)strBounds.getWidth();
- strHeight = (int)strBounds.getHeight();
- strX = IMAGE_BORDER_SIZE;
- strY = getHeight()-IMAGE_BOTTOM_BORDER_SIZE-2;
- g.drawString(
- msgStr,
- strX,
- strY);
- }
- }
-
- private void drawTvImage(Graphics g)
- {
- //g.setColor(Color.WHITE);
- //g.clearRect(IMAGE_BORDER_SIZE, IMAGE_BORDER_SIZE, getWidth()-IMAGE_BORDER_SIZE*2, getHeight()-IMAGE_BORDER_SIZE-IMAGE_BOTTOM_BORDER_SIZE);
- g.drawImage(tvOnImage, IMAGE_BORDER_SIZE, IMAGE_BORDER_SIZE, null);
- }
-
- private void clear(Graphics g)
- {
- g.setColor(Color.GRAY);
- g.clearRect(0, 0, getWidth(), getHeight());
- }
-
-
- private void drawPanelImage(Graphics g)
- {
- g.drawImage(panelmage, 0, 0, null);
- }
-
- public void paint(Graphics g)
- {
- clear(g);
- drawPanelImage(g);
- TvDevice tvDev = getDevice();
- if (tvDev.isOn() == true) {
- drawTvImage(g);
- drawClockInfo(g);
- }
- }
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.upnp.sample.tv;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+
+import javax.imageio.ImageIO;
+import javax.swing.JPanel;
+
+public class TvPane extends JPanel // MouseListener
+{
+ private final static int IMAGE_BORDER_SIZE = 20;
+ private final static int IMAGE_BOTTOM_BORDER_SIZE = 30;
+
+ ////////////////////////////////////////////////
+ // Constructor
+ ////////////////////////////////////////////////
+
+ public TvPane()
+ {
+ loadImage();
+ initPanel();
+ }
+
+ ////////////////////////////////////////////////
+ // TvDevice
+ ////////////////////////////////////////////////
+
+ private TvDevice tvDev = null;
+
+ public void setDevice(TvDevice dev)
+ {
+ tvDev = dev;
+ }
+
+ public TvDevice getDevice()
+ {
+ return tvDev;
+ }
+
+ ////////////////////////////////////////////////
+ // Background
+ ////////////////////////////////////////////////
+
+ private BufferedImage panelmage;
+ private BufferedImage tvOnImage;
+
+ private void loadImage()
+ {
+ try {
+ panelmage = ImageIO.read(TvPane.class.getResourceAsStream("images/tv.jpg"));
+ tvOnImage = ImageIO.read(TvPane.class.getResourceAsStream("images/tvon.jpg"));
+ }
+ catch (Exception e) {
+ System.out.println(e);
+ }
+ }
+
+ ////////////////////////////////////////////////
+ // Background
+ ////////////////////////////////////////////////
+
+ private void initPanel()
+ {
+ setPreferredSize(new Dimension(panelmage.getWidth(), panelmage.getHeight()));
+ }
+
+ ////////////////////////////////////////////////
+ // Font
+ ////////////////////////////////////////////////
+
+ private final static String DEFAULT_FONT_NAME = "Lucida Console";
+ private final static int DEFAULT_TIME_FONT_SIZE = 10;
+
+ private Font timeFont = null;
+
+ private Font getFont(Graphics g, int size)
+ {
+ Font font = new Font(DEFAULT_FONT_NAME, Font.BOLD, size);
+ if (font != null)
+ return font;
+ return g.getFont();
+ }
+
+ private Font getFont(Graphics g)
+ {
+ if (timeFont == null)
+ timeFont = getFont(g, DEFAULT_TIME_FONT_SIZE);
+ return timeFont;
+ }
+
+ ////////////////////////////////////////////////
+ // paint
+ ////////////////////////////////////////////////
+
+ private void drawClockInfo(Graphics g)
+ {
+ TvDevice tvDev = getDevice();
+
+ int winWidth = getWidth();
+ int winHeight = getHeight();
+
+ Font font = getFont(g);
+ g.setFont(font);
+ FontMetrics fontMetric = g.getFontMetrics();
+ g.setColor(Color.RED);
+
+ Rectangle2D strBounds;
+ int strWidth;
+ int strHeight;
+ int strX;
+ int strY;
+
+ //// Time String ////
+
+ String timeStr = tvDev.getClockTime();
+ if (timeStr != null && 0 < timeStr.length()) {
+ strBounds = fontMetric.getStringBounds(timeStr, g);
+ strWidth = (int)strBounds.getWidth();
+ strHeight = (int)strBounds.getHeight();
+ strX = IMAGE_BORDER_SIZE;
+ strY = IMAGE_BORDER_SIZE + strHeight;
+ g.drawString(
+ timeStr,
+ strX,
+ strY);
+ }
+
+ //// Tempture String ////
+
+ String tempStr = tvDev.getAirconTempture();
+ if (tempStr != null && 0 < tempStr.length()) {
+ tempStr += "C";
+ strBounds = fontMetric.getStringBounds(tempStr, g);
+ strWidth = (int)strBounds.getWidth();
+ strHeight = (int)strBounds.getHeight();
+ strX = winWidth - IMAGE_BORDER_SIZE - strWidth;
+ strY = IMAGE_BORDER_SIZE + strHeight;
+ g.drawString(
+ tempStr,
+ strX,
+ strY);
+ }
+
+ //// Message String ////
+
+ String msgStr = tvDev.getMessage();
+ if (msgStr != null && 0 < msgStr.length()) {
+ strBounds = fontMetric.getStringBounds(msgStr, g);
+ strWidth = (int)strBounds.getWidth();
+ strHeight = (int)strBounds.getHeight();
+ strX = IMAGE_BORDER_SIZE;
+ strY = getHeight()-IMAGE_BOTTOM_BORDER_SIZE-2;
+ g.drawString(
+ msgStr,
+ strX,
+ strY);
+ }
+ }
+
+ private void drawTvImage(Graphics g)
+ {
+ //g.setColor(Color.WHITE);
+ //g.clearRect(IMAGE_BORDER_SIZE, IMAGE_BORDER_SIZE, getWidth()-IMAGE_BORDER_SIZE*2, getHeight()-IMAGE_BORDER_SIZE-IMAGE_BOTTOM_BORDER_SIZE);
+ g.drawImage(tvOnImage, IMAGE_BORDER_SIZE, IMAGE_BORDER_SIZE, null);
+ }
+
+ private void clear(Graphics g)
+ {
+ g.setColor(Color.GRAY);
+ g.clearRect(0, 0, getWidth(), getHeight());
+ }
+
+
+ private void drawPanelImage(Graphics g)
+ {
+ g.drawImage(panelmage, 0, 0, null);
+ }
+
+ public void paint(Graphics g)
+ {
+ clear(g);
+ drawPanelImage(g);
+ TvDevice tvDev = getDevice();
+ if (tvDev.isOn() == true) {
+ drawTvImage(g);
+ drawClockInfo(g);
+ }
+ }
+}
+
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvPane.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvPane.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/TvPane.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/UPnPSubscriber.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/UPnPSubscriber.java?rev=674879&r1=674878&r2=674879&view=diff
==============================================================================
--- felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/UPnPSubscriber.java (original)
+++ felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/UPnPSubscriber.java Tue Jul 8 09:59:54 2008
@@ -1,63 +1,63 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.felix.upnp.sample.tv;
-
-import java.util.Properties;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.upnp.UPnPDevice;
-import org.osgi.service.upnp.UPnPEventListener;
-import org.osgi.service.upnp.UPnPService;
-
-/*
-* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
-*/
-
-public class UPnPSubscriber {
- ServiceRegistration registration = null;
- BundleContext context;
- UPnPEventListener listener;
-
- public UPnPSubscriber(BundleContext context,UPnPEventListener listener){
- this.context = context;
- this.listener = listener;
- }
-
- public void subscribe(String deviceType, String serviceType){
- String keys = "(&(" + UPnPDevice.TYPE + "="+ deviceType + ")(" + UPnPService.TYPE + "=" + serviceType + "))";
- try {
- Filter filter = context.createFilter(keys);
- Properties props = new Properties();
- props.put(UPnPEventListener.UPNP_FILTER, filter);
- registration = context.registerService(UPnPEventListener.class.getName(), listener, props);
- }catch (Exception ex){
- System.out.println(ex);
- }
- }
-
- public void unsubscribe(){
- registration.unregister();
- registration = null;
- }
-
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.upnp.sample.tv;
+
+import java.util.Properties;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPEventListener;
+import org.osgi.service.upnp.UPnPService;
+
+/*
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
+
+public class UPnPSubscriber {
+ ServiceRegistration registration = null;
+ BundleContext context;
+ UPnPEventListener listener;
+
+ public UPnPSubscriber(BundleContext context,UPnPEventListener listener){
+ this.context = context;
+ this.listener = listener;
+ }
+
+ public void subscribe(String deviceType, String serviceType){
+ String keys = "(&(" + UPnPDevice.TYPE + "="+ deviceType + ")(" + UPnPService.TYPE + "=" + serviceType + "))";
+ try {
+ Filter filter = context.createFilter(keys);
+ Properties props = new Properties();
+ props.put(UPnPEventListener.UPNP_FILTER, filter);
+ registration = context.registerService(UPnPEventListener.class.getName(), listener, props);
+ }catch (Exception ex){
+ System.out.println(ex);
+ }
+ }
+
+ public void unsubscribe(){
+ registration.unregister();
+ registration = null;
+ }
+
+
+}
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/UPnPSubscriber.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/UPnPSubscriber.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: felix/trunk/upnp/samples/tv/src/main/java/org/apache/felix/upnp/sample/tv/UPnPSubscriber.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Propchange: felix/trunk/upnp/samples/tv/src/main/resources/org/apache/felix/upnp/sample/tv/images/logo.gif
------------------------------------------------------------------------------
--- svn:mime-type (original)
+++ svn:mime-type Tue Jul 8 09:59:54 2008
@@ -1 +1 @@
-application/octet-stream
+image/gif
Propchange: felix/trunk/upnp/samples/tv/src/main/resources/org/apache/felix/upnp/sample/tv/images/tv.gif
------------------------------------------------------------------------------
--- svn:mime-type (original)
+++ svn:mime-type Tue Jul 8 09:59:54 2008
@@ -1 +1 @@
-application/octet-stream
+image/gif
Modified: felix/trunk/upnp/tester/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/tester/pom.xml?rev=674879&r1=674878&r2=674879&view=diff
==============================================================================
--- felix/trunk/upnp/tester/pom.xml (original)
+++ felix/trunk/upnp/tester/pom.xml Tue Jul 8 09:59:54 2008
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -17,69 +17,70 @@
specific language governing permissions and limitations
under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <artifactId>felix</artifactId>
- <groupId>org.apache.felix</groupId>
- <version>1.0.2</version>
- <relativePath>../../pom/pom.xml</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.upnp.tester</artifactId>
- <packaging>bundle</packaging>
- <name>Apache Felix UPnP Tester</name>
- <version>0.2.0-SNAPSHOT</version>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>felix</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <version>1.0.2</version>
+ <relativePath>../../pom/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.upnp.tester</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Felix UPnP Tester</name>
+ <version>0.2.0-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
<version>1.4.0</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Name>${pom.name}</Bundle-Name>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${pom.name}</Bundle-Name>
<Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
- <Bundle-Author><![CDATA[Matteo Demuru <de...@apache.org>,Francesco Furfari <fu...@apache.org>,Stefano "Kismet" Lenzi <le...@apache.org>]]></Bundle-Author>
- <Bundle-Description>
- OSGi Generic Control Point to control UPnPDevice services
- </Bundle-Description>
- <Bundle-SymbolicName>org.apache.felix.upnp.tester</Bundle-SymbolicName>
- <Bundle-Activator>org.apache.felix.upnp.tester.Activator</Bundle-Activator>
- <Private-Package>org.apache.felix.upnp.tester.*</Private-Package>
- <Import-Package>*</Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.osgi.compendium</artifactId>
+ <Bundle-Author><![CDATA[Matteo Demuru <de...@apache.org>,Francesco Furfari <fu...@apache.org>,Stefano "Kismet" Lenzi <le...@apache.org>]]></Bundle-Author>
+ <Bundle-Description>
+ OSGi Generic Control Point to control UPnPDevice services
+ </Bundle-Description>
+ <Bundle-SymbolicName>org.apache.felix.upnp.tester</Bundle-SymbolicName>
+ <Bundle-Activator>org.apache.felix.upnp.tester.Activator</Bundle-Activator>
+ <Private-Package>org.apache.felix.upnp.tester.*</Private-Package>
+ <Import-Package>*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
<version>1.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.upnp.basedriver</artifactId>
- <version>0.3.0-SNAPSHOT</version>
- </dependency>
- <!-- dependency>
- Note: this dependency might be restored when (if) a converter utility will be exposed by extra bundle.
- So far Tester uses the Converter class of the basedriver (it should be fixed)
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.upnp.extra</artifactId>
- <version>0.3.0-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency -->
- </dependencies>
-</project>
-
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.upnp.basedriver</artifactId>
+ <version>0.8.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <!-- dependency>
+ Note: this dependency might be restored when (if) a converter utility will be exposed by extra bundle.
+ So far Tester uses the Converter class of the basedriver (it should be fixed)
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.upnp.extra</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency -->
+ </dependencies>
+</project>
+
Propchange: felix/trunk/upnp/tester/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/upnp/tester/pom.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: felix/trunk/upnp/tester/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Propchange: felix/trunk/upnp/tester/src/main/java/org/apache/felix/upnp/tester/Activator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/upnp/tester/src/main/java/org/apache/felix/upnp/tester/Activator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: felix/trunk/upnp/tester/src/main/java/org/apache/felix/upnp/tester/Activator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain