All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.stepfunc.rodbus.DeviceMap Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
// This library is provided under the terms of a non-commercial license.
// 
// Please refer to the source repository for details:
// 
// https://github.com/stepfunc/rodbus/blob/master/LICENSE.txt
// 
// Please contact Step Function I/O if you are interested in commercial license:
// 
// [email protected]
package io.stepfunc.rodbus;

import org.joou.*;

/**
 * Maps endpoint handlers to Modbus address
 */
public final class DeviceMap
{
    final private long self;
    private java.util.concurrent.atomic.AtomicBoolean disposed = new java.util.concurrent.atomic.AtomicBoolean(false);
    
    private DeviceMap(long self)
    {
        this.self = self;
    }
    
    /**
     * Create a device map that will be used to bind devices to a server endpoint
     * 
     */
    public DeviceMap()
    {
        DeviceMap object = NativeFunctions.device_map_new();
        this.self = object.self;
        object.disposed.set(true);
    }
    
    private void close()
    {
        if (this.disposed.getAndSet(true))
            return;
        
        NativeFunctions.device_map_destroy(this);
    }
    
    @Override
    public void finalize()
    {
        this.close();
    }
    
    /**
     * add an endpoint to the map
     * 
     * @param unitId Unit id of the endpoint
     * @param handler callback interface for handling write operations for this device
     * @param configure one-time callback interface configuring the initial state of the database
     * @return True if the unit id doesn't already exists, false otherwise
     */
    public boolean addEndpoint(UByte unitId, WriteHandler handler, DatabaseCallback configure)
    {
        return NativeFunctions.map_add_endpoint(this, unitId, handler, configure);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy