org.freedesktop.dbus.exceptions.DBusException Java Examples

The following examples show how to use org.freedesktop.dbus.exceptions.DBusException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BleApplication.java    From ble-java with MIT License 6 votes vote down vote up
/**
 * Search for a Adapter that has GattManager1 and LEAdvertisement1 interfaces, otherwise return null.
 * @return
 * @throws DBusException
 */
private String findAdapterPath() throws DBusException {
	ObjectManager bluezObjectManager = (ObjectManager) dbusConnection.getRemoteObject(BLUEZ_DBUS_BUSNAME, "/", ObjectManager.class);
	if(bluezObjectManager == null) { return null; }

	Map<Path, Map<String, Map<String, Variant>>> bluezManagedObject = bluezObjectManager.GetManagedObjects();
	if(bluezManagedObject == null) { return null; }
	
	for (Path path : bluezManagedObject.keySet()) {
		Map<String, Map<String, Variant>> value = bluezManagedObject.get(path);
		boolean hasGattManager = false;
		boolean hasAdvManager = false;
		
		for(String key : value.keySet()) {
			if(key.equals(BLUEZ_GATT_INTERFACE)) { hasGattManager = true; }
			if(key.equals(BLUEZ_LE_ADV_INTERFACE)) { hasAdvManager = true; }
			
			if(hasGattManager && hasAdvManager) { return path.toString(); }
		}
	}
	
	return null;
}
 
Example #2
Source File: Message.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Warning, do not use this method unless you really know what you are doing.
 */
public void setSource(String source) throws DBusException {
    if (null != body) {
        wiredata = new byte[BUFFERINCREMENT][];
        bufferuse = 0;
        bytecounter = 0;
        preallocate(12);
        append("yyyyuu", big ? Endian.BIG : Endian.LITTLE, type, flags, protover, bodylen, serial);
        headers.put(HeaderField.SENDER, source);
        Object[][] newhead = new Object[headers.size()][];
        int i = 0;
        for (Byte b : headers.keySet()) {
            newhead[i] = new Object[2];
            newhead[i][0] = b;
            newhead[i][1] = headers.get(b);
            i++;
        }
        append("a(yv)", (Object) newhead);
        pad((byte) 8);
        appendBytes(body);
    }
}
 
Example #3
Source File: DBusSignal.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static Class<? extends DBusSignal> createSignalClass(String intname, String signame) throws DBusException {
    String name = intname + '$' + signame;
    Class<? extends DBusSignal> c = classCache.get(name);
    if (null == c) c = DBusMatchRule.getCachedSignalType(name);
    if (null != c) return c;
    do {
        try {
            c = (Class<? extends DBusSignal>) Class.forName(name);
        } catch (ClassNotFoundException CNFe) {
        }
        name = name.replaceAll("\\.([^\\.]*)$", "\\$$1");
    } while (null == c && name.matches(".*\\..*"));
    if (null == c)
        throw new DBusException(getString("cannotCreateClassFromSignal") + intname + '.' + signame);
    classCache.put(name, c);
    return c;
}
 
Example #4
Source File: Message.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Create a message from wire-format data.
 *
 * @param msg     D-Bus serialized data of type yyyuu
 * @param headers D-Bus serialized data of type a(yv)
 * @param body    D-Bus serialized data of the signature defined in headers.
 */
@SuppressWarnings("unchecked")
void populate(byte[] msg, byte[] headers, byte[] body) throws DBusException {
    big = (msg[0] == Endian.BIG);
    type = msg[1];
    flags = msg[2];
    protover = msg[3];
    wiredata[0] = msg;
    wiredata[1] = headers;
    wiredata[2] = body;
    this.body = body;
    bufferuse = 3;
    bodylen = ((Number) extract(Message.ArgumentType.UINT32_STRING, msg, 4)[0]).longValue();
    serial = ((Number) extract(Message.ArgumentType.UINT32_STRING, msg, 8)[0]).longValue();
    bytecounter = msg.length + headers.length + body.length;
    if (Debug.debug) Debug.print(Debug.VERBOSE, headers);
    Object[] hs = extract("a(yv)", headers, 0);
    if (Debug.debug) Debug.print(Debug.VERBOSE, Arrays.deepToString(hs));
    for (Object o : (Vector<Object>) hs[0]) {
        this.headers.put((Byte) ((Object[]) o)[0], ((Variant<Object>) ((Object[]) o)[1]).getValue());
    }
}
 
