Skip to content

Commit 1d663ac

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 67398a3 + d1dab2e commit 1d663ac

File tree

8 files changed

+55
-37
lines changed

8 files changed

+55
-37
lines changed
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package io.github.digitalsmile.gpio.libcurl;
22

33
import io.github.digitalsmile.annotation.NativeMemory;
4+
import io.github.digitalsmile.annotation.NativeMemoryException;
45
import io.github.digitalsmile.annotation.NativeMemoryOptions;
56
import io.github.digitalsmile.annotation.function.ByAddress;
67
import io.github.digitalsmile.annotation.function.NativeManualFunction;
7-
import io.github.digitalsmile.annotation.NativeMemoryException;
88
import io.github.digitalsmile.annotation.structure.Enum;
99
import io.github.digitalsmile.annotation.structure.Enums;
1010
import io.github.digitalsmile.annotation.structure.Struct;
1111
import io.github.digitalsmile.annotation.structure.Structs;
12-
import io.github.digitalsmile.gpio.libcurl.enums.CURLcode;
13-
import io.github.digitalsmile.gpio.libcurl.enums.CURLoption;
14-
import io.github.digitalsmile.gpio.libcurl.opaque.CURL;
12+
import io.github.digitalsmile.gpio.libcurl.enums.CURLCode;
13+
import io.github.digitalsmile.gpio.libcurl.enums.CURLOption;
14+
import io.github.digitalsmile.gpio.libcurl.opaque.CurlInstance;
1515

1616
@NativeMemory(headers = "libcurl/curl/include/curl/curl.h")
1717
@NativeMemoryOptions(systemIncludes = {
@@ -27,17 +27,17 @@
2727
public interface Libcurl {
2828

2929
@NativeManualFunction(name = "curl_easy_init", library = "/usr/lib/x86_64-linux-gnu/libcurl.so")
30-
CURL easyInit() throws NativeMemoryException;
30+
CurlInstance easyInit() throws NativeMemoryException;
3131

3232
@NativeManualFunction(name = "curl_global_init", library = "/usr/lib/x86_64-linux-gnu/libcurl.so")
33-
CURLcode globalInit(long flags) throws NativeMemoryException;
33+
CURLCode globalInit(long flags) throws NativeMemoryException;
3434

3535
@NativeManualFunction(name = "curl_easy_setopt", library = "/usr/lib/x86_64-linux-gnu/libcurl.so")
36-
CURLcode easySetOpt(CURL curl, CURLoption option, String value) throws NativeMemoryException;
36+
CURLCode easySetOpt(CurlInstance curl, CURLOption option, String value) throws NativeMemoryException;
3737

3838
@NativeManualFunction(name = "curl_easy_setopt", library = "/usr/lib/x86_64-linux-gnu/libcurl.so")
39-
CURLcode easySetOpt(CURL curl, CURLoption option, @ByAddress long value) throws NativeMemoryException;
39+
CURLCode easySetOpt(CurlInstance curl, CURLOption option, @ByAddress long value) throws NativeMemoryException;
4040

4141
@NativeManualFunction(name = "curl_easy_perform", library = "/usr/lib/x86_64-linux-gnu/libcurl.so")
42-
CURLcode easyPerform(CURL curl) throws NativeMemoryException;
42+
CURLCode easyPerform(CurlInstance curl) throws NativeMemoryException;
4343
}
Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,27 @@
11
package io.github.digitalsmile.gpio.libcurl;
22

33
import io.github.digitalsmile.annotation.NativeMemoryException;
4-
import io.github.digitalsmile.gpio.libcurl.enums.CURLcode;
5-
import io.github.digitalsmile.gpio.libcurl.enums.CURLoption;
4+
import io.github.digitalsmile.gpio.libcurl.enums.CURLCode;
5+
import io.github.digitalsmile.gpio.libcurl.enums.CURLOption;
66
import org.junit.jupiter.api.Test;
77

88
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
910
public class LibcurlTest {
1011

1112
@Test
1213
public void libcurl() throws NativeMemoryException {
13-
try(var libcurl = new LibcurlNative()) {
14-
var code = libcurl.globalInit(CurlConstants.CURL_GLOBAL_DEFAULT);
15-
assertEquals(code, CURLcode.CURLE_OK);
16-
var curl = libcurl.easyInit();
17-
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_URL, "https://example.com");
18-
assertEquals(code, CURLcode.CURLE_OK);
19-
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_FOLLOWLOCATION, 1L);
20-
assertEquals(code, CURLcode.CURLE_OK);
21-
22-
code = libcurl.easyPerform(curl);
23-
assertEquals(code, CURLcode.CURLE_OK);
24-
}
25-
}
26-
27-
public static void main(String[] args) throws NativeMemoryException {
28-
try(var libcurl = new LibcurlNative()) {
14+
try (var libcurl = new LibcurlNative()) {
2915
var code = libcurl.globalInit(CurlConstants.CURL_GLOBAL_DEFAULT);
30-
assertEquals(code, CURLcode.CURLE_OK);
16+
assertEquals(code, CURLCode.CURLE_OK);
3117
var curl = libcurl.easyInit();
32-
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_URL, "https://example.com");
33-
assertEquals(code, CURLcode.CURLE_OK);
34-
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_FOLLOWLOCATION, 1L);
35-
assertEquals(code, CURLcode.CURLE_OK);
18+
code = libcurl.easySetOpt(curl, CURLOption.CURLOPT_URL, "https://example.com");
19+
assertEquals(code, CURLCode.CURLE_OK);
20+
code = libcurl.easySetOpt(curl, CURLOption.CURLOPT_FOLLOWLOCATION, 1L);
21+
assertEquals(code, CURLCode.CURLE_OK);
3622

3723
code = libcurl.easyPerform(curl);
38-
assertEquals(code, CURLcode.CURLE_OK);
24+
assertEquals(code, CURLCode.CURLE_OK);
3925
}
4026
}
4127
}

