2001-10-23 Lutz M�ller <urc8@rz.uni-karlsruhe.de>

* libgphoto2/gphoto2-core.[c,h]: Removed. All functions redirected
          to gphoto2-abilities-list. Caching of this list should be done
          in the frontend.
        * frontends/command-line/main.c: Don't use gp_autodetect, use
	  gp_abilities_list_detect instead.
        * libgphoto2/setting.c: Move some initialization stuff from
          gphoto2-core to here.


git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2705 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Lutz Mueller
2001-10-23 18:00:18 +00:00
parent 46555f8514
commit a3364e4b63
12 changed files with 60 additions and 252 deletions

View File

@@ -1,3 +1,12 @@
2001-10-23 Lutz Müller <urc8@rz.uni-karlsruhe.de>
* libgphoto2/gphoto2-core.[c,h]: Removed. All functions redirected
to gphoto2-abilities-list. Caching of this list should be done
in the frontend.
* frontends/command-line/main.c: Don't use gp_autodetect.
* libgphoto2/setting.c: Move some initialization stuff from
gphoto2-core to here.
2001-10-23 Lutz Müller <urc8@rz.uni-karlsruhe.de>
* camlibs: Remove every reference to gp_camera_result_as_string

View File

@@ -27,7 +27,6 @@
#include <time.h>
#include <gphoto2-library.h>
#include <gphoto2-core.h>
#include <gphoto2-debug.h>
#include <gphoto2-port-log.h>

View File