Example #5
Source File: DBusConnection.java    From keycloak with Apache License 2.0 6 votes vote down vote up
protected <T extends DBusSignal> void removeSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler) throws DBusException {

        SignalTuple key = new SignalTuple(rule.getInterface(), rule.getMember(), rule.getObject(), rule.getSource());
        synchronized (handledSignals) {
            Vector<DBusSigHandler<? extends DBusSignal>> v = handledSignals.get(key);
            if (null != v) {
                v.remove(handler);
                if (0 == v.size()) {
                    handledSignals.remove(key);
                    try {
                        _dbus.RemoveMatch(rule.toString());
                    } catch (NotConnected NC) {
                        if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, NC);
                    } catch (DBusExecutionException DBEe) {
                        if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe);
                        throw new DBusException(DBEe.getMessage());
                    }
                }
            }
        }
    }
 
Example #6
Source File: BleApplication.java    From ble-java with MIT License 6 votes vote down vote up
/**
 * Stop the advertisement and unpublish the service.
 * @throws DBusException
 * @throws InterruptedException
 */
public void stop() throws DBusException, InterruptedException {
	if(adapterPath == null) { return; }
	GattManager1 gattManager = (GattManager1) dbusConnection.getRemoteObject(BLUEZ_DBUS_BUSNAME, adapterPath, GattManager1.class);
	LEAdvertisingManager1 advManager = (LEAdvertisingManager1) dbusConnection.getRemoteObject(BLUEZ_DBUS_BUSNAME, adapterPath, LEAdvertisingManager1.class);
	
	if(adv != null) {
		advManager.UnregisterAdvertisement(adv);
	}
	gattManager.UnregisterApplication(this);

	unexport();
	dbusConnection.removeSigHandler(InterfacesAdded.class, interfacesAddedSignalHandler);
	dbusConnection.removeSigHandler(InterfacesRemoved.class, interfacesRemovedSignalHandler);
	dbusConnection.disconnect();
	dbusConnection = null;
}
 
Example #7
Source File: DBusConnection.java    From keycloak with Apache License 2.0 6 votes vote down vote up
protected <T extends DBusSignal> void addSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler) throws DBusException {
    try {
        _dbus.AddMatch(rule.toString());
    } catch (DBusExecutionException DBEe) {
        if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe);
        throw new DBusException(DBEe.getMessage());
    }
    SignalTuple key = new SignalTuple(rule.getInterface(), rule.getMember(), rule.getObject(), rule.getSource());
    synchronized (handledSignals) {
        Vector<DBusSigHandler<? extends DBusSignal>> v = handledSignals.get(key);
        if (null == v) {
            v = new Vector<DBusSigHandler<? extends DBusSignal>>();
            v.add(handler);
            handledSignals.put(key, v);
        } else
            v.add(handler);
    }
}
 
Example #8
Source File: ExportedObject.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public ExportedObject(DBusInterface object, boolean weakreferences) throws DBusException {
    if (weakreferences)
        this.object = new WeakReference<DBusInterface>(object);
    else
        this.object = new StrongReference<DBusInterface>(object);
    introspectiondata = "";
    methods = getExportedMethods(object.getClass());
    introspectiondata +=
            " <interface name=\"org.freedesktop.DBus.Introspectable\">\n" +
                    "  <method name=\"Introspect\">\n" +
                    "   <arg type=\"s\" direction=\"out\"/>\n" +
                    "  </method>\n" +
                    " </interface>\n";
    introspectiondata +=
            " <interface name=\"org.freedesktop.DBus.Peer\">\n" +
                    "  <method name=\"Ping\">\n" +
                    "  </method>\n" +
                    " </interface>\n";
}
 
Example #9
Source File: DBusConnection.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Connect to the BUS. If a connection already exists to the specified Bus, a reference to it is returned.
 *
 * @param address The address of the bus to connect to
 * @throws DBusException If there is a problem connecting to the Bus.
 */
public static DBusConnection getConnection(String address) throws DBusException {
    synchronized (conn) {
        DBusConnection c = conn.get(address);
        if (null != c) {
            synchronized (c._reflock) {
                c._refcount++;
            }
            return c;
        } else {
            c = new DBusConnection(address);
            conn.put(address, c);
            return c;
        }
    }
}
 
