static void test_fact_structure_name (void) { OhmStructure* s; s = ohm_structure_new ("org.freedesktop.ohm.test"); g_assert (_vala_strcmp0 (ohm_structure_get_name (s), "org.freedesktop.ohm.test") == 0); g_assert (ohm_structure_get_qname (s) == g_quark_from_string ("org.freedesktop.ohm.test")); (s == NULL ? NULL : (s = (g_object_unref (s), NULL))); }
static void test_fact_pattern_new_for_fact (void) { void* pf; void* pp; pf = NULL; pp = NULL; { OhmFact* f; OhmPattern* p; OhmFact* _tmp0; f = ohm_fact_new ("org.test.match"); p = ohm_pattern_new_for_fact (f); pf = f; pp = p; g_object_add_weak_pointer (G_OBJECT (f), &pf); g_object_add_weak_pointer (G_OBJECT (p), &pp); _tmp0 = NULL; f = (_tmp0 = NULL, (f == NULL ? NULL : (f = (g_object_unref (f), NULL))), _tmp0); g_assert (pf != NULL); g_assert (ohm_pattern_get_fact (p) != NULL); g_assert (_vala_strcmp0 (ohm_structure_get_name (OHM_STRUCTURE (ohm_pattern_get_fact (p))), "org.test.match") == 0); (f == NULL ? NULL : (f = (g_object_unref (f), NULL))); (p == NULL ? NULL : (p = (g_object_unref (p), NULL))); } g_assert (pf == NULL); g_assert (pp == NULL); }
/******************** * dres_store_check ********************/ int dres_store_check(dres_t *dres) { dres_store_t *store = &dres->store; dres_variable_t *var; const char *name; int id, idx, updated; GSList *changes, *l; OhmFact *fact; OhmPatternMatch *match; if (store->view == NULL) return ENOENT; updated = FALSE; if ((changes = ohm_view_get_changes(store->view)) != NULL) { for (l = changes; l != NULL; l = g_slist_next(l)) { if (!OHM_PATTERN_IS_MATCH(l->data)) { DRES_ERROR("%s: invalid data from view", __FUNCTION__); continue; } match = OHM_PATTERN_MATCH(l->data); fact = ohm_pattern_match_get_fact(match); name = ohm_structure_get_name(OHM_STRUCTURE(fact)); id = (int)g_hash_table_lookup(store->ht, name); #if 0 DRES_INFO("variable '%s' has changed", name); #endif if (!id) { DRES_ERROR("%s: unkown variable %s", __FUNCTION__, name); continue; } if (DRES_ID_TYPE(id) != DRES_TYPE_FACTVAR) { DRES_ERROR("%s: got invalid type for variable %s (0x%x)", __FUNCTION__, name, id); continue; } if ((idx = DRES_INDEX(id)) >= dres->nfactvar) { DRES_ERROR("%s: invalid index %d for variable %s", __FUNCTION__, idx, name); continue; } var = dres->factvars + idx; dres_update_var_stamp(dres, var); updated = TRUE; } ohm_view_reset_changes(store->view); } return updated; }
static void removed_cb(void *data, OhmFact *fact) { (void)data; char *name; watch_fact_t *wfact; watch_entry_t *wentry; if (fact == NULL) { OHM_ERROR("resource: %s() called with null fact pointer",__FUNCTION__); return; } name = (char *)ohm_structure_get_name(OHM_STRUCTURE(fact)); if ((wfact = find_watch(name, watch_remove)) != NULL) { OHM_DEBUG(DBG_FS, "fact watch point: fact '%s' removed", name); for (wentry = wfact->entries; wentry != NULL; wentry = wentry->next){ wentry->callback.fact_watch(fact, name, fact_watch_remove, wentry->usrdata); } /* for */ } /* if find_watch */ }
static void _structure_set_get (OhmStructure* s) { GValue* v; GValue* vq; g_return_if_fail (OHM_IS_STRUCTURE (s)); g_assert (_vala_strcmp0 (ohm_structure_get_name (s), "org.freedesktop.ohm.test") == 0); g_assert (((void*) ohm_structure_get (s, "field1")) == NULL); ohm_structure_set (s, "field1", ohm_value_from_string ("test1")); ohm_structure_set (s, "field2", ohm_value_from_int (42)); v = ((GValue*) ohm_structure_get (s, "field1")); g_assert (_vala_strcmp0 (g_value_get_string (v), "test1") == 0); v = ((GValue*) ohm_structure_get (s, "field2")); g_assert (g_value_get_int (v) == 42); vq = ((GValue*) ohm_structure_qget (s, g_quark_from_string ("field2"))); g_assert (v == vq); ohm_structure_set (s, "field2", NULL); v = ((GValue*) ohm_structure_get (s, "field2")); g_assert (v == NULL); }
static void updated_cb(void *data,OhmFact *fact,GQuark fldquark,gpointer value) { (void)data; GValue *gval = (GValue *)value; char *name; watch_fact_t *wfact; watch_entry_t *wentry; fsif_field_t fld; char valb[256]; char *valstr; if (fact == NULL) { OHM_ERROR("resource: %s() called with null fact pointer",__FUNCTION__); return; } name = (char *)ohm_structure_get_name(OHM_STRUCTURE(fact)); if (value != NULL && (wfact = find_watch(name, watch_update)) != NULL) { for (wentry = wfact->entries; wentry != NULL; wentry = wentry->next){ fld.name = (char *)g_quark_to_string(fldquark); if (matching_entry(fact, wentry->selist) && (!wentry->fldname || !strcmp(fld.name, wentry->fldname))) { switch (G_VALUE_TYPE(gval)) { case G_TYPE_STRING: fld.type = fldtype_string; fld.value.string = (char *)g_value_get_string(gval); break; case G_TYPE_LONG: fld.type = fldtype_integer; fld.value.integer = g_value_get_long(gval); break; case G_TYPE_INT: fld.type = fldtype_integer; fld.value.integer = g_value_get_int(gval); break; case G_TYPE_ULONG: fld.type = fldtype_unsignd; fld.value.unsignd = g_value_get_ulong(gval); break; case G_TYPE_DOUBLE: fld.type = fldtype_floating; fld.value.floating = g_value_get_double(gval); break; case G_TYPE_UINT64: fld.type = fldtype_time; fld.value.time = g_value_get_uint64(gval); break; default: OHM_ERROR("resource: [%s] Unsupported data type (%d) " "for field '%s'", __FUNCTION__, G_VALUE_TYPE(gval), fld.name); return; } valstr = print_value(fld.type, (void *)&fld.value, valb, sizeof(valb)); OHM_DEBUG(DBG_FS, "field watch point: field '%s:%s' " "changed to '%s'", name, fld.name, valstr); wentry->callback.field_watch(fact, name, &fld,wentry->usrdata); return; } /* if matching_entry */ } /* for */ } /* if find_watch */ }