You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@celix.apache.org by Pepijn Noltes <pe...@gmail.com> on 2020/05/14 08:12:23 UTC
Re: Structs to Java
Hi Brian,
The $ char is not allowed in a descriptor. I expect you need this
because of Java inner classes.
I created an issue for this (#223)
I also cheated a bit and put your example through our companies code
gen, maybe this helps in getting everything to work.
Results:
//RemoteExample.avdl
@version("1.0.0")
@namespace("org.apache.celix")
protocol RemoteExample {
record ComplexInputExample2 {
double a;
double b;
int n;
string name;
}
record ComplexOutputExample2 {
double pow;
int fib;
string name;
}
ComplexOutputExample2 setComplex2(ComplexInputExample2 exmpl);
}
//org/apache/celix/ComplexInputExample2.h
/* WARNING GENERATED CODE. DO NOT EDIT */
#ifndef ORG_APACHE_CELIX_COMPLEXINPUTEXAMPLE2_H_
#define ORG_APACHE_CELIX_COMPLEXINPUTEXAMPLE2_H_
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
/*============================================================================
Includes - Based on avro idl imports
============================================================================*/
/*============================================================================
Type and Version defines
============================================================================*/
#define ORG_APACHE_CELIX_COMPLEXINPUTEXAMPLE2_TYPE
"org.apache.celix.ComplexInputExample2"
#define ORG_APACHE_CELIX_COMPLEXINPUTEXAMPLE2_VERSION "1.0.0"
#define ORG_APACHE_CELIX_COMPLEXINPUTEXAMPLE2_VERSION_MAJOR "1"
#define ORG_APACHE_CELIX_COMPLEXINPUTEXAMPLE2_VERSION_MINOR "0"
#define ORG_APACHE_CELIX_COMPLEXINPUTEXAMPLE2_VERSION_MICRO "0"
#define ORG_APACHE_CELIX_COMPLEXINPUTEXAMPLE2_VERSION_QUALIFIER ""
typedef struct org_apache_celix_ComplexInputExample2_struct
org_apache_celix_ComplexInputExample2_t;
struct org_apache_celix_ComplexInputExample2_struct {
double a;
double b;
int32_t n;
char* name;
};
#endif // ORG_APACHE_CELIX_COMPLEXINPUTEXAMPLE2_H_
//org/apache/celix/CompexOutputExampl2.h
/* WARNING GENERATED CODE. DO NOT EDIT */
#ifndef ORG_APACHE_CELIX_COMPLEXOUTPUTEXAMPLE2_H_
#define ORG_APACHE_CELIX_COMPLEXOUTPUTEXAMPLE2_H_
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
/*============================================================================
Includes - Based on avro idl imports
============================================================================*/
/*============================================================================
Type and Version defines
============================================================================*/
#define ORG_APACHE_CELIX_COMPLEXOUTPUTEXAMPLE2_TYPE
"org.apache.celix.ComplexOutputExample2"
#define ORG_APACHE_CELIX_COMPLEXOUTPUTEXAMPLE2_VERSION "1.0.0"
#define ORG_APACHE_CELIX_COMPLEXOUTPUTEXAMPLE2_VERSION_MAJOR "1"
#define ORG_APACHE_CELIX_COMPLEXOUTPUTEXAMPLE2_VERSION_MINOR "0"
#define ORG_APACHE_CELIX_COMPLEXOUTPUTEXAMPLE2_VERSION_MICRO "0"
#define ORG_APACHE_CELIX_COMPLEXOUTPUTEXAMPLE2_VERSION_QUALIFIER ""
/*============================================================================
Type
============================================================================*/
typedef struct org_apache_celix_ComplexOutputExample2_struct
org_apache_celix_ComplexOutputExample2_t;
struct org_apache_celix_ComplexOutputExample2_struct {
double pow;
int32_t fib;
char* name;
};
#endif // ORG_APACHE_CELIX_COMPLEXOUTPUTEXAMPLE2_H_
//org/apache/celix/RemoteExample.h
/* WARNING GENERATED CODE. DO NOT EDIT */
#ifndef ORG_APACHE_CELIX_REMOTEEXAMPLE_H_
#define ORG_APACHE_CELIX_REMOTEEXAMPLE_H_
#include <stdio.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/*============================================================================
Includes - Based on avro idl imports
============================================================================*/
#include "org/apache/celix/ComplexInputExample2.h"
#include "org/apache/celix/ComplexOutputExample2.h"
#ifdef __cplusplus
extern "C" {
#endif
/*============================================================================
Service - Service org_apache_celix_RemoteExample_t
============================================================================*/
#define ORG_APACHE_CELIX_REMOTEEXAMPLE_SERVICE_NAME
"org.apache.celix.RemoteExample"
#define ORG_APACHE_CELIX_REMOTEEXAMPLE_SERVICE_VERSION "1.0.0"
typedef struct org_apache_celix_RemoteExample_struct {
void* handle;
int (*setComplex2)(void* handle,
org_apache_celix_ComplexInputExample2_t* exmpl,
org_apache_celix_ComplexOutputExample2_t** out);
} org_apache_celix_RemoteExample_t;
#ifdef __cplusplus
}
#endif
#endif // ORG_APACHE_CELIX_REMOTEEXAMPLE_H_
//org.example.apache.RemoteExample.descriptor
:header
type=interface
name=org.apache.celix.RemoteExample
version=1.0.0
:annotations
avroFqn=org.apache.celix.RemoteExample
:types
org_apache_celix_ComplexInputExample2={DDIt a b n name}
org_apache_celix_ComplexOutputExample2={DIt pow fib name}
:methods
setComplex2(Lorg/apache/celix/ComplexInputExample2;)Lorg/apache/celix/ComplexOutputExample2;=setComplex2(#am=handle;PLorg_apache_celix_ComplexInputExample2;#am=out;*Lorg_apache_celix_ComplexOutputExample2;)N
//org/apache/celix/ComplexInputExample2.java
package org.apache.celix;
import java.util.Objects;
public final class ComplexInputExample2 {
public static final String $NAME$ = "ComplexInputExample2";
public static final String $VERSION$ = "1.0.0";
private final double a;
private final double b;
private final int n;
private final String name;
/**
* Empty constructor for serialization
*/
private ComplexInputExample2() {
this.a = 0.0d;
this.b = 0.0d;
this.n = 0;
this.name = null;
}
/**
* Constructor using Builder
*/
private ComplexInputExample2(Builder builder) {
this.a = builder.a;
this.b = builder.b;
this.n = builder.n;
this.name = builder.name;
}
public double getA() {
return a;
}
public double getB() {
return b;
}
public int getN() {
return n;
}
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ComplexInputExample2 instance = (ComplexInputExample2) o;
return Objects.equals(a, instance.a) &&
Objects.equals(b, instance.b) &&
Objects.equals(n, instance.n) &&
Objects.equals(name, instance.name);
}
@Override
public int hashCode() {
return Objects.hash(a, b, n, name);
}
@Override
public String toString() {
return "MyClass{" +
"a=" + a +
", b=" + b +
", n=" + n +
", name=" + name +
'}';
}
/**
* Builder to construct ComplexInputExample2
*/
public static final class Builder {
private double a;
private boolean a$et = false;
private double b;
private boolean b$et = false;
private int n;
private boolean n$et = false;
private String name;
private boolean name$et = false;
public Builder() {
// Default empty constructor
}
public Builder(double a, double b, int n, String name) {
this.a = a;
this.a$et = true;
this.b = b;
this.b$et = true;
this.n = n;
this.n$et = true;
this.name = name;
this.name$et = true;
}
public Builder withA(double a) {
this.a = a;
this.a$et = true;
return this;
}
public Builder withB(double b) {
this.b = b;
this.b$et = true;
return this;
}
public Builder withN(int n) {
this.n = n;
this.n$et = true;
return this;
}
public Builder withName(String name) {
this.name = name;
this.name$et = true;
return this;
}
public void validate() {
// Validate fields set
if (!a$et) { throw new IllegalStateException("Field a is
not set"); }
if (!b$et) { throw new IllegalStateException("Field b is
not set"); }
if (!n$et) { throw new IllegalStateException("Field n is
not set"); }
if (!name$et) { throw new IllegalStateException("Field
name is not set"); }
}
public ComplexInputExample2 build() {
validate();
return new ComplexInputExample2(this);
}
}
}
//org/apache/celix/ComplexOutputExample2.java
package org.apache.celix;
import java.util.Objects;
public final class ComplexOutputExample2 {
public static final String $NAME$ = "ComplexOutputExample2";
public static final String $VERSION$ = "1.0.0";
private final double pow;
private final int fib;
private final String name;
/**
* Empty constructor for serialization
*/
private ComplexOutputExample2() {
this.pow = 0.0d;
this.fib = 0;
this.name = null;
}
/**
* Constructor using Builder
*/
private ComplexOutputExample2(Builder builder) {
this.pow = builder.pow;
this.fib = builder.fib;
this.name = builder.name;
}
public double getPow() {
return pow;
}
public int getFib() {
return fib;
}
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ComplexOutputExample2 instance = (ComplexOutputExample2) o;
return Objects.equals(pow, instance.pow) &&
Objects.equals(fib, instance.fib) &&
Objects.equals(name, instance.name);
}
@Override
public int hashCode() {
return Objects.hash(pow, fib, name);
}
@Override
public String toString() {
return "MyClass{" +
"pow=" + pow +
", fib=" + fib +
", name=" + name +
'}';
}
/**
* Builder to construct ComplexOutputExample2
*/
public static final class Builder {
private double pow;
private boolean pow$et = false;
private int fib;
private boolean fib$et = false;
private String name;
private boolean name$et = false;
public Builder() {
// Default empty constructor
}
public Builder(double pow, int fib, String name) {
this.pow = pow;
this.pow$et = true;
this.fib = fib;
this.fib$et = true;
this.name = name;
this.name$et = true;
}
public Builder withPow(double pow) {
this.pow = pow;
this.pow$et = true;
return this;
}
public Builder withFib(int fib) {
this.fib = fib;
this.fib$et = true;
return this;
}
public Builder withName(String name) {
this.name = name;
this.name$et = true;
return this;
}
public void validate() {
// Validate fields set
if (!pow$et) { throw new IllegalStateException("Field pow
is not set"); }
if (!fib$et) { throw new IllegalStateException("Field fib
is not set"); }
if (!name$et) { throw new IllegalStateException("Field
name is not set"); }
}
public ComplexOutputExample2 build() {
validate();
return new ComplexOutputExample2(this);
}
}
}
//org/example/celix/RemoteExample.java package org.apache.celix;
public interface RemoteExample {
public static final String $NAME$ = "RemoteExample";
public static final String $VERSION$ = "1.0.0";
ComplexOutputExample2 setComplex2(ComplexInputExample2 exmpl);
}
Greetings,
Pepijn
On Wed, May 13, 2020 at 10:09 PM Brian Michael <br...@gmail.com> wrote:
>
> Hello,
>
> I was looking to get some assistance in passing a struct to Java via the RSA. I get that you need to setup a class on the java end to mimic your C struct but I can’t seem to get the descriptor file to work with what I’ve got.
>
> Java Interface is named RemoteExample inside package org.apache.celix
>
> class complex_input_example2 {
> public double a;
> public double b;
> public int n;
> public String name;
> }
>
> class complex_output_example2 {
> public double pow;
> public int fib;
> public String name;
> }
>
> complex_output_example2 setComplex2(complex_input_example2 exmpl);
>
> In C I have:
>
> struct complex_input_example2 {
> double a;
> double b;
> int32_t n;
> char* name;
> };
>
> struct complex_output_example2 {
> double pow;
> int32_t fib;
> char* name;
> };
>
> struct remote_example {
> void* handle;
> int (*setComplex2)(void* handle, complex_input_example2* exmpl,
> complex_output_example2 **out);
> };
>
>
> //Example.descriptor
> :header
> type=interface
> name=org.apache.celix.RemoteExample
> version=1.0.0
> :annotations
> classname=org.apache.celix.RemoteExample
> :types
> complex_input_example2={DDNt a bn name}
> complex_output_example2={DNt pow fib name}
> :methods
> setComplex2(Lorg/apache/celix/RemoteExample.complex_input_example2;)Lorg/apache/celix/RemoteExample.complex_output_example2;=setComplex2(#am=handle;PLcomplex_input_example2;#am=out;*Lcomplex_output_example2;)N
>
> Debugging out what the descriptor wants seems to yield:
> setComplex2(Lorg/apache/celix/RemoteExample$complex_input_example2;)Lorg/apache/celixRemoteExample$complex_output_example2;
>
> Error says “Cannot find method with sig” the above string. However if I put the $ in the descriptor then it just errors out and won’t load the descriptor.
>
> Thanks,
> Brian
>
> Sent from my iPhone
>
>
> Sent from my iPhone