annotation-processor-test/src/test/java/io/github/digitalsmile/gpio/shared/SharedTestTwo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@NativeMemory(headers = "/usr/include/x86_64-linux-gnu/sys/stat.h")
1313
@NativeMemoryOptions(systemHeader = true)
1414
@Structs(
15-
@Struct(name = "stat")
15+
@Struct(name = "stat", javaName = "Stat")
1616
)
1717
public interface SharedTestTwo {
1818

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.github.digitalsmile.gpio.types.custom;
2+
3+
import io.github.digitalsmile.annotation.NativeMemory;
4+
import io.github.digitalsmile.annotation.NativeMemoryOptions;
5+
import io.github.digitalsmile.annotation.structure.Enums;
6+
import io.github.digitalsmile.annotation.structure.Struct;
7+
import io.github.digitalsmile.annotation.structure.Structs;
8+
import io.github.digitalsmile.annotation.structure.Unions;
9+
10+
@NativeMemory(headers = "/usr/src/linux-headers-${version}/include/uapi/linux/gpio.h")
11+
@NativeMemoryOptions(
12+
processRootConstants = true
13+
)
14+
@Structs({
15+
@Struct(name = "gpiochip_info", javaName = "ChipInfo"),
16+
@Struct(name = "gpio_v2_line_attribute", javaName = "LineAttribute"),
17+
@Struct(name = "gpio_v2_line_config", javaName = "LineConfig"),
18+
@Struct(name = "gpio_v2_line_config_attribute", javaName = "LineConfigAttribute"),
19+
@Struct(name = "gpio_v2_line_event", javaName = "LineEvent"),
20+
@Struct(name = "gpio_v2_line_info", javaName = "LineInfo"),
21+
@Struct(name = "gpio_v2_line_request", javaName = "LineRequest"),
22+
@Struct(name = "gpio_v2_line_values", javaName = "LineValues")
23+
})
24+
@Enums
25+
@Unions
26+
public interface GPIOTest {
27+
}

annotation-processor/src/main/java/io/github/digitalsmile/NativeProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,17 @@ private List<NativeMemoryNode> processHeaderFiles(Element element, String[] head
112112
List<Type> structs = null;
113113
if (structsAnnotation != null) {
114114
structs = Arrays.stream(structsAnnotation.value()).map(struct -> new Type(struct.name(), struct.javaName())).toList();
115+
Arrays.stream(structsAnnotation.value()).forEach(struct -> PrettyName.addName(struct.name(), struct.javaName()));
115116
}
116117
List<Type> enums = null;
117118
if (enumsAnnotation != null) {
118119
enums = Arrays.stream(enumsAnnotation.value()).map(enoom -> new Type(enoom.name(), enoom.javaName())).toList();
120+
Arrays.stream(enumsAnnotation.value()).forEach(enoom -> PrettyName.addName(enoom.name(), enoom.javaName()));
119121
}
120122
List<Type> unions = null;
121123
if (unionsAnnotation != null) {
122124
unions = Arrays.stream(unionsAnnotation.value()).map(union -> new Type(union.name(), union.javaName())).toList();
125+
Arrays.stream(unionsAnnotation.value()).forEach(union -> PrettyName.addName(union.name(), union.javaName()));
123126
}
124127

125128
var rootConstants = false;

annotation-processor/src/main/java/io/github/digitalsmile/PrettyName.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void addName(String name, String javaName) {
1515
public static String getVariableName(String name) {
1616
var cachedName = NAMING_CACHE.get(name);
1717
if (cachedName != null) {
18-
return cachedName;
18+
name = cachedName;
1919
}
2020
name = checkJavaName(name);
2121
if (name.matches("([a-z]+[a-zA-Z0-9]+)+")) {
@@ -38,7 +38,7 @@ public static String getVariableName(String name) {
3838
public static String getObjectName(String name) {
3939
var cachedName = NAMING_CACHE.get(name);
4040
if (cachedName != null) {
41-
return cachedName;
41+
name = cachedName;
4242
}
4343
name = checkJavaName(name);
4444
if (name.matches("([A-Z]+[a-zA-Z0-9]+)+")) {

annotation-processor/src/main/java/io/github/digitalsmile/composers/ContextComposer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.squareup.javapoet.*;
44
import io.github.digitalsmile.PackageName;
5+
import io.github.digitalsmile.PrettyName;
56
import io.github.digitalsmile.annotation.ArenaType;
67
import io.github.digitalsmile.annotation.function.NativeCall;
78
import io.github.digitalsmile.annotation.types.interfaces.NativeMemoryContext;
@@ -88,7 +89,7 @@ public String compose(String packageName, String javaName, Map<Library, List<Fun
8889
parameters.add(CodeBlock.builder().add("$T.ADDRESS", ValueLayout.class).build());
8990
} else if (node.getNodeType().isEnum()) {
9091
var parameterPackageName = PackageName.getPackageName(type.typeName());
91-
var typeName = ClassName.get(parameterPackageName, type.typeName());
92+
var typeName = ClassName.get(parameterPackageName, PrettyName.getObjectName(type.typeName()));
9293
parameters.add(CodeBlock.builder().add("$T.LAYOUT", typeName).build());
9394
} else {
9495
parameters.add(CodeBlock.builder().add("$T.$L", ValueLayout.class, type.valueLayoutName()).build());

annotation-processor/src/main/java/io/github/digitalsmile/headers/model/NativeMemoryNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.util.ArrayList;
88
import java.util.List;
9+
import java.util.Objects;
910

1011
public class NativeMemoryNode implements Node {
1112
private final String name;

0 commit comments

Comments
 (0)