static int profile_load_state(void) { OhmFactStore *fs = ohm_fact_store_get_fact_store(); OhmFact *fact; GSList *l, *n; gchar key[128]; GValue *value; FILE *fp; int err; if ((fp = fopen(PROFILE_SAVE_PATH, "r")) == NULL) { if (errno != ENOENT) OHM_ERROR("profile: could not load saved state from %s (%d: %s)", PROFILE_SAVE_PATH, errno, strerror(errno)); return errno; } /* remove any old profile facts */ l = ohm_fact_store_get_facts_by_name(fs, FACTSTORE_PROFILE); while (l != NULL) { n = l->next; ohm_fact_store_remove(fs, l->data); l = n; } /* create new fact and populate it with saved fields */ if ((fact = ohm_fact_new(FACTSTORE_PROFILE)) == NULL) { OHM_ERROR("profile: failed to create fact %s", FACTSTORE_PROFILE); fclose(fp); return ENOMEM; } while ((err = load_field(fp, key, sizeof(key), &value)) == 0) ohm_fact_set(fact, key, value); fclose(fp); if (err != ENOENT) { g_object_unref(fact); OHM_ERROR("profile: failed to load saved state"); return err; } ohm_fact_store_insert(fs, fact); OHM_INFO("profile: saved state loaded"); return 0; }
/** * \brief Read an xml node "field". * \param item (out) The item class for we read the hierarchy. * \param node The node. */ void bf::xml::item_instance_field_node::read ( item_instance& item, const wxXmlNode* node ) const { CLAW_PRECOND( node!=NULL ); CLAW_PRECOND( node->GetName() == wxT("field") ); const std::string field_name( reader_tool::read_string(node, wxT("name")) ); const item_class& the_class(item.get_class()); if ( !the_class.has_field(field_name) ) claw::logger << claw::log_warning << "Unknown field '" << field_name << "' in '" << the_class.get_class_name() << "'" << std::endl; else { const type_field& field = the_class.get_field(field_name); load_field( item, field, node->GetChildren() ); } } // item_instance_field_node::read()