File: _params.c

package info (click to toggle)
lebiniou 3.67.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,500 kB
  • sloc: ansic: 28,670; makefile: 1,276; sh: 602; awk: 432; xml: 261; javascript: 23
file content (106 lines) | stat: -rw-r--r-- 3,113 bytes parent folder | download | duplicates (3)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 *  Copyright 1994-2022 Olivier Girondel
 *
 *  This file is part of lebiniou.
 *
 *  lebiniou is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  lebiniou is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with lebiniou. If not, see <http://www.gnu.org/licenses/>.
 */

#include "constants.h"
#include "context.h"
#include "parameters.h"


uint32_t version = 0;
uint32_t options = BO_NONE;
enum LayerMode mode = LM_OVERLAY;
char desc[] = "Debug parameters";
char dname[] = "_Params";


/* parameters */
static int integer = 32;
static double real = 1;
static int boolean = 0;
enum Mode { MODE_ONE = 0, MODE_TWO, MODE_THREE, MODE_FOUR, MODE_FIVE, MODE_NB } Mode_e;
static const char *string_list[MODE_NB] = { "Joe", "William", "Jack", "Averell", "Ma" };
static int string_idx = MODE_ONE;
static json_t *playlist = NULL;


json_t *
get_parameters(const uint8_t fetch_all)
{
  json_t *params = json_object();

  plugin_parameters_add_int(params, BPP_DEBUG_INTEGER, integer, 1, 64, 1, "Integer");
  plugin_parameters_add_double(params, BPP_DEBUG_REAL, real, 0, 10, 0.1, "Real");
  plugin_parameters_add_boolean(params, BPP_DEBUG_BOOLEAN, boolean, "Boolean");
  plugin_parameters_add_string_list(params, BPP_DEBUG_STRING_LIST, MODE_NB, string_list, string_idx, MODE_NB-1, "String list");
  plugin_parameters_add_playlist(params, BPP_DEBUG_PLAYLIST, playlist, "Playlist");

  // DEBUG_JSON("params", params, 1);

  return params;
}


void
set_parameters(const Context_t *ctx, const json_t *in_parameters)
{
  plugin_parameter_parse_int_range(in_parameters, BPP_DEBUG_INTEGER, &integer);
  plugin_parameter_parse_double_range(in_parameters, BPP_DEBUG_REAL, &real);
  plugin_parameter_parse_boolean(in_parameters, BPP_DEBUG_BOOLEAN, &boolean);
  plugin_parameter_parse_string_list_as_int_range(in_parameters, BPP_DEBUG_STRING_LIST, MODE_NB, string_list, &string_idx);
  plugin_parameter_parse_playlist(in_parameters, BPP_DEBUG_PLAYLIST, &playlist);
}


json_t *
parameters(const Context_t *ctx, const json_t *in_parameters, const uint8_t fetch_all)
{
  if (NULL != in_parameters) {
    set_parameters(ctx, in_parameters);
  }

  return get_parameters(fetch_all);
}


int8_t
create(Context_t *ctx)
{
  playlist = json_pack("[sssss]", "File #1", "File #2", "File #3", "File #4", "File #5");
  // DEBUG_JSON("playlist", playlist, 1);

  return 1;
}


void
destroy(Context_t *ctx)
{
  json_decref(playlist);
}


void
run(Context_t *ctx)
{
  if (boolean) {
    xdebug("%s integer: %d, real: %f, boolean: %s, string: %s\n", __FILE__, integer, real,
           boolean ? "true" : "false", string_list[string_idx]);
    // DEBUG_JSON("playlist", playlist, 1);
  }
}