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