Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame] | 17 | #include <libyang/libyang.h> |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 18 | #include <sysrepo.h> |
| 19 | #include <sysrepo/xpath.h> |
| 20 | |
| 21 | //Needed to handle callback functions with a working data type in CGO |
| 22 | typedef void (*function)(); // https://golang.org/issue/19835 |
| 23 | |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame] | 24 | //CGO can't see raw structs |
| 25 | typedef struct lyd_node lyd_node; |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 26 | |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame] | 27 | //Exported by sysrepo.go |
| 28 | sr_error_t get_devices_cb(sr_session_ctx_t *session, lyd_node **parent); |
| 29 | |
| 30 | //The wrapper function is needed because CGO cannot express const char* |
| 31 | //and thus it can't match sysrepo's callback signature |
| 32 | int get_devices_cb_wrapper( |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 33 | sr_session_ctx_t *session, |
| 34 | uint32_t subscription_id, |
| 35 | const char *module_name, |
| 36 | const char *path, |
| 37 | const char *request_xpath, |
| 38 | uint32_t request_id, |
| 39 | struct lyd_node **parent, |
| 40 | void *private_data) |
| 41 | { |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame] | 42 | return get_devices_cb(session, parent); |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 43 | } |