Esempio n. 1
0
/**
 * Close connection to camera.
 *
 * @param camera a #Camera object
 * @param context a #GPContext object
 * @return a gphoto2 error code.
 *
 * Closes a connection to the camera and therefore gives other application
 * the possibility to access the camera, too.
 *
 * It is recommended that you 
 * call this function when you currently don't need the camera. The camera
 * will get reinitialized by gp_camera_init() automatically if you try to 
 * access the camera again.
 *
 */
int
gp_camera_exit (Camera *camera, GPContext *context)
{
	C_PARAMS (camera);

	GP_LOG_D ("Exiting camera ('%s')...", camera->pc->a.model);

	/*
	 * We have to postpone this operation if the camera is currently 
	 * in use. gp_camera_exit will be called again if the
	 * camera->pc->used will drop to zero.
	 */
	if (camera->pc->used) {
		camera->pc->exit_requested = 1;
		return (GP_OK);
	}

	/* Remove every timeout that is still pending */
	while (camera->pc->timeout_ids_len)
		gp_camera_stop_timeout (camera, camera->pc->timeout_ids[0]);
	free (camera->pc->timeout_ids);
	camera->pc->timeout_ids = NULL;

	if (camera->functions->exit) {
#ifdef HAVE_MULTI
		gp_port_open (camera->port);
#endif
		camera->functions->exit (camera, context);
	}
	gp_port_close (camera->port);
	memset (camera->functions, 0, sizeof (CameraFunctions));

	if (camera->pc->lh) {
#if !defined(VALGRIND)
		lt_dlclose (camera->pc->lh);
		lt_dlexit ();
#endif
		camera->pc->lh = NULL;
	}

	gp_filesystem_reset (camera->fs);

	return (GP_OK);
}
Esempio n. 2
0
static int
delete_all_func (CameraFilesystem *fs, const char* folder, void *data,
                 GPContext *context)
{
        Camera *camera = data;
        unsigned int not_erased = 0;
	KncCamRes cr;

        if (strcmp (folder, "/")) return (GP_ERROR_DIRECTORY_NOT_FOUND);

        CR (knc_erase_all (camera->pl->c, &cr, KNC_SOURCE_CARD, &not_erased),
	    context);
	CCR (cr, context);

        if (not_erased) {
                gp_context_error (context, _("%i pictures could not be "
                        "deleted because they are protected"), not_erased);
                gp_filesystem_reset (camera->fs);
                return (GP_ERROR);
        }

        return (GP_OK);
}
Esempio n. 3
0
int
main ()
{
	CameraFilesystem *fs;
	CameraFileInfo info;
	CameraList *list;
	int x, count;
	const char *name;
	char *foldername;
	GPContext *context;

#ifdef HAVE_MCHECK_H
	mtrace();
#endif

	CHECK (gp_list_new(&list));

	gp_log_add_func (GP_LOG_DEBUG, log_func, NULL);
	context = gp_context_new ();
	gp_context_set_error_func (context, error_func, NULL);

	printf ("*** Creating file system...\n");
	CHECK (gp_filesystem_new (&fs));

	printf ("*** Setting the callbacks...\n");
	CHECK (gp_filesystem_set_funcs (fs, &fsfuncs, NULL));

	printf ("*** Adding a file...\n");
	CHECK (gp_filesystem_append (fs, "/", "my.file", context));

	gp_filesystem_dump (fs);

	printf ("*** Removing this file...\n");
	CHECK (gp_filesystem_delete_file (fs, "/", "my.file", context));

	gp_filesystem_dump (fs);

	printf ("*** Resetting...\n");
	CHECK (gp_filesystem_reset (fs));

	gp_filesystem_dump (fs);

	printf ("*** Adding /...\n");
	CHECK (gp_filesystem_append (fs, "/", NULL, context));

	printf ("*** Adding /whatever ...\n");
	CHECK (gp_filesystem_append (fs, "/whatever", NULL, context));

	printf ("*** Adding /whatever/dir...\n");
	CHECK (gp_filesystem_append (fs, "/whatever/dir", NULL, context));

	printf ("*** Adding /whatever/dir/file1...\n");
	CHECK (gp_filesystem_append (fs, "/whatever/dir", "file1", context));

	gp_filesystem_dump (fs);

	printf ("*** Adding /whatever/dir/file2...\n");
	CHECK (gp_filesystem_append (fs, "/whatever/dir", "file2", context));
	CHECK (gp_filesystem_append (fs, "/whatever/dir", "file3", context));
	CHECK (gp_filesystem_append (fs, "/whatever/dir", "file4", context));
	CHECK (gp_filesystem_append (fs, "/whatever/dir", "file5", context));

	gp_filesystem_dump (fs);

	printf ("*** Deleting everything below root...\n");
	CHECK (gp_filesystem_delete_all (fs, "/", context));

	gp_filesystem_dump (fs);

	printf ("*** Appending root directory...\n");
	CHECK (gp_filesystem_append (fs, "/", NULL, context));

	printf ("*** Appending some directories...\n");
	CHECK (gp_filesystem_append (fs, "/whatever", NULL, context));
	CHECK (gp_filesystem_append (fs, "/whatever/directory", NULL, context));

	printf ("*** Adding some files...\n");
	CHECK (gp_filesystem_append (fs, "/whatever/directory",
				     "some.file", context));
	CHECK (gp_filesystem_append (fs, "/whatever/directory",
				     "some.file2", context));
	CHECK (gp_filesystem_append (fs, "/another/directory",
				     "another.file", context));

	gp_filesystem_dump (fs);

	printf ("*** Getting info about a file...\n");
	CHECK (gp_filesystem_get_info (fs, "/whatever/directory", "some.file",
				       &info, context));

	printf ("*** Getting info again (cache!)...\n");
	CHECK (gp_filesystem_get_info (fs, "/whatever/directory", "some.file",
				       &info, context));

	printf ("*** Set info about another file...\n");
	CHECK (gp_filesystem_set_info (fs, "/whatever/directory", "some.file2",
				       info, context));

	printf ("*** Getting info about this file (cache!)...\n");
	CHECK (gp_filesystem_get_info (fs, "/whatever/directory", "some.file2",
				       &info, context));

	printf ("*** Deleting a file...\n");
	CHECK (gp_filesystem_delete_file (fs, "/whatever/directory",
					  "some.file2", context));

	gp_filesystem_dump (fs);

	printf ("*** Resetting the filesystem...\n");
	CHECK (gp_filesystem_reset (fs));

	gp_filesystem_dump (fs);

	printf ("*** Getting file list for folder '/whatever/directory'...\n");
	CHECK (gp_filesystem_list_folders (fs, "/whatever/directory",
					   list, context));

	printf ("*** Getting file list for folder '/whatever/directory' "
		"again (cached!)...\n");
	CHECK (gp_filesystem_list_folders (fs, "/whatever/directory",
					   list, context));

	printf ("*** Counting the contents...\n");
	CHECK (count = gp_list_count (list));

	printf ("*** Listing the contents...\n");
	for (x = 0; x < count; x++) {
		CHECK (gp_list_get_name (list, x, &name));
		printf (" %i: '%s'\n", x, name);
	}

	printf ("*** Getting folder of 'file1'...\n");
	CHECK (gp_filesystem_get_folder (fs, "file1", &foldername, context));
	printf ("... found in '%s'.\n", foldername);
	free(foldername);

	printf ("*** Deleting a couple of files...\n");
	CHECK (gp_filesystem_delete_file (fs, "/whatever", "file5", context));
	CHECK (gp_filesystem_delete_file (fs, "/whatever", "file4", context));
	CHECK (gp_filesystem_delete_file (fs, "/whatever", "file3", context));

	gp_filesystem_dump (fs);

	printf ("*** Freeing file system...\n");
	CHECK (gp_filesystem_free (fs));

	gp_context_unref (context);

	CHECK (gp_list_free(list));

#ifdef HAVE_MCHECK_H
	muntrace();
#endif

	return (0);
}