static bool
read_state_cb(struct sml_object *sml, void *data)
{
    float time, weekday;
    Context *ctx = data;
    GList *itr;

    time = get_time(ctx);
    weekday = get_weekday(ctx->read_counter, ctx->read_freq);

    if (ctx->time)
        sml_variable_set_value(sml, ctx->time, time);
    if (ctx->weekday)
        sml_variable_set_value(sml, ctx->weekday, weekday);

    if (ctx->debug)
        printf("%i::READ(%i%%) - Weekday:%s, TB: %d\n", ctx->read_counter,
            ctx->read_counter  * 100 / ctx->reads, WEEKDAYS[(int)weekday],
            (int)time);

    for (itr = ctx->inputs; itr; itr = itr->next) {
        Variable *var = itr->data;
        variable_set_value(sml, var, ctx->read_counter, ctx->debug, ctx->rand);
    }

    for (itr = ctx->outputs; itr; itr = itr->next) {
        Variable *var = itr->data;
        variable_set_value(sml, var, ctx->read_counter, ctx->debug, ctx->rand);
    }

    ctx->read_counter++;

    return true;
}
Example #2
0
void varlist_set_value(VARLIST * v, gchar * name, gchar * value) 
{
  // remove old value
  varlist_remove_value(v, name);
  
  // set new value
  VARIABLE * var = variable_new(name);
  variable_set_value(var, value);
  g_tree_insert(v->tree, strdup(name), var);
  
  // update status variables and gauges, if need be
  if (!v->sess) return;
  svlist_handle_variable_change ((SVLIST *) v->sess->svlist, name);
  gaugelist_handle_variable_change ((GAUGELIST *) v->sess->gaugelist, name);
}