Example #10
Source File: AbstractBluetoothObject.java    From bluez-dbus with MIT License 5 votes vote down vote up
/**
 * Helper to get a value of a DBus property.
 * @param _field DBus property key
 * @param _type expected return type of DBus property
 * @param <T> class of the expected result
 * @return value of _field as _type class or null
 */
protected <T> T getTyped(String _field, Class<T> _type) {
    try {
        Properties remoteObject = dbusConnection.getRemoteObject("org.bluez", dbusPath, Properties.class);
        Object obj = remoteObject.Get(getInterfaceClass().getName(), _field);
        if (ClassUtils.isAssignable(_type, obj.getClass())) {
            return _type.cast(obj);
        }

    } catch (DBusException | DBusExecutionException _ex) {
        logger.trace("Error while receiving data from DBUS (Field: {}, Type: {}).", _field, _type, _ex);
    }
    return null;
}
 
Example #11
Source File: AbstractConnection.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private Message readIncoming() throws DBusException {
    if (!connected) throw new NotConnected(getString("missingTransport"));
    Message m = null;
    try {
        m = transport.min.readMessage();
    } catch (IOException IOe) {
        throw new FatalDBusException(IOe.getMessage());
    }
    return m;
}
 
Example #12
Source File: Signal.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public MessageReceived(String objectpath, long timestamp, String sender, byte[] groupId, String message, List<String> attachments) throws DBusException {
    super(objectpath, timestamp, sender, groupId, message, attachments);
    this.timestamp = timestamp;
    this.sender = sender;
    this.groupId = groupId;
    this.message = message;
    this.attachments = attachments;
}
 
Example #13
Source File: DBusSignal.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void appendbody(AbstractConnection conn) throws DBusException {
    if (bodydone) return;

    Type[] types = typeCache.get(getClass());
    Object[] args = Marshalling.convertParameters(getParameters(), types, conn);
    setArgs(args);
    String sig = getSig();

    long c = bytecounter;
    if (null != args && 0 < args.length) append(sig, args);
    marshallint(bytecounter - c, blen, 0, 4);
    bodydone = true;
}
 
Example #14
Source File: DeviceManager.java    From bluez-dbus with MIT License 5 votes vote down vote up
/**
 * Create a new {@link DeviceManager} instance using the given DBus address (e.g. tcp://127.0.0.1:13245)
 * @param _address address to connect to
 * @throws DBusException on error
 *
 * @return {@link DeviceManager}
 */
public static DeviceManager createInstance(String _address) throws DBusException {
    if (_address == null) {
        throw new DBusException("Null is not a valid address");
    }
    INSTANCE = new DeviceManager(DBusConnection.getConnection(_address));
    return INSTANCE;
}
 
Example #15
Source File: Variant.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Create a Variant from a basic type object.
 *
 * @param o The wrapped value.
 * @throws IllegalArugmentException If you try and wrap Null or an object of a non-basic type.
 */
public Variant(T o) throws IllegalArgumentException {
    if (null == o) throw new IllegalArgumentException(getString("cannotWrapNullInVariant"));
    type = o.getClass();
    try {
        String[] ss = Marshalling.getDBusType(o.getClass(), true);
        if (ss.length != 1)
            throw new IllegalArgumentException(getString("cannotWrapMultiValuedInVariant") + type);
        this.sig = ss[0];
    } catch (DBusException DBe) {
        if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe);
        throw new IllegalArgumentException(MessageFormat.format(getString("cannotWrapUnqualifiedVariant"), new Object[]{o.getClass(), DBe.getMessage()}));
    }
    this.o = o;
}
 
Example #16
Source File: DBusConnection.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Disconnect from the Bus.
 * This only disconnects when the last reference to the bus has disconnect called on it
 * or has been destroyed.
 */
