blob: f20aa15d6f502cee8cee7bb4d7432f0df3a691bf [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 Furfari91af5da2006-04-04 23:44:23 +00009 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Francesco Furfari91af5da2006-04-04 23:44:23 +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 Furfari91af5da2006-04-04 23:44:23 +000018 */
19
20package org.apache.felix.upnp.tester.discovery;
21
22import org.apache.felix.upnp.extra.controller.*;
23import org.apache.felix.upnp.tester.*;
24
25import org.osgi.framework.*;
Francesco Furfarif2a67912006-07-17 17:08:02 +000026/*
Karl Paulsd312acc2007-06-18 20:38:33 +000027* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Francesco Furfarif2a67912006-07-17 17:08:02 +000028*/
Francesco Furfari91af5da2006-04-04 23:44:23 +000029public 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}