static void test_fact_store_pattern_delete (void) { #define FACT_NAME "com.nokia.ahoy" OhmFactStore *fs; OhmFactStoreView *v1, *v2; OhmPattern *p1, *p2; OhmFact *f; fs = ohm_fact_store_new(); v1 = ohm_fact_store_new_view(fs, NULL); v2 = ohm_fact_store_new_view(fs, NULL); p1 = ohm_pattern_new(FACT_NAME); p2 = ohm_pattern_new(FACT_NAME); ohm_fact_store_view_add(v1, OHM_STRUCTURE(p1)); ohm_fact_store_view_add(v2, OHM_STRUCTURE(p2)); g_object_unref(p1); g_object_unref(p2); f = ohm_fact_new(FACT_NAME); ohm_fact_store_insert(fs, f); ohm_fact_store_view_remove(v1, OHM_STRUCTURE(p1)); g_object_unref(v1); f = ohm_fact_new(FACT_NAME); ohm_fact_store_insert(fs, f); }
static void test_fact_store_view_two (void) { OhmFactStore* fs; OhmFactStoreView* v; OhmFactStoreView* v2; OhmPattern* _tmp0; OhmPattern* _tmp1; OhmFact* _tmp2; OhmFact* _tmp3; OhmFact* _tmp4; OhmFact* _tmp5; OhmFact* f; fs = ohm_fact_store_new (); v = ohm_fact_store_new_view (fs, NULL); v2 = ohm_fact_store_new_view (fs, NULL); _tmp0 = NULL; ohm_fact_store_view_add (v, OHM_STRUCTURE ((_tmp0 = ohm_pattern_new ("org.freedesktop.hello")))); (_tmp0 == NULL ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL))); _tmp1 = NULL; ohm_fact_store_view_add (v2, OHM_STRUCTURE ((_tmp1 = ohm_pattern_new ("org.freedesktop.hello")))); (_tmp1 == NULL ? NULL : (_tmp1 = (g_object_unref (_tmp1), NULL))); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 0); _tmp2 = NULL; ohm_fact_store_insert (fs, (_tmp2 = ohm_fact_new ("org.freedesktop.match2"))); (_tmp2 == NULL ? NULL : (_tmp2 = (g_object_unref (_tmp2), NULL))); _tmp3 = NULL; ohm_fact_store_insert (fs, (_tmp3 = ohm_fact_new ("org.freedesktop.hello"))); (_tmp3 == NULL ? NULL : (_tmp3 = (g_object_unref (_tmp3), NULL))); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 1); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v2)->change_set)) == 1); _tmp4 = NULL; ohm_fact_store_insert (fs, (_tmp4 = ohm_fact_new ("org.freedesktop.hello"))); (_tmp4 == NULL ? NULL : (_tmp4 = (g_object_unref (_tmp4), NULL))); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 2); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v2)->change_set)) == 2); ohm_fact_store_change_set_reset (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 0); _tmp5 = NULL; ohm_fact_store_insert (fs, (_tmp5 = ohm_fact_new ("org.freedesktop.hello"))); (_tmp5 == NULL ? NULL : (_tmp5 = (g_object_unref (_tmp5), NULL))); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) != 0); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v2)->change_set)) == 3); f = ohm_fact_new ("org.freedesktop.self"); ohm_fact_store_change_set_reset (OHM_FACT_STORE_SIMPLE_VIEW (v2)->change_set); ohm_fact_store_view_add (v, OHM_STRUCTURE (f)); ohm_fact_store_insert (fs, f); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 2); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v2)->change_set)) == 0); (fs == NULL ? NULL : (fs = (g_object_unref (fs), NULL))); (v == NULL ? NULL : (v = (g_object_unref (v), NULL))); (v2 == NULL ? NULL : (v2 = (g_object_unref (v2), NULL))); (f == NULL ? NULL : (f = (g_object_unref (f), 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_free ********************/ void dres_store_free(dres_t *dres) { dres_store_t *store = &dres->store; OhmPattern *pattern; GSList *p, *n; if (store->ht != NULL) { g_hash_table_destroy(store->ht); store->ht = NULL; } if (store->view != NULL) { for (p = store->view->patterns; p != NULL; p = n) { n = p->next; pattern = p->data; if (!OHM_IS_PATTERN(pattern)) DRES_ERROR("%s@%s:%d: non-pattern object in view...", __FUNCTION__, __FILE__, __LINE__); else { ohm_fact_store_view_remove(store->view, OHM_STRUCTURE(pattern)); g_object_unref(pattern); } } g_object_unref(store->view); store->view = NULL; } if (store->fs) { g_object_unref(store->fs); store->fs = 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; }
/******************** * dres_store_track ********************/ int dres_store_track(dres_t *dres) { dres_store_t *store = &dres->store; dres_variable_t *var; OhmPattern *pattern; char *name; int id, i; store->view = ohm_fact_store_new_transparent_view(store->fs, NULL); if (store->view == NULL) return ENOMEM; for (i = 0; i < dres->nfactvar; i++) { var = dres->factvars + i; id = var->id; name = var->name; if (!DRES_TST_FLAG(var, VAR_PREREQ)) continue; if ((pattern = ohm_pattern_new(name)) == NULL) return ENOMEM; ohm_fact_store_view_add(store->view, OHM_STRUCTURE(pattern)); g_object_unref(pattern); g_hash_table_insert(store->ht, (gpointer)name, (gpointer)id); } return 0; }
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 test_fact_store_transaction_push_and_commit (void) { OhmFactStore* fs; OhmFactStoreView* v; OhmFactStoreView* v2; OhmFactStoreView* tpv; OhmPattern* _tmp0; OhmPattern* _tmp1; OhmFact* fact; GValue* val; fs = ohm_fact_store_new (); v = ohm_fact_store_new_view (fs, NULL); v2 = ohm_fact_store_new_view (fs, NULL); tpv = ohm_fact_store_new_transparent_view (fs, NULL); _tmp0 = NULL; ohm_fact_store_view_add (v, OHM_STRUCTURE ((_tmp0 = ohm_pattern_new ("org.test.match")))); (_tmp0 == NULL ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL))); _tmp1 = NULL; ohm_fact_store_view_add (v2, OHM_STRUCTURE ((_tmp1 = ohm_pattern_new ("org.freedesktop.hello")))); (_tmp1 == NULL ? NULL : (_tmp1 = (g_object_unref (_tmp1), NULL))); _tmp1 = NULL; ohm_fact_store_view_add (tpv, OHM_STRUCTURE ((_tmp1 = ohm_pattern_new ("org.test.match")))); (_tmp1 == NULL ? NULL : (_tmp1 = (g_object_unref (_tmp1), NULL))); _tmp1 = NULL; /* insertion*/ ohm_fact_store_transaction_push (fs); { fact = ohm_fact_new ("org.test.match"); ohm_fact_set (fact, "field", ohm_value_from_int (42)); ohm_fact_store_insert (fs, fact); g_assert (g_slist_length (ohm_fact_store_get_facts_by_name (fs, "org.test.match")) == 1); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 0); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 1); } ohm_fact_store_transaction_pop (fs, FALSE); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 1); /* and from the fact store*/ g_assert (g_slist_length (ohm_fact_store_get_facts_by_name (fs, "org.test.match")) == 1); ohm_fact_set (fact, "field", ohm_value_from_int (43)); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 2); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 2); ohm_fact_store_transaction_push (fs); { ohm_fact_store_remove (fs, fact); g_assert (g_slist_length (ohm_fact_store_get_facts_by_name (fs, "org.test.match")) == 0); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 2); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 3); } ohm_fact_store_transaction_pop (fs, FALSE); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 3); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 3); g_assert (g_slist_length (ohm_fact_store_get_facts_by_name (fs, "org.test.match")) == 0); /* update*/ fact = ohm_fact_new ("org.test.match"); ohm_fact_set (fact, "field", ohm_value_from_int (41)); ohm_fact_store_insert (fs, fact); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 4); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 4); ohm_fact_store_transaction_push (fs); { GValue* val; val = ((GValue*) ohm_fact_get (fact, "field")); g_assert (g_value_get_int (val) == 41); ohm_fact_set (fact, "field", ohm_value_from_int (42)); val = ((GValue*) ohm_fact_get (fact, "field")); g_assert (g_value_get_int (val) == 42); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 4); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 5); } ohm_fact_store_transaction_pop (fs, FALSE); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 5); g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 5); val = ((GValue*) ohm_fact_get (fact, "field")); g_assert (g_value_get_int (val) == 42); (fs == NULL ? NULL : (fs = (g_object_unref (fs), NULL))); (v == NULL ? NULL : (v = (g_object_unref (v), NULL))); (v2 == NULL ? NULL : (v2 = (g_object_unref (v2), NULL))); (fact == NULL ? NULL : (fact = (g_object_unref (fact), NULL))); }
static void test_fact_pattern_match_fields (void) { OhmPattern* p; OhmFact* match; OhmFact* match2; OhmFact* nomatch; OhmPatternMatch* _tmp0; OhmPatternMatch* _tmp1; OhmPatternMatch* _tmp2; OhmPatternMatch* _tmp3; OhmPatternMatch* m; OhmPatternMatch* _tmp4; OhmPatternMatch* _tmp5; OhmPatternMatch* _tmp6; OhmPatternMatch* _tmp7; p = ohm_pattern_new ("org.test.match"); match = ohm_fact_new ("org.test.match"); match2 = ohm_fact_new ("org.test.match"); nomatch = ohm_fact_new ("org.test.nomatch"); ohm_fact_set (match, "field1", ohm_value_from_string ("test1")); ohm_fact_set (match, "field2", ohm_value_from_int (42)); ohm_fact_set (match2, "field2", ohm_value_from_int (42)); _tmp0 = NULL; g_assert ((_tmp0 = ohm_pattern_match (p, match, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp0 == NULL ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL))); _tmp1 = NULL; g_assert ((_tmp1 = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp1 == NULL ? NULL : (_tmp1 = (g_object_unref (_tmp1), NULL))); ohm_structure_set (OHM_STRUCTURE (p), "field2", ohm_value_from_int (42)); _tmp2 = NULL; g_assert ((_tmp2 = ohm_pattern_match (p, match, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp2 == NULL ? NULL : (_tmp2 = (g_object_unref (_tmp2), NULL))); _tmp3 = NULL; g_assert ((_tmp3 = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp3 == NULL ? NULL : (_tmp3 = (g_object_unref (_tmp3), NULL))); m = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP); g_assert (ohm_pattern_match_get_fact (m) == match2); g_assert (ohm_pattern_match_get_pattern (m) == p); g_assert (ohm_pattern_match_get_event (m) == OHM_FACT_STORE_EVENT_LOOKUP); ohm_structure_set (OHM_STRUCTURE (p), "field1", ohm_value_from_string ("test1")); _tmp4 = NULL; g_assert ((_tmp4 = ohm_pattern_match (p, match, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp4 == NULL ? NULL : (_tmp4 = (g_object_unref (_tmp4), NULL))); _tmp5 = NULL; g_assert ((_tmp5 = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP)) == NULL); (_tmp5 == NULL ? NULL : (_tmp5 = (g_object_unref (_tmp5), NULL))); ohm_structure_set (OHM_STRUCTURE (p), "field1", ohm_value_from_string ("notest1")); _tmp6 = NULL; g_assert ((_tmp6 = ohm_pattern_match (p, match, OHM_FACT_STORE_EVENT_LOOKUP)) == NULL); (_tmp6 == NULL ? NULL : (_tmp6 = (g_object_unref (_tmp6), NULL))); _tmp7 = NULL; g_assert ((_tmp7 = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP)) == NULL); (_tmp7 == NULL ? NULL : (_tmp7 = (g_object_unref (_tmp7), NULL))); (p == NULL ? NULL : (p = (g_object_unref (p), NULL))); (match == NULL ? NULL : (match = (g_object_unref (match), NULL))); (match2 == NULL ? NULL : (match2 = (g_object_unref (match2), NULL))); (nomatch == NULL ? NULL : (nomatch = (g_object_unref (nomatch), NULL))); (m == NULL ? NULL : (m = (g_object_unref (m), NULL))); return; (void)test_fact_pattern_match_instance; }
static void test_fact_pattern_set_get (void) { OhmPattern* f; f = ohm_pattern_new ("org.freedesktop.ohm.test"); _structure_set_get (OHM_STRUCTURE (f)); (f == NULL ? NULL : (f = (g_object_unref (f), 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 */ }