summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/plcd/src/plcd_files.c
blob: b13242b9e208d60e1ae45091f0cc81f9f4494121 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Cleopatre project {{{
 *
 * Copyright (C) 2013 MStar Semiconductor
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    devkit/plcd/src/plcd_files.c
 * \ingroup plcd
 *
 * Manage read and write operation for :
 *  - HPAV.CONF
 *  - HPAV.INFO
 */
#include "plcd_files.h"
#include "plcd_ctx.h"

#include "libspid.h"

int
plcd_files_read_hpavconf (plcd_ctx_t *ctx)
{
    char is_cco_preferred_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
    char was_cco_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};

    PLCD_ASSERT (ctx);

    /* read and save hpav.conf file contents */
    if ((LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
        LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED, is_cco_preferred_str,
        LIBSPID_BOOLEAN_STR_MAX_LEN))
        || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
        LIBSPID_HPAV_CONF_LABEL_WAS_CCO, was_cco_str, LIBSPID_BOOLEAN_STR_MAX_LEN))
        || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
        LIBSPID_HPAV_CONF_LABEL_NMK, ctx->hpav_conf.nmk_str,
        LIBSPID_HPAV_CONF_NMK_STR_LEN))
        || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
        LIBSPID_HPAV_CONF_LABEL_NID, ctx->hpav_conf.nid_str,
        LIBSPID_HPAV_CONF_NID_STR_LEN))
        || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
        LIBSPID_HPAV_CONF_LABEL_SL, ctx->hpav_conf.sl_str,
        LIBSPID_HPAV_CONF_SL_STR_MAX_LEN))
        || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
        LIBSPID_HPAV_CONF_LABEL_USER_HFID, ctx->hpav_conf.user_hfid,
        LIBSPID_HPAV_CONF_HFID_MAX_LEN))
        || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
        LIBSPID_HPAV_CONF_LABEL_AVLN_HFID, ctx->hpav_conf.avln_hfid,
        LIBSPID_HPAV_CONF_HFID_MAX_LEN)))
    {
        syslog (LOG_WARNING, "libspid config read item failed");
        return -1;
    }

    ctx->hpav_conf.is_cco_preferred = LIBSPID_GET_BOOLEAN (is_cco_preferred_str);
    ctx->hpav_conf.was_cco = LIBSPID_GET_BOOLEAN (was_cco_str);
    return 0;
}

int
plcd_files_write_default_hpavinfo (plcd_ctx_t *ctx)
{
    PLCD_ASSERT (ctx);

    /* Set these default values into PLCD context */
    strcpy (ctx->hpav_info.status, LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED);
    strcpy (ctx->hpav_info.cco, LIBSPID_HPAV_INFO_VALUE_CCO_STATION);
    ctx->hpav_info.is_backup_cco = LIBSPID_FALSE;
    ctx->hpav_info.is_sc = LIBSPID_FALSE;
    ctx->hpav_info.is_sc_button = LIBSPID_FALSE;

    /* create an empty hpav.info file for writing default values */
    if ((LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
        LIBSPID_HPAV_INFO_LABEL_STATUS, LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED))
        || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
        LIBSPID_HPAV_INFO_LABEL_CCO, LIBSPID_HPAV_INFO_VALUE_CCO_STATION))
        || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
        LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, LIBSPID_VALUE_BOOLEAN_FALSE))
        || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
        LIBSPID_HPAV_INFO_LABEL_SC, LIBSPID_VALUE_BOOLEAN_FALSE))
        || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
        LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, LIBSPID_VALUE_BOOLEAN_FALSE)))
    {
        syslog (LOG_WARNING, "libspid config write item failed");
        return -1;
    }

    return 0;
}