Skip to content

Commit 984df11

Browse files
committed
x
1 parent 399fae6 commit 984df11

5 files changed

Lines changed: 343 additions & 90 deletions

File tree

documentation/idl_codegen.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ The generator supports per-method and per-service options in `arduino_opts.proto
2323

2424
`idl/CMakeLists.txt` already invokes the plugin and emits headers into the build tree.
2525

26-
Typical generated header names:
26+
Typical generated header names (per service):
2727

28-
1. `print_ifc.hpp`
29-
2. `stream_ifc.hpp`
30-
3. `hardware_i2c_ifc.hpp`
28+
1. `*_ifc.hpp`
29+
2. `*_api.hpp`
30+
3. `*_service.hpp`
31+
4. `*_service_impl.hpp`
3132

3233
## Method Options
3334

@@ -39,6 +40,7 @@ Defined in `idl/proto/arduino_opts.proto` as `google.protobuf.MethodOptions` ext
3940
4. `source_virtual`
4041
5. `emit_api`
4142
6. `emit_service`
43+
7. `method_visibility`
4244

4345
### Meaning
4446

@@ -50,6 +52,8 @@ Defined in `idl/proto/arduino_opts.proto` as `google.protobuf.MethodOptions` ext
5052
Whether this method is emitted to generated `Api`.
5153
4. `emit_service`
5254
Whether this method is emitted to generated `Service`.
55+
5. `method_visibility`
56+
Access specifier for generated methods. Supported values: `public`, `protected`, `private` (default: `public`).
5357

5458
## Service Options
5559

@@ -64,6 +68,7 @@ Defined as `google.protobuf.ServiceOptions` extensions:
6468
7. `service_class_name`
6569
8. `service_impl_class_name`
6670
9. `api_member_name`
71+
10. `base_services`
6772

6873
### Meaning
6974

@@ -79,6 +84,8 @@ Defined as `google.protobuf.ServiceOptions` extensions:
7984
Override generated class names.
8085
6. `api_member_name`
8186
Override delegate member name in `ServiceImpl` (default: `api_`).
87+
7. `base_services`
88+
Parent services to inherit from. You can specify a same-package short name (for example `Print`) or a fully-qualified name (for example `arduino.idl.Print` or `.arduino.idl.Print`).
8289

8390
## Recommended Mapping
8491

@@ -101,6 +108,7 @@ The generator intentionally fails when configuration is inconsistent:
101108
2. `generate_service_impl_class = true` requires `generate_service_class = true`
102109
3. `generate_api_class = true` rejects methods with `emit_api = true` and `source_virtual = false`
103110
4. `generate_service_impl_class = true` with `generate_api_class = true` requires all `Service` methods to be callable on generated `Api`
111+
5. Cyclic `base_services` references are rejected
104112

105113
## Example
106114

@@ -122,12 +130,14 @@ service Demo {
122130
option (arduino.service_class_name) = "DemoServiceCustom";
123131
option (arduino.service_impl_class_name) = "DemoServiceImplCustom";
124132
option (arduino.api_member_name) = "delegate_";
133+
option (arduino.base_services) = "Print";
125134
126135
rpc Read(google.protobuf.Empty) returns (google.protobuf.Empty) {
127136
option (arduino.cpp_decl) = "int read()";
128137
option (arduino.source_virtual) = true;
129138
option (arduino.emit_api) = true;
130139
option (arduino.emit_service) = true;
140+
option (arduino.method_visibility) = "public";
131141
}
132142
}
133143
```

idl/proto/arduino_opts.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extend google.protobuf.MethodOptions {
2222
bool source_virtual = 50111;
2323
bool emit_api = 50112;
2424
bool emit_service = 50113;
25+
string method_visibility = 50114;
2526
}
2627

2728
extend google.protobuf.ServiceOptions {
@@ -34,4 +35,5 @@ extend google.protobuf.ServiceOptions {
3435
string service_class_name = 50213;
3536
string service_impl_class_name = 50214;
3637
string api_member_name = 50215;
38+
repeated string base_services = 50216;
3739
}

idl/proto/hardware_serial.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import "google/protobuf/empty.proto";
1313
import "google/protobuf/wrappers.proto";
1414

1515
service HardwareSerial {
16+
option (arduino.base_services) = "Stream";
17+
option (arduino.generate_ifc_class) = true;
18+
option (arduino.generate_service_class) = true;
19+
option (arduino.generate_service_impl_class) = true;
20+
option (arduino.api_class_name) = "arduino::HardwareSerial";
21+
1622
rpc BeginBaud(google.protobuf.UInt64Value) returns (google.protobuf.Empty) {
1723
option (arduino.cpp_decl) = "void begin(unsigned long baudrate)";
1824
}

idl/proto/stream.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import "google/protobuf/empty.proto";
1313
import "google/protobuf/wrappers.proto";
1414

1515
service Stream {
16+
option (arduino.base_services) = "Print";
17+
1618
rpc Available(google.protobuf.Empty) returns (google.protobuf.Int32Value) {
1719
option (arduino.cpp_decl) = "int available()";
1820
}

0 commit comments

Comments
 (0)