blob: 08e7978d5c8f08634a354adbd4836c64c20790e5 [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 Battiston589addb2022-04-04 16:40:01 +020028//Provides data for the schema-mount extension
29LY_ERR mountpoint_ext_data_clb(
30 const struct lysc_ext_instance *ext,
31 void *user_data,
32 void **ext_data,
33 ly_bool *ext_data_free)
34{
35 *ext_data = (lyd_node*) user_data;
36 *ext_data_free = 0;
37 return LY_SUCCESS;
38}
39
40// Exported by sysrepo.go
Elia Battistone1cecb22022-03-21 10:05:25 +010041sr_error_t get_devices_cb(sr_session_ctx_t *session, lyd_node **parent);
42
Elia Battiston589addb2022-04-04 16:40:01 +020043//The wrapper functions are needed because CGO cannot express some keywords
44//such as "const", and thus it can't match sysrepo's callback signature
45
Elia Battistone1cecb22022-03-21 10:05:25 +010046int get_devices_cb_wrapper(
Elia Battistonac8d23f2022-03-14 17:54:56 +010047 sr_session_ctx_t *session,
48 uint32_t subscription_id,
49 const char *module_name,
50 const char *path,
51 const char *request_xpath,
52 uint32_t request_id,
53 struct lyd_node **parent,
54 void *private_data)
55{
Elia Battistone1cecb22022-03-21 10:05:25 +010056 return get_devices_cb(session, parent);
Elia Battistonac8d23f2022-03-14 17:54:56 +010057}