|
Framework Professional Edition Package |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.mbs.services.device.abstractdriver.AbstractDeviceDriver
public abstract class AbstractDeviceDriver
Base driver class for all device drivers.
A driver holds the logic of matching and attaching devices.
If the driver matches a device service (bids a highest match number
of all currently registered drivers), its attach(ServiceReference)
method is invoked. If attaching is successful a new
org.mbs.services.control.ControlUnit service is registered
in the framework.
The AbstractDeviceDriver provides implementation of the
attach method, while the extending classes should implement
the logic of matching devices in their match method.
| Field Summary | |
|---|---|
protected java.util.Hashtable |
attachedServices
Hold all attached services. |
protected org.osgi.framework.BundleContext |
bc
BundleContext object of the driver bundle |
static int |
CONTROLLER_DEBUG_LEVEL
|
static int |
DRIVER_DEBUG_LEVEL
|
protected org.osgi.framework.ServiceRegistration |
driverReg
Service registration of the driver service |
static java.lang.String |
LAYER
The identification of this component used for logging |
static ManagedLog |
log
service used for logging |
static int |
MODEL_DEBUG_LEVEL
|
protected DeviceStateGraph |
stateGraph
Device state graph |
static DB |
storage
reference to DB service, used for handling device additional names |
protected boolean |
useTokenDevices
|
| Constructor Summary | |
|---|---|
AbstractDeviceDriver(org.osgi.framework.BundleContext bc)
Constructor. |
|
| Method Summary | |
|---|---|
java.lang.String |
attach(org.osgi.framework.ServiceReference reference)
Attaches this Driver service to the Device service represented by the given ServiceReference object. |
protected DeviceControlUnit |
createDeviceCU(java.lang.Object service)
Creates device control unit implementation for the given device service. |
abstract java.lang.String |
generateControlUnitID(java.lang.Object device)
Generates a control unit id based on the service passed as parameter. |
java.lang.String[] |
getControlledDevices()
Returns a String array of the IDs of all the devices controlled by the driver |
protected abstract AbstractDeviceController |
getController(java.lang.Object device)
Returns an AbstractDeviceController instance for device type of the driver. |
abstract java.lang.String |
getDeviceServiceFilter()
This method is called to register driver service listener with service filter. |
abstract java.lang.String |
getDriverID()
Implementing classes return their DRIVER_IDs as in the Device Access specification. |
protected abstract AbstractDeviceModel |
getModel(java.lang.Object device)
An instance of a class, extending AbstractDeviceModel, model for the types of devices this driver attaches. |
void |
handleUnregistering()
Invoked when this driver's bundle is stopped. |
abstract int |
match(org.osgi.framework.ServiceReference reference)
Checks whether this Driver service can be attached to the Device service. |
static java.lang.String |
readAdditionalName(java.lang.String type,
java.lang.String id)
Reads the device additional name from persistent storage. |
void |
registerDriverService(org.osgi.framework.BundleContext bc)
Registers this class as a driver service |
void |
release()
Release driver resources. |
void |
serviceChanged(org.osgi.framework.ServiceEvent event)
Implementation of ServiceListener interface. |
void |
setDeviceStateGraph(DeviceStateGraph stateGraph)
Sets the device state graph the should be used to control devices registered by this driver. |
void |
setDeviceToken(boolean useTokenDevices)
Changes the default class of the created control unit by the driver. |
void |
unregisterDriverService()
Unregisters this class as a driver service. |
static void |
writeAdditionalName(java.lang.String type,
java.lang.String id,
java.lang.String name)
Stores persistently the device additional name. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static ManagedLog log
public static DB storage
public static final java.lang.String LAYER
public static final int DRIVER_DEBUG_LEVEL
public static final int CONTROLLER_DEBUG_LEVEL
public static final int MODEL_DEBUG_LEVEL
protected org.osgi.framework.BundleContext bc
protected java.util.Hashtable attachedServices
ServiceReference,
value is a corresponding ControlUnit instance.
protected org.osgi.framework.ServiceRegistration driverReg
protected DeviceStateGraph stateGraph
protected boolean useTokenDevices
| Constructor Detail |
|---|
public AbstractDeviceDriver(org.osgi.framework.BundleContext bc)
throws java.lang.Exception
bc - this diver's bundle BundleContext
java.lang.Exception| Method Detail |
|---|
public void setDeviceToken(boolean useTokenDevices)
useTokenDevices is true, then all control
units that will be registered by the driver will be of class
TokenDeviceControlUnit and will support the token locking
mechanism.
By default, when driver is created the token support is
determined by the value of the system property "mbs.abstractdriver.token".
Note: Calling this method will not affect already registered control units by the driver.
useTokenDevices - true if control units registered by this driver
will support token mechanism.
public abstract int match(org.osgi.framework.ServiceReference reference)
throws java.lang.Exception
ServiceReference and returns a value
indicating how well this driver can support the given Device service,
or Device#MATCH_NONE if it cannot support the given
Device service at all.
The return value must be one of the possible match values defined in the device category definition for the given Device service, or Device.MATCH_NONE if the category of the Device service is not recognized.
In order to make its decision, this Driver service may examine the properties associated with the given Device service, or may get the referenced service object (representing the actual physical device) to talk to it, as long as it ungets the service and returns the physical device to a normal state before this method returns.
A Driver service must always return the same match code whenever it is presented with the same Device service.
The match function is called by the device manager during the matching process.
match in interface Driverreference - the ServiceReference object of the device to match
java.lang.Exception - if this Driver service cannot
examine the Device service
public java.lang.String attach(org.osgi.framework.ServiceReference reference)
throws java.lang.Exception
ControlUnit service in the framework.
A return value of null indicates that this Driver service has successfully attached to the given Device service. If this Driver service is unable to attach to the given Device service, but knows of a more suitable Driver service, it must return the DRIVER_ID of that Driver service. This allows for the implementation of referring drivers whose only purpose is to refer to other drivers capable of handling a given Device service.
After having attached to the Device service, this driver may register the underlying device as a new service exposing driver-specific functionality.
This method is called by the device manager.
attach in interface Driverreference - the ServiceReference object of the device to attach to
java.lang.Exception - if the driver cannot attach to the
given device and does not know of a more suitable driverpublic abstract java.lang.String getDriverID()
protected abstract AbstractDeviceController getController(java.lang.Object device)
device - EHSDevice service which
protected abstract AbstractDeviceModel getModel(java.lang.Object device)
device -
protected DeviceControlUnit createDeviceCU(java.lang.Object service)
service - the device service
public void serviceChanged(org.osgi.framework.ServiceEvent event)
serviceChanged in interface org.osgi.framework.ServiceListenerevent - The ServiceEvent object.ServiceListener.serviceChanged(org.osgi.framework.ServiceEvent)public void registerDriverService(org.osgi.framework.BundleContext bc)
bc - the BundleContext object with which the service is registeredpublic void unregisterDriverService()
public void handleUnregistering()
public void release()
public java.lang.String[] getControlledDevices()
public abstract java.lang.String generateControlUnitID(java.lang.Object device)
device - a device service
public abstract java.lang.String getDeviceServiceFilter()
public void setDeviceStateGraph(DeviceStateGraph stateGraph)
stateGraph - device state graph
public static void writeAdditionalName(java.lang.String type,
java.lang.String id,
java.lang.String name)
throws java.io.IOException
type - the type of the deviceid - the id of the devicename - the user-friendly name of the device
java.io.IOException - thrown if problems writing to storage occur
public static java.lang.String readAdditionalName(java.lang.String type,
java.lang.String id)
type - the type of the deviceid - the id of the device
|
Framework Professional Edition Package |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||