@@ -244,24 +244,23 @@ OPTION_CALLBACK(use_stdout_size) {
OPTION_CALLBACK (auto_detect)
{
int x, count;
CameraList* list;
CameraList list;
CameraAbilitiesList *al;
const char *name, *value;
CHECK_RESULT (gp_list_new (&list));
CHECK_RESULT (gp_autodetect (list));
CHECK_RESULT (count = gp_list_count (list));
gp_abilities_list_new (&al);
gp_abilities_list_load (al);
gp_abilities_list_detect (al, &list);
CHECK_RESULT (count = gp_list_count (&list));
printf("%-30s %-16s\n", "Model", "Port");
printf("----------------------------------------------------------\n");
for (x = 0; x < count; x++) {
CHECK_RESULT (gp_list_get_name (list, x, &name));
CHECK_RESULT (gp_list_get_value (list, x, &value));
CHECK_RESULT (gp_list_get_name (&list, x, &name));
CHECK_RESULT (gp_list_get_value (&list, x, &value));
printf("%-30s %-16s\n", name, value);
}
/* We don't need to check for error here. */
gp_list_free (list);
return GP_OK;
}

View File

@@ -33,7 +33,6 @@ extern "C" {
#include <gphoto2-port.h>
#include <gphoto2-camera.h>
#include <gphoto2-core.h>
#include <gphoto2-debug.h>
#include <gphoto2-file.h>
#include <gphoto2-filesys.h>

View File

@@ -10,7 +10,6 @@ libgphoto2_la_SOURCES = \
gphoto2-abilities-list.c\
bayer.c bayer.h \
gphoto2-camera.c \
gphoto2-core.c \
gphoto2-debug.c \
exif.c exif.h \
gphoto2-file.c \
@@ -29,7 +28,6 @@ libgphoto2include_HEADERS = \
gphoto2-abilities.h \
gphoto2-abilities-list.h\
gphoto2-camera.h \
gphoto2-core.h \
gphoto2-debug.h \
gphoto2-file.h \
gphoto2-filesys.h \

View File

@@ -25,7 +25,6 @@
#include <stdio.h>
#include <string.h>
#include "gphoto2-core.h"
#include "gphoto2-result.h"
#include "gphoto2-port-log.h"
#include "gphoto2-library.h"

View File

@@ -30,7 +30,6 @@
#include <stdio.h>
#include "gphoto2-result.h"
#include "gphoto2-core.h"
#include "gphoto2-library.h"
#include "gphoto2-port-core.h"
#include "gphoto2-port-log.h"
@@ -106,12 +105,6 @@ gp_camera_new (Camera **camera)
CHECK_NULL (camera);
/*
* Be nice to frontend-writers and call some core function to make
* sure libgphoto2 is initialized...
*/
CHECK_RESULT (gp_camera_count ());
*camera = malloc (sizeof (Camera));
if (!*camera)
return (GP_ERROR_NO_MEMORY);
@@ -143,33 +136,6 @@ gp_camera_new (Camera **camera)
return(GP_OK);
}
/* DEPRECATED */
int gp_camera_set_model (Camera *, const char *);
int
gp_camera_set_model (Camera *camera, const char *model)
{
CameraAbilities abilities;
CHECK_NULL (camera && model);
CHECK_RESULT (gp_camera_abilities_by_name (model, &abilities));
CHECK_RESULT (gp_camera_set_abilities (camera, abilities));
return (GP_OK);
}
/* DEPRECATED */
int gp_camera_get_model (Camera *, const char **);
int
gp_camera_get_model (Camera *camera, const char **model)
{
CHECK_NULL (camera && model);
*model = camera->pc->a.model;
return (GP_OK);
}
/**
* gp_camera_set_abilities:
* @camera: a #Camera
@@ -724,40 +690,50 @@ gp_camera_init (Camera *camera)
*/
if (strcasecmp (camera->pc->a.model, "Directory Browse") &&
!strcmp ("", camera->pc->a.model)) {
CameraAbilitiesList *al;
int m;
gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Neither "
"port nor model set. Trying auto-detection...");
/* Call auto-detect and choose the first camera */
CRS (camera, gp_autodetect (&list));
gp_abilities_list_new (&al);
gp_abilities_list_load (al);
gp_abilities_list_detect (al, &list);
if (!gp_list_count (&list)) {
gp_log (GP_LOG_ERROR, "gphoto2-camera", _("Could not "
"detect any camera"));
gp_abilities_list_free (al);
gp_camera_set_error (camera, _("Could not detect "
"any camera"));
return (GP_ERROR_MODEL_NOT_FOUND);
}
CRS (camera, gp_list_get_name (&list, 0, &model));
CRS (camera, gp_camera_abilities_by_name (model, &a));
gp_list_get_name (&list, 0, &model);
m = gp_abilities_list_lookup_model (al, model);
gp_abilities_list_get_abilities (al, m, &a);
gp_abilities_list_free (al);
CRS (camera, gp_camera_set_abilities (camera, a));
CRS (camera, gp_list_get_value (&list, 0, &port));
CRS (camera, gp_camera_set_port_path (camera, port));
}
/* If we don't have a port at this point, return error */
if (!camera->port) {
gp_camera_status (camera, "");
return (GP_ERROR_UNKNOWN_PORT);
}
/* In case of USB, find the device */
switch (camera->port->type) {
case GP_PORT_USB:
CRS (camera, gp_port_usb_find_device (camera->port,
camera->pc->a.usb_vendor,
camera->pc->a.usb_product));
break;
default:
break;
if (strcasecmp (camera->pc->a.model, "Directory Browse")) {
/* If we don't have a port at this point, return error */
if (!camera->port) {
gp_camera_status (camera, "");
return (GP_ERROR_UNKNOWN_PORT);
}
/* In case of USB, find the device */
switch (camera->port->type) {
case GP_PORT_USB:
CRS (camera, gp_port_usb_find_device (camera->port,
camera->pc->a.usb_vendor,
camera->pc->a.usb_product));
break;
default:
break;
}
}
/* Load the library. */

View File

@@ -1,133 +0,0 @@
/* gphoto2-core.c
*
* Copyright (C) 2000 Scott Fritzinger
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include "gphoto2-core.h"
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "gphoto2-abilities.h"
#include "gphoto2-setting.h"
#include "gphoto2-result.h"
#include "gphoto2-abilities-list.h"
#include "gphoto2-camera.h"
#include "gphoto2-debug.h"
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
#define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);}
#define CHECK_INIT {if (!gal) CHECK_RESULT (gp_init ());}
/* Camera List */
CameraAbilitiesList *gal = NULL;
static int
gp_init (void)
{
char buf[1024];
int count;
gp_debug_printf (GP_DEBUG_LOW, "core", "Initializing GPhoto...");
/* Check if we are already initialized */
if (gal)
return (GP_OK);
/* Make sure the directories are created */
gp_debug_printf (GP_DEBUG_LOW, "core", "Creating $HOME/.gphoto");
#ifdef WIN32
GetWindowsDirectory (buf, 1024);
strcat (buf, "\\gphoto");
#else
sprintf (buf, "%s/.gphoto", getenv ("HOME"));
#endif
(void)GP_SYSTEM_MKDIR (buf);
/* Load settings */
gp_debug_printf (GP_DEBUG_LOW, "core", "Trying to load settings...");
load_settings();
/* What cameras do we support? */
CHECK_RESULT (gp_abilities_list_new (&gal));
CHECK_RESULT (gp_abilities_list_load (gal));
gp_debug_printf (GP_DEBUG_LOW, "core", "Following cameras were found:");
CHECK_RESULT (count = gp_abilities_list_count (gal));
if (count)
gp_abilities_list_dump_libs (gal);
else
gp_debug_printf (GP_DEBUG_LOW, "core","\tNone");
return (GP_OK);
}
int
gp_exit (void)
{
CHECK_RESULT (gp_abilities_list_free (gal));
gal = NULL;
return (GP_OK);
}
int
gp_autodetect (CameraList *list)
{
CHECK_INIT;
return (gp_abilities_list_detect (gal, list));
}
int
gp_camera_count (void)
{
CHECK_INIT;
return (gp_abilities_list_count (gal));
}
int
gp_camera_name (int camera_number, const char **camera_name)
{
CHECK_INIT;
return (gp_abilities_list_get_model (gal, camera_number, camera_name));
}
int
gp_camera_abilities (int camera_number, CameraAbilities *abilities)
{
CHECK_INIT;
return (gp_abilities_list_get_abilities (gal, camera_number,abilities));
}
int
gp_camera_abilities_by_name (const char *camera_name,
CameraAbilities *abilities)
{
int x;
CHECK_INIT;
CHECK_RESULT (x = gp_abilities_list_lookup_model (gal, camera_name));
return (gp_camera_abilities (x, abilities));
}

View File

@@ -1,43 +0,0 @@
/* gphoto2-core.h
*
* Copyright (C) 2000 Scott Fritzinger
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GPHOTO2_CORE_H__
#define __GPHOTO2_CORE_H__
#include <gphoto2-list.h>
#include <gphoto2-abilities.h>
/* Initialization is done automatically. */
int gp_exit (void);
int gp_autodetect (CameraList *list);
/* Retrieve the number of available cameras */
int gp_camera_count (void);
/* Retrieve the name of a particular camera */
int gp_camera_name (int camera_number, const char **camera_name);
/* Retreive abilities for a given camera */
int gp_camera_abilities (int camera_number, CameraAbilities *abilities);
int gp_camera_abilities_by_name (const char *camera_name,
CameraAbilities *abilities);
#endif /* __GPHOTO2_CORE_H__ */

View File

@@ -27,7 +27,6 @@
#include <string.h>
#include <stdio.h>
#include "gphoto2-core.h"
#include "gphoto2-result.h"
#include "gphoto2-file.h"
#include "gphoto2-port-log.h"

View File

@@ -21,7 +21,6 @@
#include <stdlib.h>
#include <string.h>
#include <gphoto2-library.h>
#include <gphoto2-core.h>
#include "jpeg.h"
// call example:nullpictureabort(picture,"Picture");

View File

@@ -25,8 +25,8 @@
#include <string.h>
#include "gphoto2-result.h"
#include "gphoto2-core.h"
#include "gphoto2-debug.h"
#include "gphoto2-port.h"
typedef struct {
/* key = value settings */
@@ -50,11 +50,8 @@ int gp_setting_get (char *id, char *key, char *value)
CHECK_NULL (id && key);
/*
* Be nice to frontend writers and make sure libgphoto2 is
* initialized
*/
CHECK_RESULT (gp_camera_count ());
if (!glob_setting_count)
load_settings ();
for (x=0; x<glob_setting_count; x++) {
if ((strcmp(glob_setting[x].id, id)==0) &&
@@ -133,6 +130,16 @@ int load_settings (void)
FILE *f;
char buf[1024], *id, *key, *value;
/* Make sure the directories are created */
gp_debug_printf (GP_DEBUG_LOW, "core", "Creating $HOME/.gphoto");
#ifdef WIN32
GetWindowsDirectory (buf, 1024);
strcat (buf, "\\gphoto");
#else
sprintf (buf, "%s/.gphoto", getenv ("HOME"));
#endif
(void)GP_SYSTEM_MKDIR (buf);
glob_setting_count = 0;
#ifdef WIN32
GetWindowsDirectory(buf, 1024);