blob: fa62cebda6c908ce769414a31b352f856fab2d7a [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 Furfarid8bdb642006-04-04 23:33:40 +00009 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Francesco Furfarid8bdb642006-04-04 23:33:40 +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 Furfarid8bdb642006-04-04 23:33:40 +000018 */
19
20package org.apache.felix.upnp.basedriver;
21
22import org.apache.felix.upnp.extra.controller.DevicesInfo;
23import org.apache.felix.upnp.extra.controller.DriverController;
24
25import org.cybergarage.upnp.UPnP;
26import org.cybergarage.xml.parser.JaxpParser;
27
28import org.osgi.framework.BundleActivator;
29import org.osgi.framework.BundleContext;
30import org.osgi.framework.ServiceRegistration;
31
32import org.apache.felix.upnp.basedriver.controller.impl.DriverControllerImpl;
33import org.apache.felix.upnp.basedriver.export.RootDeviceExportingQueue;
34import org.apache.felix.upnp.basedriver.export.RootDeviceListener;
35import org.apache.felix.upnp.basedriver.export.ThreadExporter;
36import org.apache.felix.upnp.basedriver.importer.core.MyCtrlPoint;
37import org.apache.felix.upnp.basedriver.importer.core.event.structs.Monitor;
38import org.apache.felix.upnp.basedriver.importer.core.event.structs.NotifierQueue;
39import org.apache.felix.upnp.basedriver.importer.core.event.structs.SubscriptionQueue;
40import org.apache.felix.upnp.basedriver.importer.core.event.thread.Notifier;
41import org.apache.felix.upnp.basedriver.importer.core.event.thread.SubScriber;
42import org.apache.felix.upnp.basedriver.tool.Logger;
43import org.apache.felix.upnp.basedriver.tool.Util;
44
Francesco Furfarif2a67912006-07-17 17:08:02 +000045/*
Karl Paulsd312acc2007-06-18 20:38:33 +000046* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Francesco Furfarif2a67912006-07-17 17:08:02 +000047*/
Francesco Furfarid8bdb642006-04-04 23:33:40 +000048public 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 Furfari99691342006-05-03 07:51:49 +000073 String levelStr = (String) Util.getPropertyDefault(context,"felix.upnpbase.log","2");
Francesco Furfarid8bdb642006-04-04 23:33:40 +000074 Activator.logger = new Logger(levelStr);
Francesco Furfari99691342006-05-03 07:51:49 +000075 String cyberLog = (String) Util.getPropertyDefault(context,"felix.upnpbase.cyberlink.log","false");
Francesco Furfarid8bdb642006-04-04 23:33:40 +000076 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 Furfari4b452e42006-11-25 23:51:49 +000085 new Thread(consumerDeviceToExport, "upnp.basedriver.Exporter").start();
Francesco Furfarid8bdb642006-04-04 23:33:40 +000086
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 Furfari4b452e42006-11-25 23:51:49 +0000132 subScriber.close();
133 notifier.close();
Francesco Furfarid8bdb642006-04-04 23:33:40 +0000134 Activator.logger.close();
135 Activator.logger=null;
136 Activator.bc = null;
137 }
Karl Paulsd312acc2007-06-18 20:38:33 +0000138}