35bcef550270d5040c6de941654787faa64f59d9
[sim/o1-interface.git] / ntsimulator / ntsim-ng / core / app / app_common.c
1 /*************************************************************************
2 *
3 * Copyright 2020 highstreet technologies GmbH and others
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 ***************************************************************************/
17
18 #define _GNU_SOURCE
19
20 #include "supervisor.h"
21 #include "utils/log_utils.h"
22 #include "utils/sys_utils.h"
23 #include <stdio.h>
24 #include <assert.h>
25
26 #include "core/session.h"
27 #include "core/framework.h"
28
29 #define SYSREPO_BUILD_TIME_XPATH    "/nts-network-function:info/build-time"
30 #define SYSREPO_VERSION_XPATH       "/nts-network-function:info/version"
31
32 static int app_common_populate_info(void);
33
34 int app_common_init(void) {
35     assert_session();
36
37     int rc = app_common_populate_info();
38     if(rc != NTS_ERR_OK) {
39         log_error("app_common_populate_info() failed\n");
40         return NTS_ERR_FAILED;
41     }
42
43     return NTS_ERR_OK;
44 }
45
46 static int app_common_populate_info(void) {
47     int rc;
48     if (framework_environment.nts.build_time && strlen(framework_environment.nts.build_time) > 0) {
49         rc  = sr_set_item_str(session_operational, SYSREPO_BUILD_TIME_XPATH, framework_environment.nts.build_time, 0, 0);
50         if(rc != SR_ERR_OK) {
51             log_error("sr_set_item_str failed\n");
52             return NTS_ERR_FAILED;
53         }
54     }
55
56     rc = sr_set_item_str(session_operational, SYSREPO_VERSION_XPATH, framework_environment.nts.version, 0, 0);
57     if(rc != SR_ERR_OK) {
58         log_error("sr_set_item_str failed\n");
59         return NTS_ERR_FAILED;
60     }
61
62     rc = sr_apply_changes(session_operational, 0, 0);
63     if(rc != SR_ERR_OK) {
64         log_error("sr_apply_changes failed: %s\n", sr_strerror(rc));
65         return NTS_ERR_FAILED;
66     }
67
68     return NTS_ERR_OK;
69 }