Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken file name mapping fix #15

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package io.github.digitalsmile.gpio.libcurl;

import io.github.digitalsmile.annotation.NativeMemory;
import io.github.digitalsmile.annotation.NativeMemoryException;
import io.github.digitalsmile.annotation.NativeMemoryOptions;
import io.github.digitalsmile.annotation.function.ByAddress;
import io.github.digitalsmile.annotation.function.NativeManualFunction;
import io.github.digitalsmile.annotation.NativeMemoryException;
import io.github.digitalsmile.annotation.structure.Enum;
import io.github.digitalsmile.annotation.structure.Enums;
import io.github.digitalsmile.annotation.structure.Struct;
import io.github.digitalsmile.annotation.structure.Structs;
import io.github.digitalsmile.gpio.libcurl.enums.CURLcode;
import io.github.digitalsmile.gpio.libcurl.enums.CURLoption;
import io.github.digitalsmile.gpio.libcurl.opaque.CURL;
import io.github.digitalsmile.gpio.libcurl.enums.CURLCode;
import io.github.digitalsmile.gpio.libcurl.enums.CURLOption;
import io.github.digitalsmile.gpio.libcurl.opaque.CurlInstance;

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

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

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

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

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

@NativeManualFunction(name = "curl_easy_perform", library = "/usr/lib/x86_64-linux-gnu/libcurl.so")
CURLcode easyPerform(CURL curl) throws NativeMemoryException;
CURLCode easyPerform(CurlInstance curl) throws NativeMemoryException;
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
package io.github.digitalsmile.gpio.libcurl;

import io.github.digitalsmile.annotation.NativeMemoryException;
import io.github.digitalsmile.gpio.libcurl.enums.CURLcode;
import io.github.digitalsmile.gpio.libcurl.enums.CURLoption;
import io.github.digitalsmile.gpio.libcurl.enums.CURLCode;
import io.github.digitalsmile.gpio.libcurl.enums.CURLOption;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class LibcurlTest {

@Test
public void libcurl() throws NativeMemoryException {
try(var libcurl = new LibcurlNative()) {
var code = libcurl.globalInit(CurlConstants.CURL_GLOBAL_DEFAULT);
assertEquals(code, CURLcode.CURLE_OK);
var curl = libcurl.easyInit();
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_URL, "https://example.com");
assertEquals(code, CURLcode.CURLE_OK);
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_FOLLOWLOCATION, 1L);
assertEquals(code, CURLcode.CURLE_OK);

code = libcurl.easyPerform(curl);
assertEquals(code, CURLcode.CURLE_OK);
}
}

