Example #1
0
struct derived* derived_new (void)
{
	struct derived *obj = malloc (sizeof(struct derived));
	obj->base = base_new ();
#ifdef DERIVED_USE_V_TABLE
	if (!derived_v_table_inited)
		derived_init_v_table ();
	derived_register_v_table (obj, derived_v_table);
#endif
	derived_constructor (obj);
	return obj;
}
Example #2
0
int main(int argc, char *argv[]) {
	gtk_init(&argc, &argv);

	gchar *dirname = g_path_get_dirname(argv[0]);
	gchar *dataFilename = g_build_filename(dirname, "phonebook.dat", NULL);
	base_t *ctx = base_new(dataFilename);
	g_free(dirname);
	g_free(dataFilename);


	GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window), "PSP1Beleg");
	gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
	g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);


	gbase_list_singleton = gbase_list_new(ctx);
	tree_view_singleton = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gbase_list_singleton));
	g_object_unref(gbase_list_singleton);

	//fill_model(gbase_list_singleton);

	gtk_tree_view_set_search_column(GTK_TREE_VIEW(tree_view_singleton), GBASE_LIST_COL_NUMBER);
	g_signal_connect(G_OBJECT(tree_view_singleton), "key-press-event", G_CALLBACK(on_key_press), NULL);

	append_column(GBASE_LIST_COL_NUMBER,   "Phone Number");
	append_column(GBASE_LIST_COL_NAME,     "Surname");
	append_column(GBASE_LIST_COL_FORENAME, "Forename");


	GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
	gtk_container_add(GTK_CONTAINER(scrolled_window), tree_view_singleton);
	gtk_container_add(GTK_CONTAINER(window), scrolled_window);


	gtk_widget_show_all(window);
	gtk_main();


	bool ok = base_save(ctx);
	base_delete(ctx);

	return ok ? 0 : 1;
}
Example #3
0
struct ydb *ydb_open(const char *directory, struct ydb_options *options)
{
	struct db *db = db_new(directory);
	if (db == NULL) {
		return NULL;
	}

	struct base *base = base_new(db, db_log_dir(db), db_index_dir(db),
				     options);
	if (base == NULL) {
		db_free(db);
		return NULL;
	}
	log_info(db, "Opening YDB database \"%s\" by pid=%i.",
		 directory, getpid());

	linux_check_overcommit(db);

	struct ydb *ydb = malloc(sizeof(struct ydb));
	ydb->db = db;
	ydb->base = base;

	struct timeval tv0, tv1;
	gettimeofday(&tv0, NULL);

	int r = base_load(ydb->base);
	if (r != 0) {
		_ydb_close(ydb, 0);
		return NULL;
	}
	base_print_stats(ydb->base);
	gettimeofday(&tv1, NULL);
	log_info(db, "YDB loaded %llu items in %.3f seconds.",
		 (unsigned long long)base->used_size.count,
		 (float)TIMEVAL_MSEC_SUBTRACT(tv1, tv0) / 1000.);
	return ydb;
}