public void disconnect() {
    synchronized (conn) {
        synchronized (_reflock) {
            if (0 == --_refcount) {
                if (Debug.debug) Debug.print(Debug.INFO, "Disconnecting DBusConnection");
                // Set all pending messages to have an error.
                try {
                    Error err = new Error(
                            "org.freedesktop.DBus.Local", "org.freedesktop.DBus.Local.disconnected", 0, "s", new Object[]{getString("disconnected")});
                    synchronized (pendingCalls) {
                        long[] set = pendingCalls.getKeys();
                        for (long l : set)
                            if (-1 != l) {
                                MethodCall m = pendingCalls.remove(l);
                                if (null != m)
                                    m.setReply(err);
                            }
                        pendingCalls = null;
                    }
                    synchronized (pendingErrors) {
                        pendingErrors.add(err);
                    }
                } catch (DBusException DBe) {
                }

                conn.remove(addr);
                super.disconnect();
            }
        }
    }
}
 
Example #17
Source File: DbusHelper.java    From bluez-dbus with MIT License 5 votes vote down vote up
/**
 * Creates an java object from a bluez dbus response.
 * @param _connection Dbus connection to use
 * @param _path dbus request path
 * @param _objClass interface class to use
 * @param <T> some class/interface implementing/extending {@link DBusInterface}
 * @return the created object or null on error
 */
public static <T extends DBusInterface> T getRemoteObject(DBusConnection _connection, String _path, Class<T> _objClass) {
    try {
        return _connection.getRemoteObject("org.bluez", _path, _objClass);
    } catch (DBusException _ex) {
        LOGGER.warn("Error while converting dbus response to object.", _ex);
    }
    return null;
}
 
Example #18
Source File: AbstractBluetoothObject.java    From bluez-dbus with MIT License 5 votes vote down vote up
/**
 * Helper to set a value on a DBus property.
 *
 * @param _field DBus property key
 * @param _value value to set
 */
protected void setTyped(String _field, Object _value) {
    try {
        Properties remoteObject = dbusConnection.getRemoteObject("org.bluez", dbusPath, Properties.class);
        remoteObject.Set(getInterfaceClass().getName(), _field, _value);
    } catch (DBusException _ex) {
        logger.trace("Error while setting data for DBUS (Field: {}, Value: {}).", _field, _value, _ex);
    }
}
 
Example #19
Source File: AbstractConnection.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected AbstractConnection(String address) throws DBusException {
    exportedObjects = new HashMap<String, ExportedObject>();
    importedObjects = new HashMap<DBusInterface, RemoteObject>();
    _globalhandlerreference = new _globalhandler();
    synchronized (exportedObjects) {
        exportedObjects.put(null, new ExportedObject(_globalhandlerreference, weakreferences));
    }
    handledSignals = new HashMap<SignalTuple, Vector<DBusSigHandler<? extends DBusSignal>>>();
    pendingCalls = new EfficientMap(PENDING_MAP_INITIAL_SIZE);
    outgoing = new EfficientQueue(PENDING_MAP_INITIAL_SIZE);
    pendingCallbacks = new HashMap<MethodCall, CallbackHandler<? extends Object>>();
    pendingCallbackReplys = new HashMap<MethodCall, DBusAsyncReply<? extends Object>>();
    pendingErrors = new LinkedList<Error>();
    runnables = new LinkedList<Runnable>();
    workers = new LinkedList<_workerthread>();
    objectTree = new ObjectTree();
    fallbackcontainer = new FallbackContainer();
    synchronized (workers) {
        for (int i = 0; i < THREADCOUNT; i++) {
            _workerthread t = new _workerthread();
            t.start();
            workers.add(t);
        }
    }
    _run = true;
    addr = address;
}
 
Example #20
Source File: DBusConnection.java    From keycloak with Apache License 2.0 5 votes vote down vote up
DBusInterface getExportedObject(String source, String path) throws DBusException {
    ExportedObject o = null;
    synchronized (exportedObjects) {
        o = exportedObjects.get(path);
    }
    if (null != o && null == o.object.get()) {
        unExportObject(path);
        o = null;
    }
    if (null != o) return o.object.get();
    if (null == source) throw new DBusException(getString("objectNotExportedNoRemoteSpecified"));
    return dynamicProxy(source, path);
}
 
