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 | 91af5da | 2006-04-04 23:44:23 +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 | 91af5da | 2006-04-04 23:44:23 +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 | 91af5da | 2006-04-04 23:44:23 +0000 | [diff] [blame] | 18 | */
|
| 19 |
|
| 20 | package org.apache.felix.upnp.tester.discovery;
|
| 21 |
|
| 22 | import org.apache.felix.upnp.extra.controller.*;
|
| 23 | import org.apache.felix.upnp.tester.*;
|
| 24 |
|
| 25 | import org.osgi.framework.*;
|
Francesco Furfari | f2a6791 | 2006-07-17 17:08:02 +0000 | [diff] [blame] | 26 | /*
|
Karl Pauls | d312acc | 2007-06-18 20:38:33 +0000 | [diff] [blame^] | 27 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
|
Francesco Furfari | f2a6791 | 2006-07-17 17:08:02 +0000 | [diff] [blame] | 28 | */
|
Francesco Furfari | 91af5da | 2006-04-04 23:44:23 +0000 | [diff] [blame] | 29 | public class DriverProxy implements ServiceListener {
|
| 30 | private DevicesInfo devicesInfo;
|
| 31 | private DriverController drvController;
|
| 32 | public DriverProxy(){
|
| 33 | ServiceReference sr = Activator.context.getServiceReference(DevicesInfo.class.getName());
|
| 34 | if (sr != null){
|
| 35 | devicesInfo = (DevicesInfo)Activator.context.getService(sr);
|
| 36 | drvController = (DriverController) devicesInfo;
|
| 37 | Mediator.getControlPoint().enableMenus(true,getLogLevel(),getCyberDebug());
|
| 38 | Mediator.getTreeViewer().setPopupMenuEnabled(true);
|
| 39 | }
|
| 40 | String filter = "(" + Constants.OBJECTCLASS + "=" + DevicesInfo.class.getName() + ")" ;
|
| 41 | try {
|
| 42 | Activator.context.addServiceListener(this,filter);
|
| 43 | } catch (Exception ignored){};
|
| 44 | }
|
| 45 |
|
| 46 | public boolean isDriverAvailable(){
|
| 47 | return (drvController != null);
|
| 48 | }
|
| 49 |
|
| 50 | public String getDeviceDescriptionURI(String udn){
|
| 51 | if (devicesInfo != null)
|
| 52 | return devicesInfo.getLocationURL(udn);
|
| 53 | return "";
|
| 54 | }
|
| 55 |
|
| 56 | public String getServiceDescriptionURI(String udn,String serviceId){
|
| 57 | if (devicesInfo != null)
|
| 58 | return devicesInfo.getSCPDURL(udn,serviceId);
|
| 59 | return null;
|
| 60 | }
|
| 61 |
|
| 62 | public String resolveRelativeUrl(String udn,String link){
|
| 63 | if (devicesInfo != null)
|
| 64 | return devicesInfo.resolveRelativeUrl(udn,link);
|
| 65 | return null;
|
| 66 | }
|
| 67 |
|
| 68 | public boolean getCyberDebug(){
|
| 69 | if (drvController != null)
|
| 70 | return drvController.getCyberDebug();
|
| 71 | return false;
|
| 72 | }
|
| 73 | public void setCyberDebug(boolean b){
|
| 74 | if (drvController != null)
|
| 75 | drvController.setCyberDebug(b);
|
| 76 | }
|
| 77 | public int getLogLevel(){
|
| 78 | if (drvController != null)
|
| 79 | return drvController.getLogLevel();
|
| 80 | return 0;
|
| 81 | }
|
| 82 |
|
| 83 | public void setLogLevel(int value){
|
| 84 | if (drvController != null)
|
| 85 | drvController.setLogLevel(value);
|
| 86 | }
|
| 87 | public void doSearch(String target){
|
| 88 | if (drvController != null)
|
| 89 | drvController.search(target);
|
| 90 | }
|
| 91 |
|
| 92 |
|
| 93 | public void serviceChanged(ServiceEvent e) {
|
| 94 | switch(e.getType()){
|
| 95 | case ServiceEvent.REGISTERED:{
|
| 96 | Object service = Activator.context.getService(e.getServiceReference());
|
| 97 | if (service != null){
|
| 98 | devicesInfo = (DevicesInfo) service;
|
| 99 | drvController = (DriverController) devicesInfo;
|
| 100 | Mediator.getControlPoint().enableMenus(true,getLogLevel(),getCyberDebug());
|
| 101 | Mediator.getTreeViewer().setPopupMenuEnabled(true);
|
| 102 | }
|
| 103 | };break;
|
| 104 | case ServiceEvent.UNREGISTERING:{
|
| 105 | devicesInfo = null;
|
| 106 | drvController =null;
|
| 107 | Mediator.getControlPoint().enableMenus(false,0,false);
|
| 108 | Mediator.getTreeViewer().setPopupMenuEnabled(false);
|
| 109 | };break;
|
| 110 | }
|
| 111 | }
|
| 112 |
|
| 113 | public void close(){
|
| 114 | Activator.context.removeServiceListener(this);
|
| 115 | }
|
| 116 |
|
| 117 |
|
| 118 | }
|