<commit_before>/**********************************************************************
*       Minolta Dimage V digital camera communication library         *
*               Copyright (C) 2000,2001 <NAME>                  *
*                                                                     *
*    This program is free software; you can redistribute it and/or    *
*    modify it under the terms of the GNU General Public License as   *
*    published by the Free Software Foundation; either version 2 of   *
*    the License, or (at your option) any later version.              *
*                                                                     *
*    This program is distributed in the hope that it will be useful,  *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
*    GNU General Public License for more details.                     *
*                                                                     *
*    You should have received a copy of the GNU General Public        *
*    License along with this program; if not, write to the Free       *
*    Software Foundation, Inc., 59 Temple Place, Suite 330,           *
*    Boston, MA 02111-1307 USA                                        *
*                                                                     *
**********************************************************************/

/* $Id$ */

#include "dimagev.h"

int camera_id (CameraText *id) 
{
#if defined HAVE_STRNCPY
	strncpy(id->text, "minolta-dimagev", sizeof(id->text));
#else
	strcpy(id->text, "minolta-dimagev");
#endif

	return GP_OK;
}

int camera_abilities (CameraAbilitiesList *list) 
{
	CameraAbilities *a;

	a = gp_abilities_new();

#if defined HAVE_STRNCPY
	strncpy(a->model, "Minolta Dimage V", sizeof(a->model));
#else
	strcpy(a->model, "Minolta Dimage V");
#endif
	a->port     = GP_PORT_SERIAL;
	a->speed[0] = 38400;
	a->speed[1] = 0;
	a->operations        = 	GP_OPERATION_CAPTURE_IMAGE |
				GP_OPERATION_CAPTURE_PREVIEW;
	a->file_operations   = 	GP_FILE_OPERATION_DELETE | 
				GP_FILE_OPERATION_PREVIEW;
	a->folder_operations = 	GP_FOLDER_OPERATION_PUT_FILE | 
				GP_FOLDER_OPERATION_DELETE_ALL;

	gp_abilities_list_append(list, a);

	return GP_OK;
}

int camera_init (Camera *camera) 
{
        int ret;
        dimagev_t *dimagev = NULL;

	/* First, set up all the function pointers */
	camera->functions->id 			= camera_id;
	camera->functions->abilities 		= camera_abilities;
	camera->functions->init 		= camera_init;
	camera->functions->exit 		= camera_exit;
	camera->functions->folder_list_folders 	= camera_folder_list_folders;
	camera->functions->folder_list_files   	= camera_folder_list_files;
	camera->functions->file_get 		= camera_file_get;
	camera->functions->file_get_preview 	= camera_file_get_preview;
	camera->functions->file_delete 		= camera_file_delete;
	camera->functions->folder_put_file      = camera_folder_put_file;
	camera->functions->folder_delete_all    = camera_folder_delete_all;
	camera->functions->capture 		= camera_capture;
	camera->functions->summary		= camera_summary;
	camera->functions->manual 		= camera_manual;
	camera->functions->about 		= camera_about;

	gp_debug_printf(GP_DEBUG_LOW, "dimagev", "initializing the camera");

	if ( ( dimagev = (dimagev_t*) malloc(sizeof(dimagev_t))) == NULL ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to allocate dimagev_t");
		return GP_ERROR_NO_MEMORY;
	}

	camera->camlib_data = dimagev;

	/* Now open a port. */
	if (( ret = gp_port_new(&(dimagev->dev), GP_PORT_SERIAL)) < 0 ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to allocate gp_port_dev");
		return ret;
	}

	gp_port_timeout_set(dimagev->dev, 5000);

#if defined HAVE_STRNCPY
	strncpy(dimagev->settings.serial.port, camera->port->path, sizeof(dimagev->settings.serial.port));
#else
	strcpy(dimagev->settings.serial.port, camera->port->path);
#endif
	dimagev->settings.serial.speed = 38400;
	dimagev->settings.serial.bits = 8;
	dimagev->settings.serial.parity = 0;
	dimagev->settings.serial.stopbits = 1;

	if ( ( dimagev->fs = gp_filesystem_new()) == NULL ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to allocate filesystem");
		return GP_ERROR;
	}

	gp_port_settings_set(dimagev->dev, dimagev->settings);
	gp_port_open(dimagev->dev);

	if  ( dimagev_get_camera_data(dimagev) < GP_OK ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to get current camera data");
		return GP_ERROR_IO;
	}

	if  ( dimagev_get_camera_status(dimagev) < GP_OK ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to get current camera status");
		return GP_ERROR_IO;
	}

	/* Let's make this non-fatal. An incorrect date doesn't affect much. */
	if ( dimagev_set_date(dimagev) < GP_OK ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to set camera to system time");
	}

	return GP_OK;
}

