Skip to content

Commit 9d7f524

Browse files
Daniel Zahkakuba-moo
authored andcommitted
ynl-gen-cpp: generate code for notification handling
The code generator was not generating code to initialize ynl_ntf_info::alloc_sz() and ynl_ntf_info::free(). For type casting in and out of ynl_ntf_base_type, I had the code generator create structs in a similar way to the ynl-c repo. The code generator was already doing this but leaving them empty. In the free function, the C++ needs to be manually called before freeing the memory that was allocated with calloc() Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
1 parent 7b5c2ef commit 9d7f524

21 files changed

Lines changed: 524 additions & 4 deletions

generated/binder-user.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,18 @@ int binder_report_rsp_parse(const struct nlmsghdr *nlh,
127127
return YNL_PARSE_CB_OK;
128128
}
129129

130+
static void binder_report_free(struct ynl_ntf_base_type* ntf) {
131+
auto* typed_ntf = reinterpret_cast<binder_report*>(ntf);
132+
typed_ntf->obj.~binder_report_rsp();
133+
free(ntf);
134+
}
135+
130136
static constexpr std::array<ynl_ntf_info, BINDER_CMD_REPORT + 1> binder_ntf_info = []() {
131137
std::array<ynl_ntf_info, BINDER_CMD_REPORT + 1> arr{};
132138
arr[BINDER_CMD_REPORT].policy = &binder_report_nest;
133139
arr[BINDER_CMD_REPORT].cb = binder_report_rsp_parse;
140+
arr[BINDER_CMD_REPORT].alloc_sz = sizeof(binder_report);
141+
arr[BINDER_CMD_REPORT].free = binder_report_free;
134142
return arr;
135143
} ();
136144

generated/binder-user.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ struct binder_report_rsp {
4444
};
4545

4646
struct binder_report {
47+
__u16 family;
48+
__u8 cmd;
49+
struct ynl_ntf_base_type* next;
50+
void (*free)(struct ynl_ntf_base_type* ntf);
51+
binder_report_rsp obj __attribute__((aligned(8)));
4752
};
4853

4954
} //namespace ynl_cpp

generated/dpll-user.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,12 @@ dpll_device_get_dump(ynl_cpp::ynl_socket& ys)
756756
}
757757

758758
/* DPLL_CMD_DEVICE_GET - notify */
759+
static void dpll_device_get_ntf_free(struct ynl_ntf_base_type* ntf) {
760+
auto* typed_ntf = reinterpret_cast<dpll_device_get_ntf*>(ntf);
761+
typed_ntf->obj.~dpll_device_get_rsp();
762+
free(ntf);
763+
}
764+
759765
/* ============== DPLL_CMD_DEVICE_SET ============== */
760766
/* DPLL_CMD_DEVICE_SET - do */
761767
int dpll_device_set(ynl_cpp::ynl_socket& ys, dpll_device_set_req& req)
@@ -1118,6 +1124,12 @@ dpll_pin_get_dump(ynl_cpp::ynl_socket& ys, dpll_pin_get_req_dump& req)
11181124
}
11191125

