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 | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 26 | typedef struct ly_ctx ly_ctx; |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 27 | |
Elia Battiston | 4750d3c | 2022-07-14 13:24:56 +0000 | [diff] [blame^] | 28 | //Used to define the datastore edit mode |
| 29 | const char* mergeOperation = "merge"; |
| 30 | |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 31 | //Provides data for the schema-mount extension |
| 32 | LY_ERR mountpoint_ext_data_clb( |
| 33 | const struct lysc_ext_instance *ext, |
| 34 | void *user_data, |
| 35 | void **ext_data, |
| 36 | ly_bool *ext_data_free) |
| 37 | { |
| 38 | *ext_data = (lyd_node*) user_data; |
| 39 | *ext_data_free = 0; |
| 40 | return LY_SUCCESS; |
| 41 | } |
| 42 | |
Elia Battiston | 4750d3c | 2022-07-14 13:24:56 +0000 | [diff] [blame^] | 43 | // Exported by callbacks.go |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame] | 44 | sr_error_t get_devices_cb(sr_session_ctx_t *session, lyd_node **parent); |
| 45 | |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 46 | //The wrapper functions are needed because CGO cannot express some keywords |
| 47 | //such as "const", and thus it can't match sysrepo's callback signature |
| 48 | |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame] | 49 | int get_devices_cb_wrapper( |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 50 | sr_session_ctx_t *session, |
| 51 | uint32_t subscription_id, |
| 52 | const char *module_name, |
| 53 | const char *path, |
| 54 | const char *request_xpath, |
| 55 | uint32_t request_id, |
| 56 | struct lyd_node **parent, |
| 57 | void *private_data) |
| 58 | { |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame] | 59 | return get_devices_cb(session, parent); |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 60 | } |