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 | d8bdb64 | 2006-04-04 23:33:40 +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 | d8bdb64 | 2006-04-04 23:33:40 +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 | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | package org.apache.felix.upnp.basedriver; |
| 21 | |
| 22 | import org.apache.felix.upnp.extra.controller.DevicesInfo; |
| 23 | import org.apache.felix.upnp.extra.controller.DriverController; |
| 24 | |
| 25 | import org.cybergarage.upnp.UPnP; |
| 26 | import org.cybergarage.xml.parser.JaxpParser; |
| 27 | |
| 28 | import org.osgi.framework.BundleActivator; |
| 29 | import org.osgi.framework.BundleContext; |
| 30 | import org.osgi.framework.ServiceRegistration; |
| 31 | |
| 32 | import org.apache.felix.upnp.basedriver.controller.impl.DriverControllerImpl; |
| 33 | import org.apache.felix.upnp.basedriver.export.RootDeviceExportingQueue; |
| 34 | import org.apache.felix.upnp.basedriver.export.RootDeviceListener; |
| 35 | import org.apache.felix.upnp.basedriver.export.ThreadExporter; |
| 36 | import org.apache.felix.upnp.basedriver.importer.core.MyCtrlPoint; |
| 37 | import org.apache.felix.upnp.basedriver.importer.core.event.structs.Monitor; |
| 38 | import org.apache.felix.upnp.basedriver.importer.core.event.structs.NotifierQueue; |
| 39 | import org.apache.felix.upnp.basedriver.importer.core.event.structs.SubscriptionQueue; |
| 40 | import org.apache.felix.upnp.basedriver.importer.core.event.thread.Notifier; |
| 41 | import org.apache.felix.upnp.basedriver.importer.core.event.thread.SubScriber; |
| 42 | import org.apache.felix.upnp.basedriver.tool.Logger; |
| 43 | import org.apache.felix.upnp.basedriver.tool.Util; |
| 44 | |
Francesco Furfari | f2a6791 | 2006-07-17 17:08:02 +0000 | [diff] [blame] | 45 | /* |
Karl Pauls | d312acc | 2007-06-18 20:38:33 +0000 | [diff] [blame^] | 46 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
Francesco Furfari | f2a6791 | 2006-07-17 17:08:02 +0000 | [diff] [blame] | 47 | */ |
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 48 | public class Activator implements BundleActivator { |
| 49 | |
| 50 | public static BundleContext bc; |
| 51 | public static Logger logger; |
| 52 | private RootDeviceExportingQueue queue; |
| 53 | private RootDeviceListener producerDeviceToExport; |
| 54 | private ThreadExporter consumerDeviceToExport; |
| 55 | |
| 56 | private MyCtrlPoint ctrl; |
| 57 | private SubScriber subScriber; |
| 58 | private Notifier notifier; |
| 59 | private NotifierQueue notifierQueue; |
| 60 | private SubscriptionQueue subQueue; |
| 61 | private Monitor monitor; |
| 62 | private DriverControllerImpl drvController; |
| 63 | private ServiceRegistration drvControllerRegistrar; |
| 64 | |
| 65 | /** |
| 66 | * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) |
| 67 | */ |
| 68 | public void start(BundleContext context) throws Exception { |
| 69 | //Setting basic variabile used by everyone |
| 70 | |
| 71 | Activator.bc = context; |
| 72 | |
Francesco Furfari | 9969134 | 2006-05-03 07:51:49 +0000 | [diff] [blame] | 73 | String levelStr = (String) Util.getPropertyDefault(context,"felix.upnpbase.log","2"); |
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 74 | Activator.logger = new Logger(levelStr); |
Francesco Furfari | 9969134 | 2006-05-03 07:51:49 +0000 | [diff] [blame] | 75 | String cyberLog = (String) Util.getPropertyDefault(context,"felix.upnpbase.cyberlink.log","false"); |
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 76 | Activator.logger.setCyberDebug(cyberLog); |
| 77 | |
| 78 | UPnP.setXMLParser(new JaxpParser()); |
| 79 | |
| 80 | //Setting up Base Driver Exporter |
| 81 | this.queue = new RootDeviceExportingQueue(); |
| 82 | this.producerDeviceToExport = new RootDeviceListener(queue); |
| 83 | producerDeviceToExport.activate(); |
| 84 | consumerDeviceToExport = new ThreadExporter(queue); |
Francesco Furfari | 4b452e4 | 2006-11-25 23:51:49 +0000 | [diff] [blame] | 85 | new Thread(consumerDeviceToExport, "upnp.basedriver.Exporter").start(); |
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 86 | |
| 87 | //Setting up Base Driver Importer |
| 88 | this.notifierQueue = new NotifierQueue(); |
| 89 | this.subQueue = new SubscriptionQueue(); |
| 90 | ctrl = new MyCtrlPoint(context, subQueue, notifierQueue); |
| 91 | |
| 92 | //Enable CyberLink re-new for Event |
| 93 | ctrl.setNMPRMode(true); |
| 94 | |
| 95 | this.monitor=new Monitor(); |
| 96 | this.notifier = new Notifier(notifierQueue,monitor); |
| 97 | this.subScriber = new SubScriber(ctrl, subQueue,monitor); |
| 98 | |
| 99 | ctrl.start(); |
| 100 | subScriber.start(); |
| 101 | notifier.start(); |
| 102 | |
| 103 | doControllerRegistration(); |
| 104 | |
| 105 | } |
| 106 | |
| 107 | private void doControllerRegistration() { |
| 108 | drvController = new DriverControllerImpl(ctrl); |
| 109 | drvControllerRegistrar = bc.registerService( |
| 110 | new String[]{ |
| 111 | DriverController.class.getName(), |
| 112 | DevicesInfo.class.getName()}, |
| 113 | drvController, |
| 114 | null |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) |
| 120 | */ |
| 121 | public void stop(BundleContext context) throws Exception { |
| 122 | |
| 123 | drvControllerRegistrar.unregister(); |
| 124 | |
| 125 | //Setting up Base Driver Exporter |
| 126 | consumerDeviceToExport.end(); |
| 127 | consumerDeviceToExport.cleanUp(); |
| 128 | producerDeviceToExport.deactive(); |
| 129 | |
| 130 | //Setting up Base Driver Importer |
| 131 | ctrl.stop(); |
Francesco Furfari | 4b452e4 | 2006-11-25 23:51:49 +0000 | [diff] [blame] | 132 | subScriber.close(); |
| 133 | notifier.close(); |
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 134 | Activator.logger.close(); |
| 135 | Activator.logger=null; |
| 136 | Activator.bc = null; |
| 137 | } |
Karl Pauls | d312acc | 2007-06-18 20:38:33 +0000 | [diff] [blame^] | 138 | } |