blob: 82e9e3e642cea7bdbdb17892ba6f49415123872f [file] [log] [blame]
Elia Battistonac8d23f2022-03-14 17:54:56 +01001/*
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 Battistone1cecb22022-03-21 10:05:25 +010017#include <libyang/libyang.h>
Elia Battistonac8d23f2022-03-14 17:54:56 +010018#include <sysrepo.h>
19#include <sysrepo/xpath.h>
20
21//Needed to handle callback functions with a working data type in CGO
22typedef void (*function)(); // https://golang.org/issue/19835
23
Elia Battistone1cecb22022-03-21 10:05:25 +010024//CGO can't see raw structs
25typedef struct lyd_node lyd_node;
Elia Battiston589addb2022-04-04 16:40:01 +020026typedef struct ly_ctx ly_ctx;
Elia Battistonac8d23f2022-03-14 17:54:56 +010027
Elia Battiston4750d3c2022-07-14 13:24:56 +000028//Used to define the datastore edit mode
29const char* mergeOperation = "merge";
30
Elia Battiston589addb2022-04-04 16:40:01 +020031//Provides data for the schema-mount extension
32LY_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 Battiston4750d3c2022-07-14 13:24:56 +000043// Exported by callbacks.go
Elia Battistone1cecb22022-03-21 10:05:25 +010044sr_error_t get_devices_cb(sr_session_ctx_t *session, lyd_node **parent);
Elia Battistona1333642022-07-27 12:17:24 +000045sr_error_t get_services_cb(sr_session_ctx_t *session, lyd_node **parent);
46sr_error_t get_vlans_cb(sr_session_ctx_t *session, lyd_node **parent);
47sr_error_t get_bandwidth_profiles_cb(sr_session_ctx_t *session, lyd_node **parent);
48sr_error_t edit_service_profiles_cb(sr_session_ctx_t *session, sr_session_ctx_t *runningSession, sr_event_t event);
49sr_error_t edit_vlans_cb(sr_session_ctx_t *session, sr_event_t event);
Elia Battistone1cecb22022-03-21 10:05:25 +010050
Elia Battiston589addb2022-04-04 16:40:01 +020051//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 Battistone1cecb22022-03-21 10:05:25 +010054int get_devices_cb_wrapper(
Elia Battistonac8d23f2022-03-14 17:54:56 +010055 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 Battistone1cecb22022-03-21 10:05:25 +010064 return get_devices_cb(session, parent);
Elia Battistona1333642022-07-27 12:17:24 +000065}
66
67int 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
80int 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
93int 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
106int 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
119int 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 Battistonac8d23f2022-03-14 17:54:56 +0100129}