001 /*
002 * Copyright (c) OSGi Alliance (2001, 2008). All Rights Reserved.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.osgi.service.device;
017
018 import org.osgi.framework.ServiceReference;
019
020 /**
021 * When the device manager detects a new Device service, it calls all registered
022 * Driver services to determine if anyone matches the Device service. If at
023 * least one Driver service matches, the device manager must choose one. If
024 * there is a Driver Selector service registered with the Framework, the device
025 * manager will ask it to make the selection. If there is no Driver Selector
026 * service, or if it returns an invalid result, or throws an
027 * <code>Exception</code>, the device manager uses the default selection
028 * strategy.
029 *
030 * @version $Revision: 5654 $
031 * @since 1.1
032 * @ThreadSafe
033 */
034 public interface DriverSelector {
035 /**
036 * Return value from <code>DriverSelector.select</code>, if no Driver
037 * service should be attached to the Device service. The value is -1.
038 */
039 public static final int SELECT_NONE = -1;
040
041 /**
042 * Select one of the matching Driver services. The device manager calls this
043 * method if there is at least one driver bidding for a device. Only Driver
044 * services that have responded with nonzero (not {@link Device#MATCH_NONE})
045 * <code></code> match values will be included in the list.
046 *
047 * @param reference the <code>ServiceReference</code> object of the Device
048 * service.
049 * @param matches the array of all non-zero matches.
050 * @return index into the array of <code>Match</code> objects, or
051 * <code>SELECT_NONE</code> if no Driver service should be attached
052 */
053 public int select(ServiceReference reference, Match[] matches);
054 }