Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +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 |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 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. |
| 18 | */ |
| 19 | package org.apache.felix.das; |
| 20 | |
| 21 | |
Marcel Offermans | b8f9bcb | 2011-04-11 20:46:19 +0000 | [diff] [blame] | 22 | import org.apache.felix.das.util.Util; |
| 23 | import org.apache.felix.dm.Component; |
| 24 | import org.apache.felix.dm.DependencyActivatorBase; |
| 25 | import org.apache.felix.dm.DependencyManager; |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 26 | import org.osgi.framework.BundleContext; |
| 27 | import org.osgi.framework.Constants; |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 28 | import org.osgi.service.device.Device; |
| 29 | import org.osgi.service.device.Driver; |
| 30 | import org.osgi.service.device.DriverLocator; |
| 31 | import org.osgi.service.device.DriverSelector; |
| 32 | import org.osgi.service.log.LogService; |
| 33 | |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * TODO: add javadoc |
| 37 | * |
| 38 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 39 | */ |
| 40 | public class Activator extends DependencyActivatorBase |
| 41 | { |
| 42 | |
| 43 | /** the bundle context */ |
Marcel Offermans | b627d2b | 2012-09-27 21:30:58 +0000 | [diff] [blame] | 44 | private volatile BundleContext m_context; |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 45 | |
| 46 | /** the dependency manager */ |
Marcel Offermans | b627d2b | 2012-09-27 21:30:58 +0000 | [diff] [blame] | 47 | private volatile DependencyManager m_manager; |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 48 | |
| 49 | /** the device manager */ |
| 50 | private DeviceManager m_deviceManager; |
| 51 | |
| 52 | |
| 53 | /** |
| 54 | * Here, we create and start the device manager, but we do not register it |
| 55 | * within the framework, since that is not specified by the specification. |
| 56 | * |
| 57 | * @see org.apache.felix.dependencymanager.DependencyActivatorBase#init(org.osgi.framework.BundleContext, |
| 58 | * org.apache.felix.dependencymanager.DependencyManager) |
| 59 | */ |
| 60 | public void init( BundleContext context, DependencyManager manager ) throws Exception |
| 61 | { |
| 62 | |
| 63 | m_context = context; |
| 64 | m_manager = manager; |
| 65 | |
| 66 | m_deviceManager = new DeviceManager( m_context ); |
| 67 | |
| 68 | // the real device manager |
| 69 | startDeviceManager(); |
| 70 | |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | |
Marcel Offermans | b8f9bcb | 2011-04-11 20:46:19 +0000 | [diff] [blame] | 74 | private void startDeviceManager() { |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 75 | |
Marcel Offermans | b8f9bcb | 2011-04-11 20:46:19 +0000 | [diff] [blame] | 76 | final String driverFilter = Util.createFilterString( "(%s=%s)", new String[] |
| 77 | { org.osgi.service.device.Constants.DRIVER_ID, "*" } ); |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 78 | |
Marcel Offermans | b8f9bcb | 2011-04-11 20:46:19 +0000 | [diff] [blame] | 79 | final String deviceFilter = Util.createFilterString( "(|(%s=%s)(&(%s=%s)(%s=%s)))", new String[] |
| 80 | { |
| 81 | Constants.OBJECTCLASS, Device.class.getName(), |
| 82 | Constants.OBJECTCLASS, "*", |
| 83 | org.osgi.service.device.Constants.DEVICE_CATEGORY, "*" |
| 84 | } ); |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 85 | |
Marcel Offermans | b8f9bcb | 2011-04-11 20:46:19 +0000 | [diff] [blame] | 86 | Component svc = createComponent(); |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 87 | |
| 88 | svc.setImplementation( m_deviceManager ); |
| 89 | |
| 90 | svc.add( createServiceDependency().setService( LogService.class ).setRequired( false ) ); |
| 91 | |
Marcel Offermans | b8f9bcb | 2011-04-11 20:46:19 +0000 | [diff] [blame] | 92 | svc.add( createServiceDependency().setService( DriverSelector.class ).setRequired( false ).setAutoConfig( false ) |
| 93 | .setCallbacks( "selectorAdded", "selectorRemoved" ) ); |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 94 | |
| 95 | svc.add( createServiceDependency().setService( DriverLocator.class ).setRequired( false ).setAutoConfig( false ) |
| 96 | .setCallbacks( "locatorAdded", "locatorRemoved" ) ); |
Marcel Offermans | b8f9bcb | 2011-04-11 20:46:19 +0000 | [diff] [blame] | 97 | |
| 98 | svc.add( createServiceDependency().setService( Driver.class, driverFilter ).setRequired( false ) |
Marcel Offermans | b627d2b | 2012-09-27 21:30:58 +0000 | [diff] [blame] | 99 | .setCallbacks( "driverAdded", "driverModified", "driverRemoved" ) ); |
Marcel Offermans | b8f9bcb | 2011-04-11 20:46:19 +0000 | [diff] [blame] | 100 | |
| 101 | svc.add( createServiceDependency().setService( deviceFilter ).setRequired( false ) |
| 102 | .setCallbacks( "deviceAdded", "deviceModified", "deviceRemoved" ) ); |
| 103 | |
Marcel Offermans | 613a620 | 2009-03-11 22:31:44 +0000 | [diff] [blame] | 104 | m_manager.add( svc ); |
| 105 | |
| 106 | } |
| 107 | |
| 108 | |
| 109 | public void destroy( BundleContext context, DependencyManager manager ) throws Exception |
| 110 | { |
| 111 | // TODO Auto-generated method stub |
| 112 | |
| 113 | } |
| 114 | |
| 115 | } |