blob: f9f53c635949c596bb3ed0f7479436aafc592ac6 [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);
45
Elia Battiston589addb2022-04-04 16:40:01 +020046//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 Battistone1cecb22022-03-21 10:05:25 +010049int get_devices_cb_wrapper(
Elia Battistonac8d23f2022-03-14 17:54:56 +010050 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 Battistone1cecb22022-03-21 10:05:25 +010059 return get_devices_cb(session, parent);
Elia Battistonac8d23f2022-03-14 17:54:56 +010060}