Example #21
Source File: Error.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public Error(String source, String dest, String errorName, long replyserial, String sig, Object... args) throws DBusException {
    super(Message.Endian.BIG, Message.MessageType.ERROR, (byte) 0);

    if (null == errorName)
        throw new MessageFormatException(getString("missingErrorName"));
    headers.put(Message.HeaderField.REPLY_SERIAL, replyserial);
    headers.put(Message.HeaderField.ERROR_NAME, errorName);

    Vector<Object> hargs = new Vector<Object>();
    hargs.add(new Object[]{Message.HeaderField.ERROR_NAME, new Object[]{ArgumentType.STRING_STRING, errorName}});
    hargs.add(new Object[]{Message.HeaderField.REPLY_SERIAL, new Object[]{ArgumentType.UINT32_STRING, replyserial}});

    if (null != source) {
        headers.put(Message.HeaderField.SENDER, source);
        hargs.add(new Object[]{Message.HeaderField.SENDER, new Object[]{ArgumentType.STRING_STRING, source}});
    }

    if (null != dest) {
        headers.put(Message.HeaderField.DESTINATION, dest);
        hargs.add(new Object[]{Message.HeaderField.DESTINATION, new Object[]{ArgumentType.STRING_STRING, dest}});
    }

    if (null != sig) {
        hargs.add(new Object[]{Message.HeaderField.SIGNATURE, new Object[]{ArgumentType.SIGNATURE_STRING, sig}});
        headers.put(Message.HeaderField.SIGNATURE, sig);
        setArgs(args);
    }

    byte[] blen = new byte[4];
    appendBytes(blen);
    append("ua(yv)", serial, hargs.toArray());
    pad((byte) 8);

    long c = bytecounter;
    if (null != sig) append(sig, args);
    marshallint(bytecounter - c, blen, 0, 4);
}
 
Example #22
Source File: DBusConnection.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private DBusConnection(String address) throws DBusException {
    super(address);
    busnames = new Vector<String>();

    synchronized (_reflock) {
        _refcount = 1;
    }

    try {
        transport = new Transport(addr, AbstractConnection.TIMEOUT);
        connected = true;
    } catch (IOException IOe) {
        if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOe);
        disconnect();
        throw new DBusException(getString("connectionFailure") + IOe.getMessage());
    } catch (ParseException Pe) {
        if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, Pe);
        disconnect();
        throw new DBusException(getString("connectionFailure") + Pe.getMessage());
    }

    // start listening for calls
    listen();

    // register disconnect handlers
    DBusSigHandler h = new _sighandler();
    addSigHandlerWithoutMatch(org.freedesktop.DBus.Local.Disconnected.class, h);
    addSigHandlerWithoutMatch(org.freedesktop.DBus.NameAcquired.class, h);

    // register ourselves
    _dbus = getRemoteObject("org.freedesktop.DBus", "/org/freedesktop/DBus", DBus.class);
    try {
        busnames.add(_dbus.Hello());
    } catch (DBusExecutionException DBEe) {
        if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe);
        throw new DBusException(DBEe.getMessage());
    }
}
 
Example #23
Source File: AbstractConnection.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected <T extends DBusSignal> void addSigHandlerWithoutMatch(Class<? extends DBusSignal> signal, DBusSigHandler<T> handler) throws DBusException {
    DBusMatchRule rule = new DBusMatchRule(signal);
    SignalTuple key = new SignalTuple(rule.getInterface(), rule.getMember(), rule.getObject(), rule.getSource());
    synchronized (handledSignals) {
        Vector<DBusSigHandler<? extends DBusSignal>> v = handledSignals.get(key);
        if (null == v) {
            v = new Vector<DBusSigHandler<? extends DBusSignal>>();
            v.add(handler);
            handledSignals.put(key, v);
        } else
            v.add(handler);
    }
}
 
Example #24
Source File: TypeSignature.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public TypeSignature(Type[] types) throws DBusException {
    StringBuffer sb = new StringBuffer();
    for (Type t : types) {
        String[] ts = Marshalling.getDBusType(t);
        for (String s : ts)
            sb.append(s);
    }
    this.sig = sb.toString();
}
 
Example #25
Source File: Sssd.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public Sssd(String username) {
    this.username = username;
    try {
        if (LibraryLoader.load().succeed())
            dBusConnection = DBusConnection.getConnection(DBusConnection.SYSTEM);
    } catch (DBusException e) {
        e.printStackTrace();
    }

}
 
Example #26
Source File: Variant.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Create a Variant.
 *
 * @param o    The wrapped value.
 * @param type The explicit type of the value.
 * @throws IllegalArugmentException If you try and wrap Null or an object which cannot be sent over DBus.
 */
