Package com.lucimber.dbus.type
This package implements the complete D-Bus type system as Java wrapper classes that ensure type safety and prevent marshalling errors. All D-Bus types are represented as immutable Java objects that can be safely used across threads.
Getting Started
For first-time users: Start with common types like DBusString, DBusInt32, and DBusBoolean. For paths use DBusObjectPath, and for collections
use DBusArray and DBusDict. All types use static factory methods like
DBusString.valueOf("hello").
Type Hierarchy
All D-Bus types implement the DBusType interface and are organized into two main
categories:
Basic Types (DBusBasicType)
Fixed-size, atomic data types:
DBusByte- 8-bit unsigned integer (0-255)DBusBoolean- Boolean value (true/false)DBusInt16- 16-bit signed integerDBusUInt16- 16-bit unsigned integerDBusInt32- 32-bit signed integerDBusUInt32- 32-bit unsigned integerDBusInt64- 64-bit signed integerDBusUInt64- 64-bit unsigned integerDBusDouble- IEEE 754 double-precision floating pointDBusString- UTF-8 text stringDBusObjectPath- D-Bus object pathDBusSignature- D-Bus type signatureDBusUnixFD- Unix file descriptor
Container Types (DBusContainerType)
Variable-size, composite data types:
DBusArray- Homogeneous array of elementsDBusStruct- Heterogeneous structure (like a tuple)DBusDict- Key-value dictionary/mapDBusDictEntry- Single dictionary entryDBusVariant- Dynamically typed value
Usage Examples
Basic Types
// Creating basic types
DBusString text = DBusString.valueOf("Hello, D-Bus!");
DBusInt32 number = DBusInt32.valueOf(42);
DBusBoolean flag = DBusBoolean.valueOf(true);
DBusObjectPath path = DBusObjectPath.valueOf("/org/example/Object");
// Type safety at compile time
// This would be a compilation error:
// DBusString text = DBusInt32.valueOf(42); // Won't compile!
Arrays
// Create a string array
DBusSignature signature = DBusSignature.valueOf("as");
DBusArray<DBusString> stringArray = new DBusArray<>(signature);
stringArray.add(DBusString.valueOf("first"));
stringArray.add(DBusString.valueOf("second"));
stringArray.add(DBusString.valueOf("third"));
// Type safety ensures only strings can be added
// stringArray.add(DBusInt32.valueOf(123)); // Compilation error!
Dictionaries
// Create a string-to-integer dictionary
DBusSignature dictSignature = DBusSignature.valueOf("a{si}");
DBusDict<DBusString, DBusInt32> dict = new DBusDict<>(dictSignature);
dict.put(DBusString.valueOf("count"), DBusInt32.valueOf(10));
dict.put(DBusString.valueOf("limit"), DBusInt32.valueOf(100));
// Access values safely
DBusInt32 count = dict.get(DBusString.valueOf("count"));
if (count != null) {
System.out.println("Count: " + count.getDelegate());
}
Structures
// Create a structure (string, int32, boolean)
DBusSignature structSig = DBusSignature.valueOf("(sib)");
DBusStruct struct = new DBusStruct(structSig,
DBusString.valueOf("example"),
DBusInt32.valueOf(42),
DBusBoolean.valueOf(true)
);
// Access struct elements
List<DBusType> elements = struct.getElements();
DBusString firstElement = (DBusString) elements.get(0);
Variants
// Variants can hold any D-Bus type
DBusVariant stringVariant = DBusVariant.valueOf(DBusString.valueOf("text"));
DBusVariant numberVariant = DBusVariant.valueOf(DBusInt32.valueOf(123));
// Type checking when extracting values
if (stringVariant.getValue() instanceof DBusString) {
DBusString text = (DBusString) stringVariant.getValue();
System.out.println("Text: " + text.toString());
}
Type Signatures
D-Bus type signatures describe the structure of data using a compact string format:
| Type | Signature | Java Type |
|---|---|---|
| Byte | y | DBusByte |
| Boolean | b | DBusBoolean |
| Int32 | i | DBusInt32 |
| String | s | DBusString |
| Array of strings | as | DBusArray<DBusString> |
| Dictionary | a{si} | DBusDict<DBusString, DBusInt32> |
| Struct | (si) | DBusStruct |
| Variant | v | DBusVariant |
Validation and Constraints
All types enforce D-Bus specification constraints:
- String validation: Strings must be valid UTF-8 and not contain NUL characters
- Object path validation: Object paths must follow D-Bus naming conventions
- Signature validation: Type signatures must be syntactically correct
- Size limits: Arrays and strings have maximum size limits (64MB for arrays, 256MB for strings)
- Alignment requirements: Data is properly aligned according to D-Bus specification
Immutability and Thread Safety
All D-Bus types are immutable and thread-safe:
- Once created, type instances cannot be modified
- Container types provide defensive copies when needed
- All operations are safe for concurrent access
- No synchronization is required when sharing instances between threads
Memory Efficiency
The type system is designed for memory efficiency:
- Basic types wrap primitive values with minimal overhead
- Container types use efficient underlying collections
- Large objects (arrays, strings) are handled with care for memory usage
- Type signatures are validated once and cached
- Since:
- 1.0
- See Also:
-
ClassDescriptionAn ordered collection of elements.The D-Bus type system consists of two distinct categories known as basic and container types.Maps a
Booleanto its D-Bus equivalent of BOOLEAN.Maps aByteto its D-Bus equivalent of BYTE.The D-Bus type system consists of two distinct categories known as basic and container types.An object that maps keys to values.A map entry (key-value pair).Maps aDoubleto its D-Bus equivalent of DOUBLE.Maps aShortto its D-Bus equivalent of INT16.Maps anIntegerto its D-Bus equivalent of INT32.Maps aLongto its D-Bus equivalent of INT64.D-Bus objects are identified within an application via their object path.D-Bus uses a string-based type encoding mechanism called Signatures to describe the number and types of arguments required by methods and signals.Maps aStringto its D-Bus equivalent of STRING.A struct that can hold various objects.Common interface of all D-Bus data types.Maps an unsignedShortto its D-Bus equivalent of UINT16.Maps an unsignedIntegerto its D-Bus equivalent of UINT32.Maps an unsignedLongto its D-Bus equivalent of UINT64.Maps an unsignedIntegerto its D-Bus equivalent of UNIX_FD.Variants may contain a value of any type.ARuntimeExceptionthat gets thrown byDBusObjectPath, if a marshalledDBusObjectPathcannot be parsed.ARuntimeExceptionthat gets thrown byDBusSignature, if a marshalledDBusSignaturecannot be parsed.Represents the data types defined by D-Bus.Represents the alignment values of the data types that are used by D-Bus.Represents the type codes of the data types that are used by D-Bus.A utility class that provides useful methods in conjunction with the D-Bus data types.