Coverage Report

Created: 2026-01-17 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/S2OPC/src/Common/configuration/sopc_common.c
Line
Count
Source
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
bool SOPC_Common_IsInitialized(void)
33
0
{
34
0
    return bCommon_IsInitialized;
35
0
}
36
37
SOPC_ReturnStatus SOPC_Common_Initialize(const SOPC_Log_Configuration* optLogConfig,
38
                                         const SOPC_Audit_Configuration* optAuditConfig)
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(optLogConfig);
65
66
0
    if (res)
67
0
    {
68
        /* Initialize Audit */
69
0
        res = SOPC_Audit_Initialize(optAuditConfig);
70
0
    }
71
72
    /* Set the IsInitialized status if everything was successful */
73
0
    if (res)
74
0
    {
75
0
        status = SOPC_STATUS_OK;
76
0
        bCommon_IsInitialized = true;
77
0
    }
78
79
0
    return status;
80
0
}
81
82
void SOPC_Common_Clear(void)
83
0
{
84
0
    bCommon_IsInitialized = false;
85
86
0
    SOPC_Audit_Clear();
87
0
    SOPC_Logger_Clear();
88
0
}
89
90
SOPC_ReturnStatus SOPC_Common_SetLogLevel(SOPC_Log_Level level)
91
0
{
92
0
    SOPC_Logger_SetTraceLogLevel(level);
93
0
    return SOPC_STATUS_OK;
94
0
}
95
96
SOPC_Log_Configuration SOPC_Common_GetDefaultLogConfiguration(void)
97
0
{
98
0
    SOPC_Log_Configuration defaultLogConfiguration = {
99
0
        .logLevel = SOPC_LOG_LEVEL_INFO,
100
0
        .logSystem = SOPC_LOG_SYSTEM_FILE,
101
0
        .logSysConfig = {.fileSystemLogConfig = {.logDirPath = "", .logMaxBytes = 1048576, .logMaxFiles = 50}}};
102
0
    return defaultLogConfiguration;
103
0
}