Coverage Report

Created: 2025-08-29 06:18

/src/S2OPC/src/Common/configuration/sopc_common.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Licensed to Systerel under one or more contributor license
3
 * agreements. See the NOTICE file distributed with this work
4
 * for additional information regarding copyright ownership.
5
 * Systerel licenses this file to you under the Apache
6
 * License, Version 2.0 (the "License"); you may not use this
7
 * file except in compliance with the License. You may obtain
8
 * a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
20
#include "sopc_common.h"
21
22
#include "sopc_common_constants.h"
23
#include "sopc_helper_endianness_cfg.h"
24
#include "sopc_ieee_check.h"
25
#include "sopc_logger.h"
26
27
/* static variables */
28
29
static bool bCommon_IsInitialized = false;
30
31
/* Functions */
32
33
bool SOPC_Common_IsInitialized(void)
34
0
{
35
0
    return bCommon_IsInitialized;
36
0
}
37
38
SOPC_ReturnStatus SOPC_Common_Initialize(SOPC_Log_Configuration logConfiguration)
39
0
{
40
0
    SOPC_ReturnStatus status = SOPC_STATUS_NOK;
41
0
    bool res = false;
42
43
0
    if (bCommon_IsInitialized)
44
0
    {
45
0
        return SOPC_STATUS_INVALID_STATE;
46
0
    }
47
48
    /* Check constants properties at runtime */
49
0
    if (!SOPC_Internal_Common_Constants_RuntimeCheck())
50
0
    {
51
0
        return SOPC_STATUS_NOK;
52
0
    }
53
54
    /* Check IEEE-754 compliance */
55
0
    if (!SOPC_IEEE_Check())
56
0
    {
57
0
        return SOPC_STATUS_NOK;
58
0
    }
59
60
    /* Check endianness */
61
0
    SOPC_Helper_Endianness_Check();
62
63
    /* Initialize logs */
64
0
    res = SOPC_Logger_Initialize(&logConfiguration);
65
66
    /* Set the IsInitialized status if everything was successful */
67
0
    if (true == res)
68
0
    {
69
0
        status = SOPC_STATUS_OK;
70
0
        bCommon_IsInitialized = true;
71
0
    }
72
73
0
    return status;
74
0
}
75
76
void SOPC_Common_Clear(void)
77
0
{
78
0
    bCommon_IsInitialized = false;
79
0
    SOPC_Logger_Clear();
80
0
}
81
82
SOPC_ReturnStatus SOPC_Common_SetLogLevel(SOPC_Log_Level level)
83
0
{
84
0
    SOPC_Logger_SetTraceLogLevel(level);
85
0
    return SOPC_STATUS_OK;
86
0
}
87
88
SOPC_Log_Configuration SOPC_Common_GetDefaultLogConfiguration(void)
89
0
{
90
0
    SOPC_Log_Configuration defaultLogConfiguration = {
91
0
        .logLevel = SOPC_LOG_LEVEL_INFO,
92
0
        .logSystem = SOPC_LOG_SYSTEM_FILE,
93
0
        .logSysConfig = {.fileSystemLogConfig = {.logDirPath = "", .logMaxBytes = 1048576, .logMaxFiles = 50}}};
94
0
    return defaultLogConfiguration;
95
0
}