public interface Function
The function service is registered in the service registry with these service properties:
SERVICE_UID
- mandatory service property. The property value
contains the function unique identifier.SERVICE_DEVICE_UID
- optional service property. The property
value is the Functional Device identifiers. The function belongs to those
devices.SERVICE_REFERENCE_UIDS
- optional service property. The property
value contains the reference function unique identifiers.SERVICE_TYPE
- mandatory service property. The property value is
the function type.SERVICE_VERSION
- optional service property. The property value
contains the function version.SERVICE_DESCRIPTION
- optional service property. The property
value is the function description.SERVICE_OPERATION_NAMES
- optional service property. The
property is missing when there are no function operations and property must
be set when there are function operations. The property value is the function
operation names.SERVICE_PROPERTY_NAMES
- optional service property. The property
is missing when there are no function properties and property must be set
when there are function properties. The property value is the function
property names.
On start up, the Function
services are registered before the
Device
services. It's possible that SERVICE_DEVICE_UID
point
to missing services at the moment of the registration. The reverse order is
used when the services are unregistered. Function
services are
unregistered last after Device
services.
The Function
service should be registered only under the function
class hierarchy. Other classes can be used if there are no ambiguous
representations. For example, an ambiguous representation can be a function
registered under two independent function classes like BinarySwitch
and Meter
. In this example, both functions support the same property
state
with different meaning.
getPropertyMetadata(String propertyName)
method cannot determinate
which property is requested. It can be BinarySwitch state
or
Meter state
.
To simplify the generic function discovery, the Function
interface
must be used for the service registration. In this way, the generic
applications can easily find all services, which are functions in the service
registry. Because of this rule, this registration is not allowed:
context.registerService(MeterV1.class.getName(), this, regProps);
If the implementation would like to mark that there is a function, but no specific function interface exists, the registration can be:
context.registerService(Function.class.getName(), this, regProps);
Note that such functions usually don't have operations and properties.
The function properties must be integrated according to these rules:
PropertyMetadata.ACCESS_READABLE
access.FunctionData
.PropertyMetadata.ACCESS_WRITABLE
access.FunctionData
.FunctionData
subclass, if there are no equal types.MyFunctionData
bean with BigDecimal
value for a
data
property. Valid setters are setData(MyFunctionData data)
and setData(BigDecimal data)
.MySecondFunctionData
bean with BigDecimal
prefix and
BigDecimal
suffix for a data
property. The prefix and suffix
are using equal types and we cannot have a setter with the values used by
MySecondFunctionData
. The only one possible setter is
setData(MySecondFunctionData data)
.PropertyMetadata.ACCESS_EVENTABLE
access.The accessor method names must be defined according JavaBeans specification.
The function operations are java methods, which cannot override the property accessor methods. They can have zero or more parameters and zero or one return value.
Operation arguments and function properties are restricted by the same set of rules. The data type can be one of the following types:
java.lang.String
.java.lang.Number
.
The numerical type must follow these conventions:
valueOf
that
returns an instance of the given type and takes a single String
argument or a public constructor which takes a single String
argument.String
argument from the previous bullet can be provided by
toString()
method of the instance.Beans
, but the beans properties must use those rules. Java Beans
are defined in JavaBeans specification.java.util.Map
s. The keys can be java.lang.String
. The values
of a single type follow these rules.
The properties metadata is accessible with
getPropertyMetadata(String)
. The operations metadata is accessible
with getOperationMetadata(String)
.
In order to provide common behavior, all functions must follow a set of common rules related to the implementation of their setters, getters, operations and events:
java.lang.Object
and this interface methods.Modifier and Type | Field and Description |
---|---|
static String |
SERVICE_DESCRIPTION
The service property value contains the function description.
|
static String |
SERVICE_DEVICE_UID
The service property value contains the device unique identifier.
|
static String |
SERVICE_OPERATION_NAMES
The service property value contains the function operation names.
|
static String |
SERVICE_PROPERTY_NAMES
The service property value contains the function property names.
|
static String |
SERVICE_REFERENCE_UIDS
The service property value contains the reference function unique
identifiers.
|
static String |
SERVICE_TYPE
The service property value contains the function type.
|
static String |
SERVICE_UID
The service property value contains the function unique identifier.
|
static String |
SERVICE_VERSION
The service property value contains the function version.
|
Modifier and Type | Method and Description |
---|---|
OperationMetadata |
getOperationMetadata(String operationName)
Provides metadata about the function operation.
|
PropertyMetadata |
getPropertyMetadata(String propertyName)
Provides metadata about the function property.
|
Object |
getServiceProperty(String propKey)
Returns the current value of the specified property.
|
String[] |
getServicePropertyKeys()
Returns an array with all function service property keys.
|
static final String SERVICE_UID
java.lang.String
. To
simplify the unique identifier generation, the property value must follow
the rule:
function UID ::= device-id ':' function-id
function UID - function unique identifier
device-id - the value of the Device.SERVICE_UID
Device service
property
function-id - function identifier in the scope of the device
If the function is not bound to a device, the function unique identifier can be device independent.
static final String SERVICE_TYPE
java.lang.String
.
Organizations that want to use function types that do not clash with OSGi Working Group defined types should prefix their types in own namespace.
The type doesn't mandate specific function interface. It can be used with different functions.
static final String SERVICE_VERSION
java.lang.String
.static final String SERVICE_DEVICE_UID
java.lang.String
.static final String SERVICE_REFERENCE_UIDS
java.lang.String[]
. It can be used to represent different
relationships between the functions.static final String SERVICE_DESCRIPTION
java.lang.String
.static final String SERVICE_PROPERTY_NAMES
java.lang.String[]
. It's not possible to exist
two or more function properties with the same name.static final String SERVICE_OPERATION_NAMES
java.lang.String[]
. It's not possible to exist
two or more function operations with the same name i.e. the operation
overloading is not allowed.PropertyMetadata getPropertyMetadata(String propertyName)
This method must continue to return the property metadata after the function service has been unregistered.
propertyName
- The function property name, for which metadata is
requested.null
if the property metadata is not available.IllegalArgumentException
- If the function property with the
specified name is not available.OperationMetadata getOperationMetadata(String operationName)
This method must continue to return the operation metadata after the function service has been unregistered.
operationName
- The function operation name, for which metadata is
requested.null
if the operation metadata is not available.IllegalArgumentException
- If the function operation with the
specified name is not available.Object getServiceProperty(String propKey)
ServiceReference.getProperty(String)
for
the service reference of this function.
This method must continue to return property values after the device function service has been unregistered.
propKey
- The property key.null
if the property key cannot be
mapped to a value.String[] getServicePropertyKeys()
ServiceReference.getPropertyKeys()
for
the service reference of this function. The result cannot be null
.null
.Copyright © Contributors to the Eclipse Foundation Licensed under the Eclipse Foundation Specification License – v1.0