static GPFsFile * func_file_get (GPFs *fs, GPFsErr *e, const char *folder, unsigned int n, void *d) { GPFsFile *f; GPFsIf *i; printf ("<<< Backend is creating a file >>>\n"); f = gpfs_file_new (); /* Interface 'default' */ printf ("<<< Backend is adding an interface >>>\n"); i = gpfs_if_new (); gpfs_obj_set_name (GPFS_OBJ (i), NULL, "default"); gpfs_if_set_func_read (i, func_read1, NULL); gpfs_obj_set_func_bag_count (GPFS_OBJ (i), func_bag_count, NULL); gpfs_obj_set_func_bag_get (GPFS_OBJ (i), func_bag_get, NULL); gpfs_file_if_add (f, i); gpfs_obj_unref (GPFS_OBJ (i)); /* Interface 'preview' */ printf ("<<< Backend is adding an interface >>>\n"); i = gpfs_if_new (); gpfs_obj_set_name (GPFS_OBJ (i), NULL, "preview"); gpfs_if_set_func_read (i, func_read2, NULL); gpfs_obj_set_func_bag_count (GPFS_OBJ (i), func_bag_count, NULL); gpfs_obj_set_func_bag_get (GPFS_OBJ (i), func_bag_get, NULL); gpfs_file_if_add (f, i); gpfs_obj_unref (GPFS_OBJ (i)); return f; }
static void gpfs_file_free (GPFsObj *o) { GPFsFile *f = (GPFsFile *) o; unsigned int i; for (i = 0; i < f->count; i++) gpfs_obj_unref (GPFS_OBJ (f->ifs[i])); free (f->ifs); }
int main (int argc, char **argv) { GPFs *fs; unsigned int n, j; GPFsFile *f; GPFsIf *i; GPFsCache *c; /* Create a cache */ c = gpfs_cache_new (); /* Set up the filesystem */ fs = gpfs_new (); gpfs_set_func_file_count (fs, func_file_count, NULL); gpfs_set_func_file_get (fs, func_file_get, NULL); /* Test the filesystem */ printf ("Counting files...\n"); n = gpfs_file_count (fs, NULL, "/"); printf ("Found %i file(s).\n", n); printf ("Getting first file...\n"); f = gpfs_file_get (fs, NULL, "/", 0); printf ("... done.\n"); gpfs_obj_unref (GPFS_OBJ (fs)); printf ("Counting interfaces...\n"); n = gpfs_file_if_count (f); printf ("... done. Found %i interface(s).\n", n); for (j = 0; j < n; j++) { i = gpfs_file_if_get (f, j); /* Add the interface to our cache. */ gpfs_cache_if_add (c, i); gpfs_cache_if_set_limit (c, i, j * 20); #if 0 printf (" %i: Interface '%s' with %i properties\n", j, gpfs_if_get_name (i), gpfs_if_count_prop (i, NULL)); for (k = 0; k < gpfs_if_count_prop (i, NULL); k++) { prop = gpfs_if_get_prop (i, NULL, k); gpfs_prop_dump (prop); } #endif } printf ("Testing interfaces...\n"); for (j = 0; j < n; j++) { i = gpfs_file_if_get (f, j); gpfs_if_read (i, NULL, func_read_cb, NULL); } printf ("There are now %i interfaces in our cache.\n", gpfs_cache_if_count (c)); printf ("Testing interfaces again...\n"); for (j = 0; j < n; j++) { i = gpfs_file_if_get (f, j); gpfs_if_read (i, NULL, func_read_cb, NULL); } printf ("... done.\n"); printf ("Releasing file...\n"); gpfs_obj_unref (GPFS_OBJ (f)); printf ("... done.\n"); printf ("Releasing cache...\n"); gpfs_obj_unref (GPFS_OBJ (c)); printf ("... done.\n"); return 0; }