int camera_exit (Camera *camera) 
{
	dimagev_t *dimagev;

	dimagev = camera->camlib_data;

	/* Set the camera back into a normal mode. */

	if ( ( dimagev == NULL ) || ( dimagev->data == NULL ) ) {
		return GP_ERROR_BAD_PARAMETERS;
	}

	dimagev->data->host_mode = 0;

	/* This will also send the host mode of zero. */
	if ( dimagev_set_date(dimagev) < GP_OK ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to set camera to system time");
		return GP_ERROR_IO;
	}

	if ( dimagev->dev != NULL ) {
		gp_port_close(dimagev->dev);
		gp_port_free(dimagev->dev);
	}

	if ( dimagev->fs != NULL ) {
		gp_filesystem_free(dimagev->fs);
	}

	if ( dimagev->data != NULL ) {
		free(dimagev->data);
	}

	if ( dimagev->status != NULL ) {
		free(dimagev->status);
	}

	if ( dimagev->info != NULL ) {
		free(dimagev->info);
	}

	free(dimagev);

	return GP_OK;
}

int camera_folder_list_folders (Camera *camera, const char *folder, 
				CameraList *list) <commit_msg>Commented out the free() calls for the info structs; it's casuing a seg fault, even though it looks like valid data. Weird.<commit_after>/**********************************************************************
*       Minolta Dimage V digital camera communication library         *
*               Copyright (C) 2000,2001 <NAME>                  *
*                                                                     *
*    This program is free software; you can redistribute it and/or    *
*    modify it under the terms of the GNU General Public License as   *
*    published by the Free Software Foundation; either version 2 of   *
*    the License, or (at your option) any later version.              *
*                                                                     *
*    This program is distributed in the hope that it will be useful,  *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
*    GNU General Public License for more details.                     *
*                                                                     *
*    You should have received a copy of the GNU General Public        *
*    License along with this program; if not, write to the Free       *
*    Software Foundation, Inc., 59 Temple Place, Suite 330,           *
*    Boston, MA 02111-1307 USA                                        *
*                                                                     *
**********************************************************************/

/* $Id$ */

#include "dimagev.h"

int camera_id (CameraText *id) 
{
#if defined HAVE_STRNCPY
	strncpy(id->text, "minolta-dimagev", sizeof(id->text));
#else
	strcpy(id->text, "minolta-dimagev");
#endif

	return GP_OK;
}

int camera_abilities (CameraAbilitiesList *list) 
{
	CameraAbilities *a;

	a = gp_abilities_new();

#if defined HAVE_STRNCPY
	strncpy(a->model, "Minolta Dimage V", sizeof(a->model));
#else
	strcpy(a->model, "Minolta Dimage V");
#endif
	a->port     = GP_PORT_SERIAL;
	a->speed[0] = 38400;
	a->speed[1] = 0;
	a->operations        = 	GP_OPERATION_CAPTURE_IMAGE |
				GP_OPERATION_CAPTURE_PREVIEW;
	a->file_operations   = 	GP_FILE_OPERATION_DELETE | 
				GP_FILE_OPERATION_PREVIEW;
	a->folder_operations = 	GP_FOLDER_OPERATION_PUT_FILE | 
				GP_FOLDER_OPERATION_DELETE_ALL;

	gp_abilities_list_append(list, a);

	return GP_OK;
}

