简体   繁体   中英

Converting a Foo into a Foo.ByValue?

I am integrating with an aged lm_sensors library using JNA and JNAerator, with a view to creating MBeans for each of the temperature sensors inside my box. Firstly I'm calling this method:

// C edition
const sensors_chip_name *sensors_get_detected_chips(int *nr);

// Java edition
sensors_chip_name sensors_get_detected_chips(IntByReference nr);

.. which works just fine. Subsequently I need to call:

// C edition
int sensors_get_feature(sensors_chip_name name, int feature, double *result);

// Java edition
int sensors_get_feature(sensors_chip_name.ByValue name, int feature, DoubleByReference result);

.. what I am lacking is how to take the result of sensors_get_detected_chips and pass it by value to the 1st argument of sensors_get_feature .

The following allows a ByValue version of the struct to be initialized from the base class.

public class sensors_chip_name extends Structure {
    public class ByValue extends sensors_chip_name implements Structure.ByValue {
        public ByValue(sensors_chip_name orig) {
            this(orig.getPointer().share());
        }
        public ByValue(Pointer p) {
            super(p);
        }
        public ByValue() { }
    }
    public sensors_chip_name() { }
    public sensors_chip_name(Pointer p) { 
        super(p);
        read();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM