74be7039741e4003d483adc735f9a56813bd7d91
[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/xpath.h"
28 #include "core/framework.h"
29
30 static int app_common_populate_info(void);
31
32 int app_common_init(void) {
33     assert_session();
34
35     int rc = app_common_populate_info();
36     if(rc != NTS_ERR_OK) {
37         log_error("app_common_populate_info() failed\n");
38         return NTS_ERR_FAILED;
39     }
40
41     return NTS_ERR_OK;
42 }
43
44 static int app_common_populate_info(void) {
45     int rc;
46     if (framework_environment.nts.build_time && strlen(framework_environment.nts.build_time) > 0) {
47         rc  = sr_set_item_str(session_operational, NTS_NF_INFO_BUILD_TIME_XPATH, framework_environment.nts.build_time, 0, 0);
48         if(rc != SR_ERR_OK) {
49             log_error("sr_set_item_str failed\n");
50             return NTS_ERR_FAILED;
51         }
52     }
53
54     rc = sr_set_item_str(session_operational, NTS_NF_INFO_VERSION_XPATH, framework_environment.nts.version, 0, 0);
55     if(rc != SR_ERR_OK) {
56         log_error("sr_set_item_str failed\n");
57         return NTS_ERR_FAILED;
58     }
59
60     rc = sr_apply_changes(session_operational, 0, 0);
61     if(rc != SR_ERR_OK) {
62         log_error("sr_apply_changes failed: %s\n", sr_strerror(rc));
63         return NTS_ERR_FAILED;
64     }
65
66     return NTS_ERR_OK;
67 }