11201126
/* DPLL_CMD_PIN_GET - notify */
1127+
static void dpll_pin_get_ntf_free(struct ynl_ntf_base_type* ntf) {
1128+
auto* typed_ntf = reinterpret_cast<dpll_pin_get_ntf*>(ntf);
1129+
typed_ntf->obj.~dpll_pin_get_rsp();
1130+
free(ntf);
1131+
}
1132+
11211133
/* ============== DPLL_CMD_PIN_SET ============== */
11221134
/* DPLL_CMD_PIN_SET - do */
11231135
int dpll_pin_set(ynl_cpp::ynl_socket& ys, dpll_pin_set_req& req)
@@ -1172,16 +1184,28 @@ static constexpr std::array<ynl_ntf_info, DPLL_CMD_PIN_CHANGE_NTF + 1> dpll_ntf_
11721184
std::array<ynl_ntf_info, DPLL_CMD_PIN_CHANGE_NTF + 1> arr{};
11731185
arr[DPLL_CMD_DEVICE_CREATE_NTF].policy = &dpll_nest;
11741186
arr[DPLL_CMD_DEVICE_CREATE_NTF].cb = dpll_device_get_rsp_parse;
1187+
arr[DPLL_CMD_DEVICE_CREATE_NTF].alloc_sz = sizeof(dpll_device_get_ntf);
1188+
arr[DPLL_CMD_DEVICE_CREATE_NTF].free = dpll_device_get_ntf_free;
11751189
arr[DPLL_CMD_DEVICE_DELETE_NTF].policy = &dpll_nest;
11761190
arr[DPLL_CMD_DEVICE_DELETE_NTF].cb = dpll_device_get_rsp_parse;
1191+
arr[DPLL_CMD_DEVICE_DELETE_NTF].alloc_sz = sizeof(dpll_device_get_ntf);
1192+
arr[DPLL_CMD_DEVICE_DELETE_NTF].free = dpll_device_get_ntf_free;
11771193
arr[DPLL_CMD_DEVICE_CHANGE_NTF].policy = &dpll_nest;
11781194
arr[DPLL_CMD_DEVICE_CHANGE_NTF].cb = dpll_device_get_rsp_parse;
1195+
arr[DPLL_CMD_DEVICE_CHANGE_NTF].alloc_sz = sizeof(dpll_device_get_ntf);
1196+
arr[DPLL_CMD_DEVICE_CHANGE_NTF].free = dpll_device_get_ntf_free;
11791197
arr[DPLL_CMD_PIN_CREATE_NTF].policy = &dpll_pin_nest;
11801198
arr[DPLL_CMD_PIN_CREATE_NTF].cb = dpll_pin_get_rsp_parse;
1199+
arr[DPLL_CMD_PIN_CREATE_NTF].alloc_sz = sizeof(dpll_pin_get_ntf);
1200+
arr[DPLL_CMD_PIN_CREATE_NTF].free = dpll_pin_get_ntf_free;
11811201
arr[DPLL_CMD_PIN_DELETE_NTF].policy = &dpll_pin_nest;
11821202
arr[DPLL_CMD_PIN_DELETE_NTF].cb = dpll_pin_get_rsp_parse;
1203+
arr[DPLL_CMD_PIN_DELETE_NTF].alloc_sz = sizeof(dpll_pin_get_ntf);
1204+
arr[DPLL_CMD_PIN_DELETE_NTF].free = dpll_pin_get_ntf_free;
11831205
arr[DPLL_CMD_PIN_CHANGE_NTF].policy = &dpll_pin_nest;
11841206
arr[DPLL_CMD_PIN_CHANGE_NTF].cb = dpll_pin_get_rsp_parse;
1207+
arr[DPLL_CMD_PIN_CHANGE_NTF].alloc_sz = sizeof(dpll_pin_get_ntf);
1208+
arr[DPLL_CMD_PIN_CHANGE_NTF].free = dpll_pin_get_ntf_free;
11851209
return arr;
11861210
} ();
11871211

generated/dpll-user.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ dpll_device_get_dump(ynl_cpp::ynl_socket& ys);
118118

119119
/* DPLL_CMD_DEVICE_GET - notify */
120120
struct dpll_device_get_ntf {
121+
__u16 family;
122+
__u8 cmd;
123+
struct ynl_ntf_base_type* next;
124+
void (*free)(struct ynl_ntf_base_type* ntf);
125+
dpll_device_get_rsp obj __attribute__((aligned(8)));
121126
};
122127

123128
/* ============== DPLL_CMD_DEVICE_SET ============== */
@@ -212,6 +217,11 @@ dpll_pin_get_dump(ynl_cpp::ynl_socket& ys, dpll_pin_get_req_dump& req);
212217

213218
/* DPLL_CMD_PIN_GET - notify */
214219
struct dpll_pin_get_ntf {
220+
__u16 family;
221+
__u8 cmd;
222+
struct ynl_ntf_base_type* next;
223+
void (*free)(struct ynl_ntf_base_type* ntf);
224+
dpll_pin_get_rsp obj __attribute__((aligned(8)));
215225
};
216226

217227
/* ============== DPLL_CMD_PIN_SET ============== */

0 commit comments

Comments
 (0)