int camera_init (Camera *camera) 
{
        int ret;
        dimagev_t *dimagev = NULL;

	/* First, set up all the function pointers */
	camera->functions->id 			= camera_id;
	camera->functions->abilities 		= camera_abilities;
	camera->functions->init 		= camera_init;
	camera->functions->exit 		= camera_exit;
	camera->functions->folder_list_folders 	= camera_folder_list_folders;
	camera->functions->folder_list_files   	= camera_folder_list_files;
	camera->functions->file_get 		= camera_file_get;
	camera->functions->file_get_preview 	= camera_file_get_preview;
	camera->functions->file_delete 		= camera_file_delete;
	camera->functions->folder_put_file      = camera_folder_put_file;
	camera->functions->folder_delete_all    = camera_folder_delete_all;
	camera->functions->capture 		= camera_capture;
	camera->functions->summary		= camera_summary;
	camera->functions->manual 		= camera_manual;
	camera->functions->about 		= camera_about;

	gp_debug_printf(GP_DEBUG_LOW, "dimagev", "initializing the camera");

	if ( ( dimagev = (dimagev_t*) malloc(sizeof(dimagev_t))) == NULL ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to allocate dimagev_t");
		return GP_ERROR_NO_MEMORY;
	}

	camera->camlib_data = dimagev;

	/* Now open a port. */
	if (( ret = gp_port_new(&(dimagev->dev), GP_PORT_SERIAL)) < 0 ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to allocate gp_port_dev");
		return ret;
	}

	gp_port_timeout_set(dimagev->dev, 5000);

#if defined HAVE_STRNCPY
	strncpy(dimagev->settings.serial.port, camera->port->path, sizeof(dimagev->settings.serial.port));
#else
	strcpy(dimagev->settings.serial.port, camera->port->path);
#endif
	dimagev->settings.serial.speed = 38400;
	dimagev->settings.serial.bits = 8;
	dimagev->settings.serial.parity = 0;
	dimagev->settings.serial.stopbits = 1;

	if ( ( dimagev->fs = gp_filesystem_new()) == NULL ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to allocate filesystem");
		return GP_ERROR;
	}

	gp_port_settings_set(dimagev->dev, dimagev->settings);
	gp_port_open(dimagev->dev);

	if  ( dimagev_get_camera_data(dimagev) < GP_OK ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to get current camera data");
		return GP_ERROR_IO;
	}

	if  ( dimagev_get_camera_status(dimagev) < GP_OK ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to get current camera status");
		return GP_ERROR_IO;
	}

	/* Let's make this non-fatal. An incorrect date doesn't affect much. */
	if ( dimagev_set_date(dimagev) < GP_OK ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to set camera to system time");
	}

	return GP_OK;
}

int camera_exit (Camera *camera) 
{
	dimagev_t *dimagev;

	dimagev = camera->camlib_data;

	/* Set the camera back into a normal mode. */

	if ( ( dimagev == NULL ) || ( dimagev->data == NULL ) ) {
		return GP_ERROR_BAD_PARAMETERS;
	}

	dimagev->data->host_mode = 0;

	/* This will also send the host mode of zero. */
	if ( dimagev_set_date(dimagev) < GP_OK ) {
		gp_debug_printf(GP_DEBUG_LOW, "dimagev", "camera_init::unable to set camera to system time");
		return GP_ERROR_IO;
	}

	if ( dimagev->dev != NULL ) {
		gp_port_close(dimagev->dev);
		gp_port_free(dimagev->dev);
	}

	if ( dimagev->fs != NULL ) {
		gp_filesystem_free(dimagev->fs);
	}

	if ( dimagev->data != NULL ) {
		free(dimagev->data);
	}

	if ( dimagev->status != NULL ) {
		free(dimagev->status);
	}

/*
	if ( dimagev->info != NULL ) {
		free(dimagev->info);
	}
*/

	free(dimagev);

	return GP_OK;
}

int camera_folder_list_folders (Camera *camera, const char *folder, 
				CameraList *list) 
{'fraction_non_alphanumeric': 0.13581790895447723, 'fraction_numerical': 0.007503751875937969, 'mean_word_length': 3.167824878387769, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 155, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '105936', 'n_tokens_mistral': 4227, 'n_tokens_neox': 3972, 'n_words': 889}