-
Notifications
You must be signed in to change notification settings - Fork 89
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
RSA, Polyglot and Descriptor Generation #590
Comments
The aim of descriptor generation for remote services is to make service header file the single source of truth. I tried the following prototype and believe it could work: //calculator_service.h
#ifndef CALCULATOR_SERVICE_H_
#define CALCULATOR_SERVICE_H_
#define CALCULATOR_SERVICE "org.apache.celix.calc.api.Calculator"
#define CALCULATOR_SERVICE_VERSION "1.3.0"
#define CALCULATOR_CONFIGURATION_TYPE "org.amdatu.remote.admin.http, celix.remote.admin.shm"
/*
* The calculator service definition corresponds to the following Java interface:
*
* interface Calculator {
* double add(double a, double b);
* double sub(double a, double b);
* double sqrt(double a);
* }
*/
typedef struct [[clang::annotate("celix::services", CALCULATOR_SERVICE, CALCULATOR_SERVICE_VERSION)]] calculator_service {
void *handle;
int (*add)(void *handle, double a, double b, double *[[clang::annotate_type("celix::pre")]] result);
int (*sub)(void *handle, double a, double b, double *[[clang::annotate_type("celix::pre")]] result);
int (*sqrt)(void *handle, double a, double * [[clang::annotate_type("celix::pre")]] result);
} calculator_service_t;
#endif /* CALCULATOR_SERVICE_H_ */ // calculator_service.c
#include "calculator_service.h" Note that $ clang-15 -Xclang -ast-dump -fsyntax-only -std=c2x calculator_service.c
TranslationUnitDecl 0x559464320ec8 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x5594643216f0 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
| `-BuiltinType 0x559464321490 '__int128'
|-TypedefDecl 0x559464321760 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
| `-BuiltinType 0x5594643214b0 'unsigned __int128'
|-TypedefDecl 0x559464321a68 <<invalid sloc>> <invalid sloc> implicit __NSConstantString 'struct __NSConstantString_tag'
| `-RecordType 0x559464321840 'struct __NSConstantString_tag'
| `-Record 0x5594643217b8 '__NSConstantString_tag'
|-TypedefDecl 0x559464321b00 <<invalid sloc>> <invalid sloc> implicit __builtin_ms_va_list 'char *'
| `-PointerType 0x559464321ac0 'char *'
| `-BuiltinType 0x559464320f70 'char'
|-TypedefDecl 0x559464321df8 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list 'struct __va_list_tag[1]'
| `-ConstantArrayType 0x559464321da0 'struct __va_list_tag[1]' 1
| `-RecordType 0x559464321be0 'struct __va_list_tag'
| `-Record 0x559464321b58 '__va_list_tag'
|-RecordDecl 0x55946437c3a8 <./calculator_service.h:36:9, line:41:1> line:36:103 struct calculator_service definition
| |-AnnotateAttr 0x55946437c450 <col:18, col:99> "celix::services"
| | |-ConstantExpr 0x55946437c500 <line:23:41> 'char (*)[37]'
| | | |-value: LValue <todo>
| | | `-ImplicitCastExpr 0x55946437c4e8 <col:41> 'char (*)[37]' <ArrayToPointerDecay>
| | | `-StringLiteral 0x55946437c308 <col:41> 'char[37]' lvalue "org.apache.celix.calc.api.Calculator"
| | `-ConstantExpr 0x55946437c5a0 <line:24:41> 'char (*)[6]'
| | |-value: LValue <todo>
| | `-ImplicitCastExpr 0x55946437c588 <col:41> 'char (*)[6]' <ArrayToPointerDecay>
| | `-StringLiteral 0x55946437c388 <col:41> 'char[6]' lvalue "1.3.0"
| |-FieldDecl 0x55946437c648 <line:37:5, col:11> col:11 handle 'void *'
| |-FieldDecl 0x55946437cb50 <line:38:5, col:103> col:11 add 'int (*)(void *, double, double, double * [[clang::annotate_type(...)]])'
| |-FieldDecl 0x55946437ce90 <line:39:5, col:103> col:11 sub 'int (*)(void *, double, double, double * [[clang::annotate_type(...)]])'
| `-FieldDecl 0x55946437d258 <line:40:5, col:95> col:11 sqrt 'int (*)(void *, double, double * [[clang::annotate_type(...)]])'
`-TypedefDecl 0x559464383368 <line:36:1, line:41:3> col:3 calculator_service_t 'struct calculator_service':'struct calculator_service'
`-ElaboratedType 0x559464383310 'struct calculator_service' sugar
`-RecordType 0x55946437c430 'struct calculator_service'
`-Record 0x55946437c3a8 'calculator_service'
We need
Another downside of using
I'm still in prototyping phase. All comments are welcome. @pnoltes @xuzhenbao |
For our RSA to be more successful, we should generate descriptor from the more readable header file automatically and make RSA available to other languaes like javascript and Java. Of course these should belong to another extended discussion.
Originally posted by @PengZheng in #544 (comment)
Indeed the future or RSA, polyglot and descriptor gen is more a future discussion.
Note that I did some - small - experimentation with libclang to parse remote service header and generate descriptors.
So I think this is feasible, but requires effort. And then maybe use something like python pycparser.
Originally posted by @pnoltes in #544 (comment)
The text was updated successfully, but these errors were encountered: