You might look at the Conversion API used by Chime. The API presents a
single Java method to perform named conversions using native libraries:
public static Object get(ConversionName conversion, Object... args)
The args are type-checked depending on the requested conversion.
ConversionName is an enum that defines the range of supported
conversions; it is not possible to call the method with an unsupported
conversion.
To add support for a new conversion, you simply add an entry to the
following array in conversion.c:
static
conversion_t conversion_table[] = {
{ "DEVPATH_TO_cNdNsN", devlink_to_cNdNsN, 1, { CNV_STRING } },
{ "FD_TO_PATH", fd_to_path, 2, { CNV_NUMBER, CNV_NUMBER } },
{ "UID_TO_USERNAME", uid_to_username, 1, { CNV_NUMBER } },
{ NULL, NULL }
};
Each entry consists of a name (matches the value that you add to the
ConversionName enumeration), a function pointer, the expected
number of arguments, and the expected argument types. Of course,
you still need to implement the C function yourself.
You can get the source code by downloading Chime:
http://www.opensolaris.org/os/project/dtrace-chime/install/
After installing Chime, unpack
/opt/OSOL0chime/share/src.tar and the API source will be in
usr/src/lib/libcnv_jni.
Any functions that you implement within this framework
would also be available to Chime (and vice versa). Since Chime
displays are described in XML (rather than compiled), the
Conversion API is particularly convenient. For example, from
the string "DEVPATH_TO_cNdNsN" parsed from XML
and assigned to the variable "name", I obtain the conversion
as follows:
ConversionName c = Enum.valueOf(
ConversionName.class, name);
For path =
"/devices/pci at 0,0/pci1022,7460 at 6/pci-ide at b/ide at 0/ cmdk at 0,0:a"
I can then call
String device = (String)Conversion.get(c, path);
The returned device might equal "c1d0s7". The API works with
JMX in Chime to support tracing on remote systems, and it will
also work independently of Chime.
Tom
--
This messages posted from opensolaris.org