public static void main(String[] args) throws NativeMemoryException {
try(var libcurl = new LibcurlNative()) {
try (var libcurl = new LibcurlNative()) {
var code = libcurl.globalInit(CurlConstants.CURL_GLOBAL_DEFAULT);
assertEquals(code, CURLcode.CURLE_OK);
assertEquals(code, CURLCode.CURLE_OK);
var curl = libcurl.easyInit();
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_URL, "https://example.com");
assertEquals(code, CURLcode.CURLE_OK);
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_FOLLOWLOCATION, 1L);
assertEquals(code, CURLcode.CURLE_OK);
code = libcurl.easySetOpt(curl, CURLOption.CURLOPT_URL, "https://example.com");
assertEquals(code, CURLCode.CURLE_OK);
code = libcurl.easySetOpt(curl, CURLOption.CURLOPT_FOLLOWLOCATION, 1L);
assertEquals(code, CURLCode.CURLE_OK);

code = libcurl.easyPerform(curl);
assertEquals(code, CURLcode.CURLE_OK);
assertEquals(code, CURLCode.CURLE_OK);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@NativeMemory(headers = "/usr/include/x86_64-linux-gnu/sys/stat.h")
@NativeMemoryOptions(systemHeader = true)
@Structs(
@Struct(name = "stat")
@Struct(name = "stat", javaName = "Stat")
)
public interface SharedTestTwo {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.digitalsmile.gpio.types.custom;

import io.github.digitalsmile.annotation.NativeMemory;
import io.github.digitalsmile.annotation.NativeMemoryOptions;
import io.github.digitalsmile.annotation.structure.Enums;
import io.github.digitalsmile.annotation.structure.Struct;
import io.github.digitalsmile.annotation.structure.Structs;
import io.github.digitalsmile.annotation.structure.Unions;

@NativeMemory(headers = "/usr/src/linux-headers-${version}/include/uapi/linux/gpio.h")
@NativeMemoryOptions(
processRootConstants = true
)
@Structs({
@Struct(name = "gpiochip_info", javaName = "ChipInfo"),
@Struct(name = "gpio_v2_line_attribute", javaName = "LineAttribute"),
@Struct(name = "gpio_v2_line_config", javaName = "LineConfig"),
@Struct(name = "gpio_v2_line_config_attribute", javaName = "LineConfigAttribute"),
@Struct(name = "gpio_v2_line_event", javaName = "LineEvent"),
@Struct(name = "gpio_v2_line_info", javaName = "LineInfo"),
@Struct(name = "gpio_v2_line_request", javaName = "LineRequest"),
@Struct(name = "gpio_v2_line_values", javaName = "LineValues")
})
@Enums
@Unions
public interface GPIOTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ private List<NativeMemoryNode> processHeaderFiles(Element element, String[] head
List<Type> structs = null;
if (structsAnnotation != null) {
structs = Arrays.stream(structsAnnotation.value()).map(struct -> new Type(struct.name(), struct.javaName())).toList();
Arrays.stream(structsAnnotation.value()).forEach(struct -> PrettyName.addName(struct.name(), struct.javaName()));
}
List<Type> enums = null;
if (enumsAnnotation != null) {
enums = Arrays.stream(enumsAnnotation.value()).map(enoom -> new Type(enoom.name(), enoom.javaName())).toList();
Arrays.stream(enumsAnnotation.value()).forEach(enoom -> PrettyName.addName(enoom.name(), enoom.javaName()));
}
List<Type> unions = null;
if (unionsAnnotation != null) {
unions = Arrays.stream(unionsAnnotation.value()).map(union -> new Type(union.name(), union.javaName())).toList();
Arrays.stream(unionsAnnotation.value()).forEach(union -> PrettyName.addName(union.name(), union.javaName()));
}

var rootConstants = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void addName(String name, String javaName) {
public static String getVariableName(String name) {
var cachedName = NAMING_CACHE.get(name);
if (cachedName != null) {
return cachedName;
name = cachedName;
}
name = checkJavaName(name);
if (name.matches("([a-z]+[a-zA-Z0-9]+)+")) {
Expand All @@ -38,7 +38,7 @@ public static String getVariableName(String name) {
public static String getObjectName(String name) {
var cachedName = NAMING_CACHE.get(name);
if (cachedName != null) {
return cachedName;
name = cachedName;
}
name = checkJavaName(name);
if (name.matches("([A-Z]+[a-zA-Z0-9]+)+")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.squareup.javapoet.*;
import io.github.digitalsmile.PackageName;
import io.github.digitalsmile.PrettyName;
import io.github.digitalsmile.annotation.ArenaType;
import io.github.digitalsmile.annotation.function.NativeCall;
import io.github.digitalsmile.annotation.types.interfaces.NativeMemoryContext;
Expand Down Expand Up @@ -88,7 +89,7 @@ public String compose(String packageName, String javaName, Map<Library, List<Fun
parameters.add(CodeBlock.builder().add("$T.ADDRESS", ValueLayout.class).build());
} else if (node.getNodeType().isEnum()) {
var parameterPackageName = PackageName.getPackageName(type.typeName());
var typeName = ClassName.get(parameterPackageName, type.typeName());
var typeName = ClassName.get(parameterPackageName, PrettyName.getObjectName(type.typeName()));
parameters.add(CodeBlock.builder().add("$T.LAYOUT", typeName).build());
} else {
parameters.add(CodeBlock.builder().add("$T.$L", ValueLayout.class, type.valueLayoutName()).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class NativeMemoryNode implements Node {
private final String name;
Expand Down
Loading