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); |
Elia Battiston | a133364 | 2022-07-27 12:17:24 +0000 | [diff] [blame^] | 45 | sr_error_t get_services_cb(sr_session_ctx_t *session, lyd_node **parent); |
| 46 | sr_error_t get_vlans_cb(sr_session_ctx_t *session, lyd_node **parent); |
| 47 | sr_error_t get_bandwidth_profiles_cb(sr_session_ctx_t *session, lyd_node **parent); |
| 48 | sr_error_t edit_service_profiles_cb(sr_session_ctx_t *session, sr_session_ctx_t *runningSession, sr_event_t event); |
| 49 | sr_error_t edit_vlans_cb(sr_session_ctx_t *session, sr_event_t event); |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame] | 50 | |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 51 | //The wrapper functions are needed because CGO cannot express some keywords |
| 52 | //such as "const", and thus it can't match sysrepo's callback signature |
| 53 | |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame] | 54 | int get_devices_cb_wrapper( |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 55 | sr_session_ctx_t *session, |
| 56 | uint32_t subscription_id, |
| 57 | const char *module_name, |
| 58 | const char *path, |
| 59 | const char *request_xpath, |
| 60 | uint32_t request_id, |
| 61 | struct lyd_node **parent, |
| 62 | void *private_data) |
| 63 | { |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame] | 64 | return get_devices_cb(session, parent); |
Elia Battiston | a133364 | 2022-07-27 12:17:24 +0000 | [diff] [blame^] | 65 | } |
| 66 | |
| 67 | int get_services_cb_wrapper( |
| 68 | sr_session_ctx_t *session, |
| 69 | uint32_t subscription_id, |
| 70 | const char *module_name, |
| 71 | const char *path, |
| 72 | const char *request_xpath, |
| 73 | uint32_t request_id, |
| 74 | struct lyd_node **parent, |
| 75 | void *private_data) |
| 76 | { |
| 77 | return get_services_cb(session, parent); |
| 78 | } |
| 79 | |
| 80 | int get_vlans_cb_wrapper( |
| 81 | sr_session_ctx_t *session, |
| 82 | uint32_t subscription_id, |
| 83 | const char *module_name, |
| 84 | const char *path, |
| 85 | const char *request_xpath, |
| 86 | uint32_t request_id, |
| 87 | struct lyd_node **parent, |
| 88 | void *private_data) |
| 89 | { |
| 90 | return get_vlans_cb(session, parent); |
| 91 | } |
| 92 | |
| 93 | int get_bandwidth_profiles_cb_wrapper( |
| 94 | sr_session_ctx_t *session, |
| 95 | uint32_t subscription_id, |
| 96 | const char *module_name, |
| 97 | const char *path, |
| 98 | const char *request_xpath, |
| 99 | uint32_t request_id, |
| 100 | struct lyd_node **parent, |
| 101 | void *private_data) |
| 102 | { |
| 103 | return get_bandwidth_profiles_cb(session, parent); |
| 104 | } |
| 105 | |
| 106 | int edit_service_profiles_cb_wrapper( |
| 107 | sr_session_ctx_t *session, |
| 108 | uint32_t subscription_id, |
| 109 | const char *module_name, |
| 110 | const char *path, |
| 111 | sr_event_t event, |
| 112 | uint32_t request_id, |
| 113 | void *private_data) |
| 114 | { |
| 115 | sr_session_ctx_t* runningSession = (sr_session_ctx_t*)private_data; |
| 116 | return edit_service_profiles_cb(session, runningSession, event); |
| 117 | } |
| 118 | |
| 119 | int edit_vlans_cb_wrapper( |
| 120 | sr_session_ctx_t *session, |
| 121 | uint32_t subscription_id, |
| 122 | const char *module_name, |
| 123 | const char *path, |
| 124 | sr_event_t event, |
| 125 | uint32_t request_id, |
| 126 | void *private_data) |
| 127 | { |
| 128 | return edit_vlans_cb(session, event); |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 129 | } |