7. Knobs State Management

7.1. Schema Values

7.1.1. DONE Values

CLOSED: [2019-12-07 Sat 17:30] Stored as a msgback blob in schema, the values store all 128 variables as an array

7.1.1.1. Schema Entry

<<knobs_schema_generation>>=
monolith_param_mkblob(*schema, 0,
                      "vals", 4,
                      NULL, 0, NULL);
7.1.1.2. msgpack generation

7.1.1.2.1. Write

<<knobs_function_declarations>>=
int knobs_data_write_vals(cmp_ctx_t *c, GFFLT *vals);
<<knobs_functions>>=
int knobs_data_write_vals(cmp_ctx_t *c, GFFLT *vals)
{
    int i;
    int rc;
    if (!cmp_write_array(c, 128)) return 0;

    for (i = 0; i < 128; i++) {
        rc = cmp_write_float(c, vals[i]);
        if (!rc) return 0;
    }

    return 1;
}
7.1.1.2.2. Read

<<knobs_function_declarations>>=
int knobs_data_read_vals(cmp_ctx_t *c, GFFLT *vals);
<<knobs_functions>>=
int knobs_data_read_vals(cmp_ctx_t *c, GFFLT *vals)
{
    int i;
    int rc;
    uint32_t size;
    if (!cmp_read_array(c, &size)) return 0;

    if (size != 128) {
        fprintf(stderr,
                "size of 128 expected, got %d\n",
                size);
        return 0;
    }

    for (i = 0; i < 128; i++) {
        rc = cmp_read_float(c, &vals[i]);
        if (!rc) return 0;
    }

    return 1;
}
7.1.1.3. DONE Saving blob

CLOSED: [2019-12-07 Sat 17:30] Must be populated explicitely.

<<knobs_data_save>>=
{
    cmp_ctx_t cmp;
    moncmp_d m;
    size_t sz;
    uint8_t *buf;

    sz = 0;
    moncmp_init_getsize(&cmp, &sz);
    knobs_data_write_vals(&cmp, knobs->vals);

    buf = calloc(1, sz);
    moncmp_init_write(&m, &cmp, buf);

    knobs_data_write_vals(&cmp, knobs->vals);
    monolith_param_setblob_default(schema, 0, buf, sz);
}
7.1.1.4. DONE Reading blob

CLOSED: [2019-12-07 Sat 17:30]

<<knobs_data_load>>=
{
    size_t sz;
    cmp_ctx_t cmp;
    uint8_t *buf;
    moncmp_d m;

    sz = 0;
    monolith_param_blob(schema, 0,
                        (void **)&buf,
                        (unsigned int *)&sz);

    moncmp_init_read(&m, &cmp, buf, sz);
    knobs_data_read_vals(&cmp, knobs->vals);
}

7.1.2. DONE Selected Knobs (4)

CLOSED: [2019-12-07 Sat 17:30] Useful because of how many knobs there are. Stored as int. Four of em.

7.1.2.1. Schema Entry

<<knobs_schema_generation>>=
sprintf(tmp, "selected_0");
for (i = 0; i < 4; i++) {
    tmp[9] = 48 + i; /* itoa */
    monolith_param_mkint(*schema, 1 + i,
                        tmp, 10,
                        knobs->selected[i]);
}
7.1.2.2. DONE Read Values

CLOSED: [2019-12-07 Sat 17:30]

<<knobs_data_load>>=
for (i = 0; i < 4; i++) {
    monolith_param_int(schema,
                       1 + i,
                       &knobs->selected[i]);
}

7.1.3. DONE Aux Knob

CLOSED: [2019-12-07 Sat 17:30] Stored as an integer.

7.1.3.1. Schema Entry

<<knobs_schema_generation>>=
monolith_param_mkint(*schema, 5,
                    "aux_knob", 8,
                    knobs->aux_knob);
7.1.3.2. DONE Read Aux Knob Value

CLOSED: [2019-12-07 Sat 17:30]

<<knobs_data_load>>=
monolith_param_int(schema,
                   5,
                   &knobs->aux_knob);

7.2. Knobs Schema Generation

A new knobs schema is created and initialized with the function knobs_schema.

<<knobs_function_declarations>>=
static int knobs_schema(page_knobs_d *knobs,
                        monolith_state_schema **schema);
<<knobs_functions>>=
static int knobs_schema(page_knobs_d *knobs,
                        monolith_state_schema **schema)
{
    int i;
    char tmp[16];

    monolith_state_schema_init(schema, 6);
<<knobs_schema_generation>>
    return 1;
}

7.3. Knobs State Save

<<knobs_function_declarations>>=
static int knobs_save(monolith_page *pg,
                    monolith_state *s,
                    const char *key,
                    unsigned int len);
<<knobs_functions>>=
static int knobs_save(monolith_page *pg,
                      monolith_state *s,
                      const char *key,
                      unsigned int len)
{
    page_knobs_d *knobs;
    monolith_state_schema *schema;
    knobs = monolith_page_data_get(pg);
    knobs_schema(knobs, &schema);
<<knobs_data_save>>
    monolith_state_write_schema(s, schema,
                                "knobs", 5,
                                key, len);
    monolith_state_schema_cleanup(&schema);
    return 1;
}
<<knobs_assign_callbacks>>=
monolith_page_save_set(pg, knobs_save);

7.4. Knobs State Load

<<knobs_function_declarations>>=
static int knobs_load(monolith_page *pg,
                      monolith_state *s,
                      const char *key,
                      unsigned int len);
<<knobs_functions>>=
static int knobs_load(monolith_page *pg,
                      monolith_state *s,
                      const char *key,
                      unsigned int len)
{
    page_knobs_d *knobs;
    monolith_state_schema *schema;
    int rc;

    knobs = monolith_page_data_get(pg);

    knobs_schema(knobs, &schema);
    rc = monolith_state_read_schema(s, schema, "knobs", 5, key, len);
    if (rc) {
        int i;
<<knobs_data_load>>
        knobs_redraw(knobs);
    }
    monolith_state_schema_cleanup(&schema);
    return rc;
}
<<knobs_assign_callbacks>>=
monolith_page_load_set(pg, knobs_load);



prev | home | next