Skip to content

Commit

Permalink
Applied review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alex9849 committed Feb 6, 2024
1 parent b5da771 commit 25d1187
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 229 deletions.
38 changes: 0 additions & 38 deletions libraries/pi4j-library-gpiod/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.pi4j.library.gpiod.internal;

import java.util.Objects;

public class CWrapper {
private long cPointer;

public CWrapper(long cPointer) {
this.cPointer = cPointer;
}

long getCPointer() {
return cPointer;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CWrapper cWrapper = (CWrapper) o;
return cPointer == cWrapper.cPointer;
}

@Override
public int hashCode() {
return Objects.hash(cPointer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
* @author Alexander Liggesmeyer (<a href="https://alexander.liggesmeyer.net/">https://alexander.liggesmeyer.net/</a>)
* @version $Id: $Id
*/
public class GpioChip implements Closeable {
private final long cPtr;
public class GpioChip extends CWrapper implements Closeable {

GpioChip(long cPtr) {
this.cPtr = cPtr;
}

long getCPtr() {
return this.cPtr;
public GpioChip(long cPointer) {
super(cPointer);
}

public void close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,31 @@
* @author Alexander Liggesmeyer (<a href="https://alexander.liggesmeyer.net/">https://alexander.liggesmeyer.net/</a>)
* @version $Id: $Id
*/
public class GpioChipIterator implements Iterator<GpioChip> {
public class GpioChipIterator extends CWrapper implements Iterator<GpioChip> {

private final long cPtr;
private boolean noCoseCurrent;
private boolean noCloseCurrent;
private GpioChip next;
private GpioChip current;

GpioChipIterator(long cPtr) {
this.cPtr = cPtr;
GpioChipIterator(long cPointer) {
super(cPointer);
}

public GpioChipIterator() {
this(GpioD.chipIterNew());
}

long getCPtr() {
return this.cPtr;
}

@Override
protected void finalize() {
if(next == null) {
if(noCoseCurrent) {
if(noCloseCurrent) {
GpioD.chipIterFreeNoClose(this);
} else {
GpioD.chipIterFree(this);
}
} else {
if(!noCoseCurrent) {
if(!noCloseCurrent) {
GpioD.chipClose(current);
}
GpioD.chipIterFree(this);
Expand All @@ -54,23 +50,23 @@ public boolean hasNext() {
@Override
public GpioChip next() {
if(next == null) {
if(noCoseCurrent) {
if(noCloseCurrent) {
current = GpioD.chipIterNextNoClose(this);
} else {
current = GpioD.chipIterNext(this);
}
} else {
if(current != null && !noCoseCurrent) {
if(current != null && !noCloseCurrent) {
GpioD.chipClose(current);
}
current = next;
noCoseCurrent = false;
noCloseCurrent = false;
next = null;
}
return current;
}

public void noCloseCurrent() {
this.noCoseCurrent = true;
this.noCloseCurrent = true;
}
}
Loading

0 comments on commit 25d1187

Please sign in to comment.