public Variant(T o, Type type) throws IllegalArgumentException {
    if (null == o) throw new IllegalArgumentException(getString("cannotWrapNullInVariant"));
    this.type = type;
    try {
        String[] ss = Marshalling.getDBusType(type);
        if (ss.length != 1)
            throw new IllegalArgumentException(getString("cannotWrapMultiValuedInVariant") + type);
        this.sig = ss[0];
    } catch (DBusException DBe) {
        if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe);
        throw new IllegalArgumentException(MessageFormat.format(getString("cannotWrapUnqualifiedVariant"), new Object[]{type, DBe.getMessage()}));
    }
    this.o = o;
}
 
Example #27
Source File: MethodReturn.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public MethodReturn(String source, String dest, long replyserial, String sig, Object... args) throws DBusException {
    super(Message.Endian.BIG, Message.MessageType.METHOD_RETURN, (byte) 0);

    headers.put(Message.HeaderField.REPLY_SERIAL, replyserial);

    Vector<Object> hargs = new Vector<Object>();
    hargs.add(new Object[]{Message.HeaderField.REPLY_SERIAL, new Object[]{ArgumentType.UINT32_STRING, replyserial}});

    if (null != source) {
        headers.put(Message.HeaderField.SENDER, source);
        hargs.add(new Object[]{Message.HeaderField.SENDER, new Object[]{ArgumentType.STRING_STRING, source}});
    }

    if (null != dest) {
        headers.put(Message.HeaderField.DESTINATION, dest);
        hargs.add(new Object[]{Message.HeaderField.DESTINATION, new Object[]{ArgumentType.STRING_STRING, dest}});
    }

    if (null != sig) {
        hargs.add(new Object[]{Message.HeaderField.SIGNATURE, new Object[]{ArgumentType.SIGNATURE_STRING, sig}});
        headers.put(Message.HeaderField.SIGNATURE, sig);
        setArgs(args);
    }

    byte[] blen = new byte[4];
    appendBytes(blen);
    append("ua(yv)", serial, hargs.toArray());
    pad((byte) 8);

    long c = bytecounter;
    if (null != sig) append(sig, args);
    marshallint(bytecounter - c, blen, 0, 4);
}
 
Example #28
Source File: Message.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Create a message; only to be called by sub-classes.
 *
 * @param endian The endianness to create the message.
 * @param type   The message type.
 * @param flags  Any message flags.
 */
protected Message(byte endian, byte type, byte flags) throws DBusException {
    wiredata = new byte[BUFFERINCREMENT][];
    headers = new HashMap<Byte, Object>();
    big = (Endian.BIG == endian);
    bytecounter = 0;
    synchronized (Message.class) {
        serial = ++globalserial;
    }
    if (Debug.debug) Debug.print(Debug.DEBUG, "Creating message with serial " + serial);
    this.type = type;
    this.flags = flags;
    preallocate(4);
    append("yyyy", endian, type, flags, Message.PROTOCOL);
}
 
Example #29
Source File: Message.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Demarshall values from a buffer.
 *
 * @param sig The D-Bus signature(s) of the value(s).
 * @param buf The buffer to demarshall from.
 * @param ofs An array of two ints, the offset into the signature
 *            and the offset into the data buffer. These values will be
 *            updated to the start of the next value ofter demarshalling.
 * @return The demarshalled value(s).
 */
public Object[] extract(String sig, byte[] buf, int[] ofs) throws DBusException {
    if (Debug.debug)
        Debug.print(Debug.VERBOSE, "extract(" + sig + ",#" + buf.length + ", {" + ofs[0] + "," + ofs[1] + "}");
    Vector<Object> rv = new Vector<Object>();
    byte[] sigb = sig.getBytes();
    for (int[] i = ofs; i[0] < sigb.length; i[0]++) {
        rv.add(extractone(sigb, buf, i, false));
    }
    return rv.toArray();
}
 
Example #30
Source File: Message.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Parses and returns the parameters to this message as an Object array.
 */
public Object[] getParameters() throws DBusException {
    if (null == args && null != body) {
        String sig = (String) headers.get(HeaderField.SIGNATURE);
        if (null != sig && 0 != body.length) {
            args = extract(sig, body, 0);
        } else args = new Object[0];
    }
    return args;
}