From 6b2e913e1efadb615cc1ff37166a2d7f63705bdd Mon Sep 17 00:00:00 2001 From: Lutz Mueller Date: Sat, 18 Aug 2001 14:39:12 +0000 Subject: [PATCH] =?UTF-8?q?2001-08-18=20=20Lutz=20M=EF=BF=BDller=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * README: Add notice about USB Mass Storage cameras. * include/*: * libgphoto2/*: Major cleanup - add licence notice to begin of each file, remove unused files/functions, ... * camlibs/konica/Makefile.am: There's no ChangeLog here... * tests/test-gphoto2.c: Adjust headers git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2003 67ed7778-7388-44ab-90cf-0a291f65f57c --- ChangeLog | 9 + README | 20 ++ camlibs/konica/Makefile.am | 2 +- include/Makefile.am | 23 +- include/gphoto2-abilities-list.h | 37 +++ include/gphoto2-abilities.h | 81 ++++++ include/gphoto2-camera.h | 100 +++++++- include/gphoto2-core.h | 50 +++- include/gphoto2-datatypes.h | 243 ------------------ include/gphoto2-filesys.h | 8 +- include/gphoto2-frontend.h | 54 +++- include/{gphoto2-lists.h => gphoto2-list.h} | 23 +- include/gphoto2-result.h | 41 +++ include/gphoto2-setting.h | 29 +++ include/gphoto2-settings.h | 2 - include/gphoto2.h | 5 +- libgphoto2/Makefile.am | 25 +- libgphoto2/abilities-list.c | 83 ++++++ libgphoto2/{util.c => abilities.c} | 58 ++++- libgphoto2/camera.c | 119 ++++----- libgphoto2/core.c | 270 ++++++++++++++------ libgphoto2/file.c | 83 +++--- libgphoto2/frontend.c | 49 +++- libgphoto2/library.c | 178 ------------- libgphoto2/library.h | 4 - libgphoto2/list.c | 64 +++++ libgphoto2/lists.c | 123 --------- libgphoto2/port.c | 8 - libgphoto2/result.c | 73 ++++++ libgphoto2/{settings.c => setting.c} | 67 +++-- libgphoto2/settings.h | 3 - libgphoto2/util.h | 2 - tests/test-gphoto2.c | 3 +- 33 files changed, 1086 insertions(+), 853 deletions(-) create mode 100644 include/gphoto2-abilities-list.h create mode 100644 include/gphoto2-abilities.h delete mode 100644 include/gphoto2-datatypes.h rename include/{gphoto2-lists.h => gphoto2-list.h} (64%) create mode 100644 include/gphoto2-result.h create mode 100644 include/gphoto2-setting.h delete mode 100644 include/gphoto2-settings.h create mode 100644 libgphoto2/abilities-list.c rename libgphoto2/{util.c => abilities.c} (67%) delete mode 100644 libgphoto2/library.c delete mode 100644 libgphoto2/library.h create mode 100644 libgphoto2/list.c delete mode 100644 libgphoto2/lists.c delete mode 100644 libgphoto2/port.c create mode 100644 libgphoto2/result.c rename libgphoto2/{settings.c => setting.c} (73%) delete mode 100644 libgphoto2/settings.h delete mode 100644 libgphoto2/util.h diff --git a/ChangeLog b/ChangeLog index d39f47772..ad87b1ce0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2001-08-18 Lutz Müller + + * README: Add notice about USB Mass Storage cameras. + * include/*: + * libgphoto2/*: Major cleanup - add licence notice to begin of each + file, remove unused files/functions, ... + * camlibs/konica/Makefile.am: There's no ChangeLog here... + * tests/test-gphoto2.c: Adjust headers + 2001-08-17 Lutz Müller * include/gphoto2-camera.h: diff --git a/README b/README index 19a8866a4..82eccf925 100644 --- a/README +++ b/README @@ -32,6 +32,26 @@ and availability of gphoto2. Another source of information is where you can access our CVS server to fetch the source code of gphoto2, gtkam and GnoCam (see below). +What is gphoto2 not? +-------------------- + +gphoto2 can only talk to cameras the language of those it understands. That is, +if you own a camera that speaks a language that isn't published anywhere and +nobody has been able to figure out the meaning of the sentences, gphoto2 cannot +communicate with those cameras. + +Then, there are cameras supporting the so-called USB Mass Storage protocol. +This is a protocol that has been published and lets you access any storage +device, be it a camera or a disk connected via USB to your computer. As there +are already drivers for this protocol out there, you don't need an additional +program like gphoto2. As of now, the following cameras seem to support the +USB Mass Storage protocol: + * Minolta Dimage 7 + * Nikon Coolpix 995 + * Olympus C-200Z, C-860L, C-2040, C-3040Z + * HP PhotoSmart 315, 618, 912 +Again, those cameras cannot be accessed through gphoto2. + Requirements ------------ diff --git a/camlibs/konica/Makefile.am b/camlibs/konica/Makefile.am index 3ad0b13c1..00d76ed1e 100644 --- a/camlibs/konica/Makefile.am +++ b/camlibs/konica/Makefile.am @@ -3,7 +3,7 @@ camlib_LTLIBRARIES = libgphoto2_konica.la CFLAGS = @CFLAGS@ `glib-config --cflags` LDFLAGS = @LDFLAGS@ `glib-config --libs` -EXTRA_DIST = ChangeLog EXPERTS +EXTRA_DIST = EXPERTS INCLUDES =\ -I$(top_srcdir)/include\ diff --git a/include/Makefile.am b/include/Makefile.am index 6be2ec707..928b1f90b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,16 +1,17 @@ ## Process this file with automake to generate a GNU Makefile gphotoheaddir = $(prefix)/include/gphoto2 -gphotohead_HEADERS= \ - gphoto2.h \ - gphoto2-camera.h \ - gphoto2-core.h \ - gphoto2-datatypes.h \ - gphoto2-file.h \ - gphoto2-filesys.h \ - gphoto2-frontend.h \ - gphoto2-library.h \ - gphoto2-lists.h \ - gphoto2-settings.h \ +gphotohead_HEADERS= \ + gphoto2.h \ + gphoto2-abilities.h \ + gphoto2-abilities-list.h \ + gphoto2-camera.h \ + gphoto2-core.h \ + gphoto2-file.h \ + gphoto2-filesys.h \ + gphoto2-frontend.h \ + gphoto2-library.h \ + gphoto2-list.h \ + gphoto2-setting.h \ gphoto2-widget.h diff --git a/include/gphoto2-abilities-list.h b/include/gphoto2-abilities-list.h new file mode 100644 index 000000000..85b71f003 --- /dev/null +++ b/include/gphoto2-abilities-list.h @@ -0,0 +1,37 @@ +/* gphoto2-abilities-list.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_ABILITIES_LIST_H__ +#define __GPHOTO2_ABILITIES_LIST_H__ + +#include + +typedef struct { + int count; + CameraAbilities **abilities; +} CameraAbilitiesList; + +CameraAbilitiesList* gp_abilities_list_new (void); + +int gp_abilities_list_free (CameraAbilitiesList *list); +int gp_abilities_list_dump (CameraAbilitiesList *list); +int gp_abilities_list_append (CameraAbilitiesList *list, CameraAbilities *); + +#endif /* __GPHOTO2_ABILITIES_LIST_H__ */ diff --git a/include/gphoto2-abilities.h b/include/gphoto2-abilities.h new file mode 100644 index 000000000..a9c059403 --- /dev/null +++ b/include/gphoto2-abilities.h @@ -0,0 +1,81 @@ +/* gphoto2-abilities.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_ABILITIES_H__ +#define __GPHOTO2_ABILITIES_H__ + +#include + +#define SERIAL_SUPPORTED(p) (p & (1 << 0)) +#define PARALLEL_SUPPORTED(p) (p & (1 << 1)) +#define USB_SUPPORTED(p) (p & (1 << 2)) +#define IEEE1394_SUPPORTED(p) (p & (1 << 3)) +#define NETWORK_SUPPORTED(p) (p & (1 << 4)) + +typedef gp_port_type CameraPortType; /* GP_PORT_SERIAL, GP_PORT_USB, etc. */ + +typedef enum { + GP_OPERATION_NONE = 0, + GP_OPERATION_CAPTURE_IMAGE = 1 << 0, + GP_OPERATION_CAPTURE_VIDEO = 1 << 1, + GP_OPERATION_CAPTURE_AUDIO = 1 << 2, + GP_OPERATION_CAPTURE_PREVIEW = 1 << 3, + GP_OPERATION_CONFIG = 1 << 4 +} CameraOperation; + +typedef enum { + GP_FILE_OPERATION_NONE = 0, + GP_FILE_OPERATION_DELETE = 1 << 1, + GP_FILE_OPERATION_CONFIG = 1 << 2, + GP_FILE_OPERATION_PREVIEW = 1 << 3 +} CameraFileOperation; + +typedef enum { + GP_FOLDER_OPERATION_NONE = 0, + GP_FOLDER_OPERATION_DELETE_ALL = 1 << 0, + GP_FOLDER_OPERATION_PUT_FILE = 1 << 1, + GP_FOLDER_OPERATION_CONFIG = 1 << 2 +} CameraFolderOperation; + +typedef struct { + char model [128]; + + /* Supported ports and speeds (latter terminated with a value of 0) */ + CameraPortType port; + int speed [64]; + + /* Supported operations */ + CameraOperation operations; + CameraFileOperation file_operations; + CameraFolderOperation folder_operations; + + int usb_vendor, usb_product; + + /* For core use */ + char library [1024]; + char id [1024]; +} CameraAbilities; + +CameraAbilities *gp_abilities_new (void); +int gp_abilities_free (CameraAbilities *abilities); +int gp_abilities_dump (CameraAbilities *abilities); +int gp_abilities_clear (CameraAbilities *abilities); + +#endif /* __GPHOTO2_ABILITIES_H__ */ diff --git a/include/gphoto2-camera.h b/include/gphoto2-camera.h index 2eabc0bda..1d9d782fc 100644 --- a/include/gphoto2-camera.h +++ b/include/gphoto2-camera.h @@ -21,9 +21,16 @@ #ifndef __GPHOTO2_CAMERA_H__ #define __GPHOTO2_CAMERA_H__ +typedef struct _Camera Camera; + +#include + #include -#include +#include #include +#include +#include +#include typedef struct { char text [32 * 1024]; @@ -66,17 +73,92 @@ typedef struct { CameraFileInfoStruct file; } CameraFileInfo; -typedef struct _Camera Camera; +typedef int (*c_id) (CameraText *); +typedef int (*c_abilities) (CameraAbilitiesList *); +typedef int (*c_init) (Camera*); +typedef int (*c_exit) (Camera*); +typedef int (*c_get_config) (Camera*, CameraWidget**); +typedef int (*c_set_config) (Camera*, CameraWidget*); +typedef int (*c_capture) (Camera*, int, CameraFilePath*); +typedef int (*c_capture_preview) (Camera*, CameraFile*); +typedef int (*c_summary) (Camera*, CameraText*); +typedef int (*c_manual) (Camera*, CameraText*); +typedef int (*c_about) (Camera*, CameraText*); -/* Retrieve the number of available cameras */ -int gp_camera_count (); +typedef int (*c_folder_list_folders) (Camera*, const char*, CameraList*); +typedef int (*c_folder_list_files) (Camera*, const char*, CameraList*); +typedef int (*c_folder_get_config) (Camera*, const char*, CameraWidget**); +typedef int (*c_folder_set_config) (Camera*, const char*, CameraWidget*); +typedef int (*c_folder_put_file) (Camera*, const char*, CameraFile*); +typedef int (*c_folder_delete_all) (Camera*, const char*); -/* Retrieve the name of a particular camera */ -int gp_camera_name (int camera_number, char *camera_name); +typedef int (*c_file_get_info) (Camera*, const char*, + const char*, CameraFileInfo*); +typedef int (*c_file_set_info) (Camera*, const char*, + const char*, CameraFileInfo*); +typedef int (*c_file_get_config) (Camera*, const char*, + const char*, CameraWidget**); +typedef int (*c_file_set_config) (Camera*, const char*, + const char*, CameraWidget*); +typedef int (*c_file_get) (Camera*, const char*, + const char*, CameraFile*); +typedef int (*c_file_get_preview) (Camera*, const char*, + const char*, CameraFile*); +typedef int (*c_file_delete) (Camera*, const char*, const char*); -/* Retreive abilities for a given camera */ -int gp_camera_abilities (int camera_number, CameraAbilities *abilities); -int gp_camera_abilities_by_name (char *camera_name, CameraAbilities *abilities); +typedef char *(*c_result_as_string) (Camera*, int); + + +typedef struct { + c_id id; + c_abilities abilities; + c_init init; + c_exit exit; + c_get_config get_config; + c_set_config set_config; + c_capture capture; + c_capture_preview capture_preview; + c_summary summary; + c_manual manual; + c_about about; + + c_folder_list_folders folder_list_folders; + c_folder_list_files folder_list_files; + c_folder_get_config folder_get_config; + c_folder_set_config folder_set_config; + c_folder_put_file folder_put_file; + c_folder_delete_all folder_delete_all; + + c_file_get_info file_get_info; + c_file_set_info file_set_info; + c_file_get_config file_get_config; + c_file_set_config file_set_config; + c_file_get_preview file_get_preview; + c_file_get file_get; + c_file_delete file_delete; + + c_result_as_string result_as_string; +} CameraFunctions; + +typedef gp_port_info CameraPortInfo; + +struct _Camera { + char model[128]; + + CameraPortInfo *port; + + int ref_count; + + void *library_handle; + + CameraAbilities *abilities; + CameraFunctions *functions; + + void *camlib_data; + void *frontend_data; + + int session; +}; /* Create a new camera device */ int gp_camera_new (Camera **camera); diff --git a/include/gphoto2-core.h b/include/gphoto2-core.h index 7af903159..a64a9bd19 100644 --- a/include/gphoto2-core.h +++ b/include/gphoto2-core.h @@ -1,13 +1,45 @@ -int gp_init(int debug); -int gp_is_initialized(void); -int gp_exit(); +/* 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. + */ -void gp_debug_printf(int level, char *id, char *format, ...); +#ifndef __GPHOTO2_CORE_H__ +#define __GPHOTO2_CORE_H__ -int gp_autodetect (CameraList *list); +#include +#include -int gp_frontend_register(CameraStatus status, CameraProgress progress, - CameraMessage message, CameraConfirm confirm, - CameraPrompt prompt); +int gp_init (int debug); +int gp_is_initialized (void); +int gp_exit (void); -char *gp_result_as_string (int result); +void gp_debug_printf (int level, char *id, char *format, ...); + +int gp_autodetect (CameraList *list); + +/* Retrieve the number of available cameras */ +int gp_camera_count (); + +/* Retrieve the name of a particular camera */ +int gp_camera_name (int camera_number, char *camera_name); + +/* Retreive abilities for a given camera */ +int gp_camera_abilities (int camera_number, CameraAbilities *abilities); +int gp_camera_abilities_by_name (char *camera_name, CameraAbilities *abilities); + +#endif /* __GPHOTO2_CORE_H__ */ diff --git a/include/gphoto2-datatypes.h b/include/gphoto2-datatypes.h deleted file mode 100644 index 97779119d..000000000 --- a/include/gphoto2-datatypes.h +++ /dev/null @@ -1,243 +0,0 @@ -#include -#include -#include - -/* Constants - ---------------------------------------------------------------- */ - -/* Return values. - Return values below -999 (starting with -1000) are defined by the - individual camera library. - - Don't forget to add the corresponding error descriptions in - libgphoto2/core.c. */ - -#define GP_ERROR_BAD_PARAMETERS -100 /* for checking function-param. */ -#define GP_ERROR_IO -101 /* IO problem */ -#define GP_ERROR_CORRUPTED_DATA -102 /* Corrupted data */ -#define GP_ERROR_FILE_EXISTS -103 /* File exists */ -#define GP_ERROR_NO_MEMORY -104 /* Insufficient memory */ -#define GP_ERROR_MODEL_NOT_FOUND -105 /* Model not found */ -#define GP_ERROR_NOT_SUPPORTED -106 /* Some op. is unsupported */ -#define GP_ERROR_DIRECTORY_NOT_FOUND -107 /* Directory not found */ -#define GP_ERROR_FILE_NOT_FOUND -108 /* File not found */ -#define GP_ERROR_DIRECTORY_EXISTS -109 /* Directory exists */ -#define GP_ERROR_NO_CAMERA_FOUND -110 /* No cameras auto-detected */ - -/* Macros - ---------------------------------------------------------------- */ - -/* Determining what kind of port a camera supports. - For use on CameraAbilities -> port */ -#define SERIAL_SUPPORTED(p) (p & (1 << 0)) -#define PARALLEL_SUPPORTED(p) (p & (1 << 1)) -#define USB_SUPPORTED(p) (p & (1 << 2)) -#define IEEE1394_SUPPORTED(p) (p & (1 << 3)) -#define NETWORK_SUPPORTED(p) (p & (1 << 4)) - -/* Enumerations - ---------------------------------------------------------------- */ - -/* Physical Connection Types */ -typedef gp_port_type CameraPortType; - /* GP_PORT_SERIAL, GP_PORT_USB, GP_PORT_PARALLEL, - GP_PORT_IEEE1394, GP_PORT_NETWORK */ - -/* Capture Type */ -typedef enum { - GP_OPERATION_NONE = 0, - GP_OPERATION_CAPTURE_IMAGE = 1 << 0, - GP_OPERATION_CAPTURE_VIDEO = 1 << 1, - GP_OPERATION_CAPTURE_AUDIO = 1 << 2, - GP_OPERATION_CAPTURE_PREVIEW = 1 << 3, - GP_OPERATION_CONFIG = 1 << 4 -} CameraOperation; - -/* File operations */ -typedef enum { - GP_FILE_OPERATION_NONE = 0, - GP_FILE_OPERATION_DELETE = 1 << 1, - GP_FILE_OPERATION_CONFIG = 1 << 2, - GP_FILE_OPERATION_PREVIEW = 1 << 3 -} CameraFileOperation; - -/* Folder operations */ -typedef enum { - GP_FOLDER_OPERATION_NONE = 0, - GP_FOLDER_OPERATION_DELETE_ALL = 1 << 0, - GP_FOLDER_OPERATION_PUT_FILE = 1 << 1, - GP_FOLDER_OPERATION_CONFIG = 1 << 2 -} CameraFolderOperation; - -/* Window prompt return values */ -typedef enum { - GP_PROMPT_CANCEL = -1, - GP_PROMPT_OK = 0 -} CameraPromptValue; - -/* Confirm return values */ -typedef enum { - GP_CONFIRM_YES, - GP_CONFIRM_YESTOALL, - GP_CONFIRM_NO, - GP_CONFIRM_NOTOALL -} CameraConfirmValue; - -/* Structures - ---------------------------------------------------------------- */ - -/* Camera capture choice */ -typedef struct { - int type; - /* One of the GP_CAPTURE_* types */ - char name[128]; - /* A string describing this resolution/setting */ - - int duration; - /* The duration of this capture event */ - /* Not needed in abilities */ -} CameraCaptureSetting; - -struct Camera; - -/* Port information/settings */ -#define CameraPortInfo gp_port_info - -/* Functions supported by the cameras */ - -struct _CameraAbilities { - char model[128]; - /* Name of the camera model */ - - int port; - /* Supported transports for this camera. */ - /* This is an OR of 1 or more GP_PORT_* types. */ - - int speed[64]; - /* Supported serial baud rates, terminated with */ - /* a value of 0. */ - - CameraOperation operations; - /* What operations the camera supports. This is */ - /* an OR of 1 or more GP_OPERATION_* types */ - - CameraFileOperation file_operations; - /* What file operations the camera supports. */ - /* This is an OR of 1 or more */ - /* GP_FILE_OPERATION_* types */ - - CameraFolderOperation folder_operations; - /* What folder operations the camera supports. */ - /* This is an OR of 1 or more */ - /* GP_FOLDER_OPERATION_* types */ - - int usb_vendor; - int usb_product; - /* Vendor and product id's for USB cameras */ - - /* Don't touch below. for core use */ - char library[1024]; - char id[64]; - -}; - -struct _CameraAbilitiesList { - int count; - CameraAbilities **abilities; -}; - -/* Camera function pointers */ -typedef int (*c_id) (CameraText *); -typedef int (*c_abilities) (CameraAbilitiesList *); -typedef int (*c_init) (Camera*); -typedef int (*c_exit) (Camera*); -typedef int (*c_get_config) (Camera*, CameraWidget**); -typedef int (*c_set_config) (Camera*, CameraWidget*); -typedef int (*c_capture) (Camera*, int, CameraFilePath*); -typedef int (*c_capture_preview) (Camera*, CameraFile*); -typedef int (*c_summary) (Camera*, CameraText*); -typedef int (*c_manual) (Camera*, CameraText*); -typedef int (*c_about) (Camera*, CameraText*); - -typedef int (*c_folder_list_folders) (Camera*, const char*, CameraList*); -typedef int (*c_folder_list_files) (Camera*, const char*, CameraList*); -typedef int (*c_folder_get_config) (Camera*, const char*, CameraWidget**); -typedef int (*c_folder_set_config) (Camera*, const char*, CameraWidget*); -typedef int (*c_folder_put_file) (Camera*, const char*, CameraFile*); -typedef int (*c_folder_delete_all) (Camera*, const char*); - -typedef int (*c_file_get_info) (Camera*, const char*, - const char*, CameraFileInfo*); -typedef int (*c_file_set_info) (Camera*, const char*, - const char*, CameraFileInfo*); -typedef int (*c_file_get_config) (Camera*, const char*, - const char*, CameraWidget**); -typedef int (*c_file_set_config) (Camera*, const char*, - const char*, CameraWidget*); -typedef int (*c_file_get) (Camera*, const char*, - const char*, CameraFile*); -typedef int (*c_file_get_preview) (Camera*, const char*, - const char*, CameraFile*); -typedef int (*c_file_delete) (Camera*, const char*, const char*); - -typedef char *(*c_result_as_string) (Camera*, int); - -/* Function pointers to the current library functions */ -typedef struct { - c_id id; - c_abilities abilities; - c_init init; - c_exit exit; - c_get_config get_config; - c_set_config set_config; - c_capture capture; - c_capture_preview capture_preview; - c_summary summary; - c_manual manual; - c_about about; - - c_folder_list_folders folder_list_folders; - c_folder_list_files folder_list_files; - c_folder_get_config folder_get_config; - c_folder_set_config folder_set_config; - c_folder_put_file folder_put_file; - c_folder_delete_all folder_delete_all; - - c_file_get_info file_get_info; - c_file_set_info file_set_info; - c_file_get_config file_get_config; - c_file_set_config file_set_config; - c_file_get_preview file_get_preview; - c_file_get file_get; - c_file_delete file_delete; - - c_result_as_string result_as_string; -} CameraFunctions; - -struct _Camera { - char model[128]; - - CameraPortInfo *port; - - int ref_count; - - void *library_handle; - - CameraAbilities *abilities; - CameraFunctions *functions; - - void *camlib_data; - void *frontend_data; - - int session; -}; - - -/* Function Pointers - ---------------------------------------------------------------- */ - -typedef int (*CameraStatus) (Camera*, char*); -typedef int (*CameraMessage) (Camera*, char*); -typedef int (*CameraConfirm) (Camera*, char*); -typedef int (*CameraProgress) (Camera*, CameraFile*, float); -typedef int (*CameraPrompt) (Camera*, CameraWidget*); diff --git a/include/gphoto2-filesys.h b/include/gphoto2-filesys.h index 0af1e8ba0..3e2ef5ab2 100644 --- a/include/gphoto2-filesys.h +++ b/include/gphoto2-filesys.h @@ -20,10 +20,10 @@ * Boston, MA 02111-1307, USA. */ -#ifndef __GPHOTO2_FILESYSTEM_H__ -#define __GPHOTO2_FILESYSTEM_H__ +#ifndef __GPHOTO2_FILESYS_H__ +#define __GPHOTO2_FILESYS_H__ -#include +#include /* You don't really want to know what's inside, do you? */ typedef struct _CameraFilesystem CameraFilesystem; @@ -54,4 +54,4 @@ int gp_filesystem_list_folders (CameraFilesystem *fs, const char *folder, CameraList *list); int gp_filesystem_dump (CameraFilesystem *fs); -#endif /* __GPHOTO2_FILESYSTEM_H__ */ +#endif /* __GPHOTO2_FILESYS_H__ */ diff --git a/include/gphoto2-frontend.h b/include/gphoto2-frontend.h index 46fd505b1..b81632304 100644 --- a/include/gphoto2-frontend.h +++ b/include/gphoto2-frontend.h @@ -1,12 +1,56 @@ -/* Header file for gPhoto2 +/* gphoto2-frontend.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. + */ - Author: Scott Fritzinger +#ifndef __GPHOTO2_FRONTEND_H__ +#define __GPHOTO2_FRONTEND_H__ - This library is covered by the LGPL. -*/ +#include +#include +#include + +typedef enum { + GP_CONFIRM_YES, + GP_CONFIRM_YESTOALL, + GP_CONFIRM_NO, + GP_CONFIRM_NOTOALL +} CameraConfirmValue; + +typedef enum { + GP_PROMPT_CANCEL = -1, + GP_PROMPT_OK = 0 +} CameraPromptValue; + +typedef int (* CameraStatus) (Camera *, char *); +typedef int (* CameraMessage) (Camera *, char *); +typedef int (* CameraConfirm) (Camera *, char *); +typedef int (* CameraProgress) (Camera *, CameraFile *, float); +typedef int (* CameraPrompt) (Camera *, CameraWidget *); + +int gp_frontend_register (CameraStatus status, CameraProgress progress, + CameraMessage message, CameraConfirm confirm, + CameraPrompt prompt); int gp_frontend_status (Camera *camera, char *status); int gp_frontend_message (Camera *camera, char *message); int gp_frontend_confirm (Camera *camera, char *message); -int gp_frontend_progress (Camera *camera, CameraFile *file, float percentage); +int gp_frontend_progress (Camera *camera, CameraFile *file, float percentage); int gp_frontend_prompt (Camera *camera, CameraWidget *window); + +#endif /* __GPHOTO2_FRONTEND_H__ */ diff --git a/include/gphoto2-lists.h b/include/gphoto2-list.h similarity index 64% rename from include/gphoto2-lists.h rename to include/gphoto2-list.h index f3701fd39..429b77f21 100644 --- a/include/gphoto2-lists.h +++ b/include/gphoto2-list.h @@ -1,4 +1,4 @@ -/* gphoto2-lists.h: Lists of files, folders, cameras, abilities, etc. +/* gphoto2-list.h: Lists of files, folders, cameras, etc. * * Copyright (C) 2001 Scott Fritzinger * @@ -18,8 +18,8 @@ * Boston, MA 02111-1307, USA. */ -#ifndef __GPHOTO2_LISTS_H__ -#define __GPHOTO2_LISTS_H__ +#ifndef __GPHOTO2_LIST_H__ +#define __GPHOTO2_LIST_H__ typedef struct { char name [128]; @@ -37,19 +37,4 @@ int gp_list_count (CameraList *list); int gp_list_append (CameraList *list, char *name); CameraListEntry* gp_list_entry (CameraList *list, int entry_number); - -typedef struct _CameraAbilities CameraAbilities; - -CameraAbilities* gp_abilities_new (void); -int gp_abilities_free (CameraAbilities *abilities); - - -typedef struct _CameraAbilitiesList CameraAbilitiesList; - -CameraAbilitiesList* gp_abilities_list_new (void); -int gp_abilities_list_free (CameraAbilitiesList *list); -int gp_abilities_list_dump (CameraAbilitiesList *list); -int gp_abilities_list_append (CameraAbilitiesList *list, - CameraAbilities *abilities); - -#endif /* __GPHOTO2_LISTS_H__ */ +#endif /* __GPHOTO2_LIST_H__ */ diff --git a/include/gphoto2-result.h b/include/gphoto2-result.h new file mode 100644 index 000000000..a392add2d --- /dev/null +++ b/include/gphoto2-result.h @@ -0,0 +1,41 @@ +/* gphoto2-result.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_RESULT_H__ +#define __GPHOTO2_RESULT_H__ + +/* Additional error codes are defined here */ +#include + +#define GP_ERROR_BAD_PARAMETERS -100 /* for checking function-param. */ +#define GP_ERROR_IO -101 /* IO problem */ +#define GP_ERROR_CORRUPTED_DATA -102 /* Corrupted data */ +#define GP_ERROR_FILE_EXISTS -103 /* File exists */ +#define GP_ERROR_NO_MEMORY -104 /* Insufficient memory */ +#define GP_ERROR_MODEL_NOT_FOUND -105 /* Model not found */ +#define GP_ERROR_NOT_SUPPORTED -106 /* Some op. is unsupported */ +#define GP_ERROR_DIRECTORY_NOT_FOUND -107 /* Directory not found */ +#define GP_ERROR_FILE_NOT_FOUND -108 /* File not found */ +#define GP_ERROR_DIRECTORY_EXISTS -109 /* Directory exists */ +#define GP_ERROR_NO_CAMERA_FOUND -110 /* No cameras auto-detected */ + +char *gp_result_as_string (int result); + +#endif /* __GPHOTO2_RESULT_H__ */ diff --git a/include/gphoto2-setting.h b/include/gphoto2-setting.h new file mode 100644 index 000000000..3369d9cd9 --- /dev/null +++ b/include/gphoto2-setting.h @@ -0,0 +1,29 @@ +/* gphoto2-setting.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_SETTING_H__ +#define __GPHOTO2_SETTING_H__ + +int load_settings (void); + +int gp_setting_set (char *id, char *key, char *value); +int gp_setting_get (char *id, char *key, char *value); + +#endif /* __GPHOTO2_SETTING_H__ */ diff --git a/include/gphoto2-settings.h b/include/gphoto2-settings.h deleted file mode 100644 index 63d855552..000000000 --- a/include/gphoto2-settings.h +++ /dev/null @@ -1,2 +0,0 @@ -int gp_setting_set (char *id, char *key, char *value); -int gp_setting_get (char *id, char *key, char *value); diff --git a/include/gphoto2.h b/include/gphoto2.h index 0cec6ff9e..935500d3e 100644 --- a/include/gphoto2.h +++ b/include/gphoto2.h @@ -21,15 +21,14 @@ extern "C" { #endif #include -#include #include #include #include #include #include #include -#include -#include +#include +#include #include diff --git a/libgphoto2/Makefile.am b/libgphoto2/Makefile.am index 292adb532..ec282fadd 100644 --- a/libgphoto2/Makefile.am +++ b/libgphoto2/Makefile.am @@ -6,19 +6,18 @@ CFLAGS= @CFLAGS@ \ -DDOCDIR=\"$(prefix)/doc/gphoto2\" libgphoto2_la_LDFLAGS = -version-info 0:0:0 -libgphoto2_la_SOURCES = \ - camera.c \ - core.c core.h \ - exif.c exif.h \ - file.c \ - filesys.c \ - frontend.c \ - globals.h \ - library.c library.h \ - lists.c \ - port.c \ - settings.c settings.h \ - util.c util.h \ +libgphoto2_la_SOURCES = \ + abilities.c \ + abilities-list.c \ + camera.c \ + core.c \ + exif.c exif.h \ + file.c \ + filesys.c \ + frontend.c \ + list.c \ + result.c \ + setting.c \ widget.c pkgconfigdir = $(libdir)/pkgconfig diff --git a/libgphoto2/abilities-list.c b/libgphoto2/abilities-list.c new file mode 100644 index 000000000..6a6b756b2 --- /dev/null +++ b/libgphoto2/abilities-list.c @@ -0,0 +1,83 @@ +/* abilities-list.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 "gphoto2-abilities-list.h" + +#include + +#include "gphoto2-core.h" +#include "gphoto2-result.h" + +CameraAbilitiesList *gp_abilities_list_new () +{ + CameraAbilitiesList *list; + + list = malloc (sizeof (CameraAbilitiesList)); + if (!list) + return (NULL); + + list->count = 0; + list->abilities = NULL; + + return (list); +} + +int gp_abilities_list_free (CameraAbilitiesList *list) +{ + int x; + + /* TODO: OS/2 Port crashes here... maybe compiler setting */ + + for (x = 0; x < list->count; x++) + free (list->abilities [x]); + free (list); + + return (GP_OK); +} + +int gp_abilities_list_dump (CameraAbilitiesList *list) +{ + int x; + + for (x = 0; x < list->count; x++) { + gp_debug_printf (GP_DEBUG_LOW, "core", "Camera #%i:", x); + gp_abilities_dump (list->abilities[x]); + } + + return (GP_OK); +} + +int gp_abilities_list_append (CameraAbilitiesList *list, + CameraAbilities *abilities) +{ + if (!list->abilities) + list->abilities = malloc (sizeof (CameraAbilities*)); + else + list->abilities = realloc (list->abilities, + sizeof (CameraAbilities*) * (list->count + 1)); + + if (!list->abilities) + return (GP_ERROR_NO_MEMORY); + + list->abilities [list->count] = abilities; + list->count++; + + return (GP_OK); +} diff --git a/libgphoto2/util.c b/libgphoto2/abilities.c similarity index 67% rename from libgphoto2/util.c rename to libgphoto2/abilities.c index 0f0ddade0..1c5d3cf6f 100644 --- a/libgphoto2/util.c +++ b/libgphoto2/abilities.c @@ -1,12 +1,54 @@ -#include -#include +/* abilities.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 "gphoto2-abilities.h" + #include -#include -#include "util.h" +#include "gphoto2-result.h" +#include "gphoto2-core.h" -int gp_abilities_dump (CameraAbilities *abilities) { +CameraAbilities * +gp_abilities_new (void) +{ + CameraAbilities *abilities; + abilities = malloc (sizeof (CameraAbilities)); + if (!abilities) + return (NULL); + + return (abilities); +} + +int +gp_abilities_free (CameraAbilities *abilities) +{ + if (!abilities) + return (GP_ERROR_BAD_PARAMETERS); + + free (abilities); + return (GP_OK); +} + +int gp_abilities_dump (CameraAbilities *abilities) +{ int x=0; gp_debug_printf(GP_DEBUG_LOW, "core", "Abilities for camera : %s", @@ -51,10 +93,10 @@ int gp_abilities_dump (CameraAbilities *abilities) { return (GP_OK); } -int gp_abilities_clear (CameraAbilities *abilities) { - +int gp_abilities_clear (CameraAbilities *abilities) +{ strcpy(abilities->model, ""); - abilities->port = 0; + abilities->port = GP_PORT_NONE; abilities->speed[0] = 0; abilities->operations = GP_OPERATION_NONE; abilities->file_operations = GP_FILE_OPERATION_NONE; diff --git a/libgphoto2/camera.c b/libgphoto2/camera.c index ea3aafbf0..4b0de57e8 100644 --- a/libgphoto2/camera.c +++ b/libgphoto2/camera.c @@ -1,11 +1,33 @@ +/* camera.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 "gphoto2-camera.h" + #include #include -#include -#ifdef HAVE_CONFIG_H +#include "gphoto2-result.h" +#include "gphoto2-frontend.h" +#include "gphoto2-core.h" + #include -#endif - #ifdef ENABLE_NLS # include # undef _ @@ -20,61 +42,14 @@ # define N_(String) (String) #endif -#include "globals.h" -#include "library.h" -#include "settings.h" -#include "util.h" +static int glob_session_camera = 0; int gp_camera_exit (Camera *camera); -int gp_camera_count () -{ - return (glob_abilities_list->count); -} - -int gp_camera_name (int camera_number, char *camera_name) -{ - if (glob_abilities_list == NULL) - return (GP_ERROR_MODEL_NOT_FOUND); - - if (camera_number > glob_abilities_list->count) - return (GP_ERROR_MODEL_NOT_FOUND); - - strcpy (camera_name, - glob_abilities_list->abilities[camera_number]->model); - return (GP_OK); -} - -int gp_camera_abilities (int camera_number, CameraAbilities *abilities) -{ - memcpy (abilities, glob_abilities_list->abilities[camera_number], - sizeof(CameraAbilities)); - - if (glob_debug) - gp_abilities_dump (abilities); - - return (GP_OK); -} - - -int gp_camera_abilities_by_name (char *camera_name, CameraAbilities *abilities) -{ - - int x; - - for (x = 0; x < glob_abilities_list->count; x++) { - if (strcmp (glob_abilities_list->abilities[x]->model, - camera_name) == 0) - return (gp_camera_abilities(x, abilities)); - } - - return (GP_ERROR_MODEL_NOT_FOUND); -} - int gp_camera_new (Camera **camera) { - *camera = (Camera*)malloc(sizeof(Camera)); + *camera = malloc (sizeof (Camera)); if (!*camera) return (GP_ERROR_NO_MEMORY); @@ -246,27 +221,24 @@ int gp_camera_init (Camera *camera) } /* Fill in camera abilities. */ - gp_debug_printf (GP_DEBUG_LOW, "core", - "Looking up abilities for model %s...", camera->model); - for (x = 0; x < glob_abilities_list->count; x++) { - if (strcmp (glob_abilities_list->abilities[x]->model, - camera->model) == 0) - break; - } - if (x == glob_abilities_list->count) - return GP_ERROR_MODEL_NOT_FOUND; - camera->abilities->file_operations = - glob_abilities_list->abilities[x]->file_operations; - camera->abilities->folder_operations = - glob_abilities_list->abilities[x]->folder_operations; - camera->abilities->operations = - glob_abilities_list->abilities[x]->operations; + result = gp_camera_abilities_by_name (camera->model, camera->abilities); + if (result != GP_OK) + return (result); /* Load the library. */ - gp_debug_printf (GP_DEBUG_LOW, "core", "Loading library %s...", - glob_abilities_list->abilities[x]->library); - if ((result = load_library(camera)) != GP_OK) - return (result); + gp_debug_printf (GP_DEBUG_LOW, "core", "Loading library..."); + camera->library_handle = GP_SYSTEM_DLOPEN (camera->abilities->library); + if (!camera->library_handle) { + gp_camera_free (camera); + return (GP_ERROR); + } + + camera->functions->id = GP_SYSTEM_DLSYM (camera->library_handle, + "camera_id"); + camera->functions->abilities = GP_SYSTEM_DLSYM (camera->library_handle, + "camera_abilities"); + camera->functions->init = GP_SYSTEM_DLSYM (camera->library_handle, + "camera_init"); return (camera->functions->init (camera)); } @@ -384,7 +356,8 @@ int gp_camera_exit (Camera *camera) return (GP_ERROR_NOT_SUPPORTED); ret = camera->functions->exit (camera); - close_library (camera); + + GP_SYSTEM_DLCLOSE (camera->library_handle); return (ret); } diff --git a/libgphoto2/core.c b/libgphoto2/core.c index 771079a33..d792fe9c7 100644 --- a/libgphoto2/core.c +++ b/libgphoto2/core.c @@ -1,31 +1,34 @@ +/* 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 "gphoto2-core.h" + #include #include #include -#include - -#ifdef HAVE_CONFIG_H -#include -#endif - -#ifdef ENABLE_NLS -# include -# undef _ -# define _(String) dgettext (PACKAGE, String) -# ifdef gettext_noop -# define N_(String) gettext_noop (String) -# else -# define N_(String) (String) -# endif -#else -# define _(String) (String) -# define N_(String) (String) -#endif - -#include "core.h" -#include "library.h" -#include "settings.h" -#include "util.h" +#include +#include +#include +#include +#include /* Debug level */ int glob_debug = 0; @@ -33,37 +36,137 @@ int glob_debug = 0; /* Camera List */ CameraAbilitiesList *glob_abilities_list; -/* Currently loaded settings */ -int glob_setting_count = 0; -Setting glob_setting[512]; - -/* Sessions */ -int glob_session_camera = 0; -int glob_session_file = 0; - -/* Front-end function pointers */ -CameraStatus gp_fe_status = NULL; -CameraProgress gp_fe_progress = NULL; -CameraMessage gp_fe_message = NULL; -CameraConfirm gp_fe_confirm = NULL; -CameraPrompt gp_fe_prompt = NULL; - -static char *result_string[] = { - /* GP_ERROR_BAD_PARAMETERS -100 */ N_("Bad parameters"), - /* GP_ERROR_IO -101 */ N_("I/O problem"), - /* GP_ERROR_CORRUPTED_DATA -102 */ N_("Corrupted data"), - /* GP_ERROR_FILE_EXISTS -103 */ N_("File exists"), - /* GP_ERROR_NO_MEMORY -104 */ N_("Insufficient memory"), - /* GP_ERROR_MODEL_NOT_FOUND -105 */ N_("Unknown model"), - /* GP_ERROR_NOT_SUPPORTED -106 */ N_("Unsupported operation"), - /* GP_ERROR_DIRECTORY_NOT_FOUND -107 */ N_("Directory not found"), - /* GP_ERROR_FILE_NOT_FOUND -108 */ N_("File not found"), - /* GP_ERROR_DIRECTORY_EXISTS -109 */ N_("Directory exists"), - /* GP_ERROR_NO_CAMERA_FOUND -110 */ N_("No cameras were detected") -}; - static int have_initted = 0; +int is_library(char *library_filename) +{ + int ret = GP_OK; + void *lh; + c_id id; + + if ((lh = GP_SYSTEM_DLOPEN(library_filename)) == NULL) + return (GP_ERROR); + id = (c_id)GP_SYSTEM_DLSYM(lh, "camera_id"); + if (!id) + ret = GP_ERROR; + GP_SYSTEM_DLCLOSE(lh); + + return (ret); +} + +/* Returns the number of cameras added to the CameraChoice list */ +/* 0 implies an error occurred */ +int load_camera_list(char *library_filename) +{ + CameraText id; + void *lh; + c_abilities load_camera_abilities; + c_id load_camera_id; + int x, old_count; + + /* try to open the library */ + if ((lh = GP_SYSTEM_DLOPEN(library_filename))==NULL) { + if (glob_debug) + perror("core:\tload_camera_list"); + return 0; + } + + /* check to see if this library has been loaded */ + load_camera_id = (c_id)GP_SYSTEM_DLSYM(lh, "camera_id"); + load_camera_id(&id); + gp_debug_printf(GP_DEBUG_LOW, "core", "\t library id: %s", id.text); + + for (x=0; xcount; x++) { + if (strcmp(glob_abilities_list->abilities[x]->id, id.text)==0) { + GP_SYSTEM_DLCLOSE(lh); + return (GP_ERROR); + } + } + + /* load in the camera_abilities function */ + load_camera_abilities = (c_abilities)GP_SYSTEM_DLSYM(lh, "camera_abilities"); + old_count = glob_abilities_list->count; + + if (load_camera_abilities(glob_abilities_list) != GP_OK) { + GP_SYSTEM_DLCLOSE(lh); + return 0; + } + + /* Copy in the core-specific information */ + for (x=old_count; xcount; x++) { + strcpy(glob_abilities_list->abilities[x]->id, id.text); + strcpy(glob_abilities_list->abilities[x]->library, library_filename); + } + + GP_SYSTEM_DLCLOSE(lh); + + return x; +} + +int load_cameras_search(char *directory) +{ + GP_SYSTEM_DIR d; + GP_SYSTEM_DIRENT de; + char buf[1024]; + + gp_debug_printf(GP_DEBUG_LOW, "core","Trying to load camera libraries in:"); + gp_debug_printf(GP_DEBUG_LOW, "core","\t%s", directory); + + /* Look for available camera libraries */ + d = GP_SYSTEM_OPENDIR(directory); + if (!d) { + gp_debug_printf(GP_DEBUG_LOW, "core", "couldn't open %s", directory); + return GP_ERROR_DIRECTORY_NOT_FOUND; + } + + do { + /* Read each entry */ + de = GP_SYSTEM_READDIR(d); + if (de) { + sprintf(buf, "%s%c%s", directory, GP_SYSTEM_DIR_DELIM, GP_SYSTEM_FILENAME(de)); + gp_debug_printf(GP_DEBUG_LOW, "core", "\tis %s a library? ", buf); + /* try to open the library */ + if (is_library(buf) == GP_OK) { + gp_debug_printf(GP_DEBUG_LOW, "core", "yes"); + load_camera_list(buf); + } else { + gp_debug_printf(GP_DEBUG_LOW, "core", "no. reason: %s", GP_SYSTEM_DLERROR()); + } + } + } while (de); + + return (GP_OK); +} + +int load_cameras() { + + int x, y, z; + CameraAbilities *t; + + /* Where should we search for camera libraries? */ + + /* The installed camera library directory */ + load_cameras_search(CAMLIBS); + + /* Current directory */ + /* load_cameras_search("."); */ + + /* Sort the camera list */ + for (x=0; xcount-1; x++) { + for (y=x+1; ycount; y++) { + z = strcmp(glob_abilities_list->abilities[x]->model, + glob_abilities_list->abilities[y]->model); + if (z > 0) { + t = glob_abilities_list->abilities[x]; + glob_abilities_list->abilities[x] = glob_abilities_list->abilities[y]; + glob_abilities_list->abilities[y] = t; + } + } + } + + return GP_OK; +} + int gp_init (int debug) { char buf[1024]; @@ -79,7 +182,6 @@ int gp_init (int debug) /* Initialize the globals */ glob_abilities_list = gp_abilities_list_new(); - glob_setting_count = 0; /* Make sure the directories are created */ gp_debug_printf (GP_DEBUG_LOW, "core", "Creating $HOME/.gphoto"); @@ -176,38 +278,44 @@ void gp_debug_printf (int level, char *id, char *format, ...) } } -int gp_frontend_register (CameraStatus status, CameraProgress progress, - CameraMessage message, CameraConfirm confirm, - CameraPrompt prompt) +int gp_camera_count () { - gp_fe_status = status; - gp_fe_progress = progress; - gp_fe_message = message; - gp_fe_confirm = confirm; - gp_fe_prompt = prompt; - - return (GP_OK); + return (glob_abilities_list->count); } -char *gp_result_as_string (int result) +int gp_camera_name (int camera_number, char *camera_name) { - /* Really an error? */ - if (result > 0) - return _("Unknown error"); + if (glob_abilities_list == NULL) + return (GP_ERROR_MODEL_NOT_FOUND); - /* IOlib error? Pass through. */ - if ((result <= 0) && (result >= -99)) - return gp_port_result_as_string(result); + if (camera_number > glob_abilities_list->count) + return (GP_ERROR_MODEL_NOT_FOUND); - /* Camlib error? You should have called gp_camera_result_as_string... */ - if (result <= -1000) - return _("Unknown camera library error"); - - /* Do we have an error description? */ - if ((-result - 100) < (int) (sizeof (result_string) / - sizeof (*result_string))) - return _(result_string[-result - 100]); - - return _("Unknown error"); + strcpy (camera_name, + glob_abilities_list->abilities[camera_number]->model); + return (GP_OK); } +int gp_camera_abilities (int camera_number, CameraAbilities *abilities) +{ + memcpy (abilities, glob_abilities_list->abilities[camera_number], + sizeof(CameraAbilities)); + + if (glob_debug) + gp_abilities_dump (abilities); + + return (GP_OK); +} + +int gp_camera_abilities_by_name (char *camera_name, CameraAbilities *abilities) +{ + int x; + + for (x = 0; x < glob_abilities_list->count; x++) { + if (strcmp (glob_abilities_list->abilities[x]->model, + camera_name) == 0) + return (gp_camera_abilities(x, abilities)); + } + + return (GP_ERROR_MODEL_NOT_FOUND); +} diff --git a/libgphoto2/file.c b/libgphoto2/file.c index 10b8e4a46..5ea96b923 100644 --- a/libgphoto2/file.c +++ b/libgphoto2/file.c @@ -1,42 +1,65 @@ +/* file.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 "gphoto2-file.h" + #include #include #include -#include -#include "globals.h" +#include "gphoto2-result.h" -CameraFile* gp_file_new () { +static int glob_session_file = 0; +CameraFile* gp_file_new () +{ CameraFile *file; - file = (CameraFile*)malloc(sizeof(CameraFile)); - strcpy(file->type, "unknown/unknown"); - strcpy(file->name, ""); + file = malloc (sizeof (CameraFile)); + strcpy (file->type, "unknown/unknown"); + strcpy (file->name, ""); file->data = NULL; file->size = 0; file->bytes_read = 0; file->session = glob_session_file++; file->ref_count = 1; - return(file); + return (file); } -int gp_file_free (CameraFile *file) { - - gp_file_clean(file); - free(file); - return(GP_OK); +int gp_file_free (CameraFile *file) +{ + gp_file_clean (file); + free (file); + return (GP_OK); } -int gp_file_ref (CameraFile *file) { - +int gp_file_ref (CameraFile *file) +{ file->ref_count += 1; return (GP_OK); } -int gp_file_unref (CameraFile *file) { - +int gp_file_unref (CameraFile *file) +{ if (file == NULL) return GP_ERROR_BAD_PARAMETERS; @@ -48,13 +71,13 @@ int gp_file_unref (CameraFile *file) { return (GP_OK); } -int gp_file_session (CameraFile *file) { - +int gp_file_session (CameraFile *file) +{ return (file->session); } -int gp_file_append (CameraFile *file, char *data, int size) { - +int gp_file_append (CameraFile *file, char *data, int size) +{ char *t; if (size < 0) @@ -76,8 +99,8 @@ int gp_file_append (CameraFile *file, char *data, int size) { return (GP_OK); } -int gp_file_get_last_chunk (CameraFile *file, char **data, int *size) { - +int gp_file_get_last_chunk (CameraFile *file, char **data, int *size) +{ if (file->bytes_read == 0) { /* chunk_add was never called. return safely. */ *data = NULL; @@ -93,8 +116,8 @@ int gp_file_get_last_chunk (CameraFile *file, char **data, int *size) { return (GP_OK); } -int gp_file_save (CameraFile *file, char *filename) { - +int gp_file_save (CameraFile *file, char *filename) +{ FILE *fp; if ((fp = fopen(filename, "wb"))==NULL) @@ -181,12 +204,12 @@ int gp_file_open (CameraFile *file, char *filename) { return (GP_OK); } -int gp_file_clean (CameraFile *file) { - - /* - frees a CameraFile's components, not the CameraFile itself. - this is used to prep a CameraFile struct to be filled. - */ +int gp_file_clean (CameraFile *file) +{ + /* + * Frees a CameraFile's components, not the CameraFile itself. + * This is used to prep a CameraFile struct to be filled. + */ if (file->data != NULL) free(file->data); strcpy(file->name, ""); diff --git a/libgphoto2/frontend.c b/libgphoto2/frontend.c index d3f9ca71c..13e0d51fc 100644 --- a/libgphoto2/frontend.c +++ b/libgphoto2/frontend.c @@ -1,13 +1,46 @@ -#include +/* frontend.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. + */ -#ifdef HAVE_CONFIG_H -#include -#endif +#include "gphoto2-frontend.h" -#include "globals.h" -#include "library.h" -#include "settings.h" -#include "util.h" +#include "gphoto2-result.h" + +/* Front-end function pointers */ +CameraStatus gp_fe_status = NULL; +CameraProgress gp_fe_progress = NULL; +CameraMessage gp_fe_message = NULL; +CameraConfirm gp_fe_confirm = NULL; +CameraPrompt gp_fe_prompt = NULL; + +int gp_frontend_register (CameraStatus status, CameraProgress progress, + CameraMessage message, CameraConfirm confirm, + CameraPrompt prompt) +{ + gp_fe_status = status; + gp_fe_progress = progress; + gp_fe_message = message; + gp_fe_confirm = confirm; + gp_fe_prompt = prompt; + + return (GP_OK); +} int gp_frontend_status (Camera *camera, char *status) { diff --git a/libgphoto2/library.c b/libgphoto2/library.c deleted file mode 100644 index 84e63c41d..000000000 --- a/libgphoto2/library.c +++ /dev/null @@ -1,178 +0,0 @@ -#include -#include -#include - -#include - -#include "globals.h" -#include "library.h" -#include "util.h" - -int is_library(char *library_filename) -{ - int ret = GP_OK; - void *lh; - c_id id; - - if ((lh = GP_SYSTEM_DLOPEN(library_filename)) == NULL) - return (GP_ERROR); - id = (c_id)GP_SYSTEM_DLSYM(lh, "camera_id"); - if (!id) - ret = GP_ERROR; - GP_SYSTEM_DLCLOSE(lh); - - return (ret); -} - -int load_library(Camera *camera) -{ - void *lh; - int x; - - for (x=0; xcount; x++) { - if (strcmp(glob_abilities_list->abilities[x]->model, camera->model)==0) { - if ((lh = GP_SYSTEM_DLOPEN(glob_abilities_list->abilities[x]->library))==NULL) { - if (glob_debug) - perror("core:\tload_library"); - return (GP_ERROR); - } - - camera->library_handle = lh; - camera->functions->id = (c_id)GP_SYSTEM_DLSYM(lh, "camera_id"); - camera->functions->abilities = (c_abilities)GP_SYSTEM_DLSYM(lh, "camera_abilities"); - camera->functions->init = (c_init)GP_SYSTEM_DLSYM(lh, "camera_init"); - - return GP_OK; - } - } - - return GP_ERROR; -} - -/* Returns the number of cameras added to the CameraChoice list */ -/* 0 implies an error occurred */ -int load_camera_list(char *library_filename) -{ - CameraText id; - void *lh; - c_abilities load_camera_abilities; - c_id load_camera_id; - int x, old_count; - - /* try to open the library */ - if ((lh = GP_SYSTEM_DLOPEN(library_filename))==NULL) { - if (glob_debug) - perror("core:\tload_camera_list"); - return 0; - } - - /* check to see if this library has been loaded */ - load_camera_id = (c_id)GP_SYSTEM_DLSYM(lh, "camera_id"); - load_camera_id(&id); - gp_debug_printf(GP_DEBUG_LOW, "core", "\t library id: %s", id.text); - - for (x=0; xcount; x++) { - if (strcmp(glob_abilities_list->abilities[x]->id, id.text)==0) { - GP_SYSTEM_DLCLOSE(lh); - return (GP_ERROR); - } - } - - /* load in the camera_abilities function */ - load_camera_abilities = (c_abilities)GP_SYSTEM_DLSYM(lh, "camera_abilities"); - old_count = glob_abilities_list->count; - - if (load_camera_abilities(glob_abilities_list) != GP_OK) { - GP_SYSTEM_DLCLOSE(lh); - return 0; - } - - /* Copy in the core-specific information */ - for (x=old_count; xcount; x++) { - strcpy(glob_abilities_list->abilities[x]->id, id.text); - strcpy(glob_abilities_list->abilities[x]->library, library_filename); - } - - GP_SYSTEM_DLCLOSE(lh); - - return x; -} - -int load_cameras_search(char *directory) -{ - GP_SYSTEM_DIR d; - GP_SYSTEM_DIRENT de; - char buf[1024]; - - gp_debug_printf(GP_DEBUG_LOW, "core","Trying to load camera libraries in:"); - gp_debug_printf(GP_DEBUG_LOW, "core","\t%s", directory); - - /* Look for available camera libraries */ - d = GP_SYSTEM_OPENDIR(directory); - if (!d) { - gp_debug_printf(GP_DEBUG_LOW, "core", "couldn't open %s", directory); - return GP_ERROR_DIRECTORY_NOT_FOUND; - } - - do { - /* Read each entry */ - de = GP_SYSTEM_READDIR(d); - if (de) { - sprintf(buf, "%s%c%s", directory, GP_SYSTEM_DIR_DELIM, GP_SYSTEM_FILENAME(de)); - gp_debug_printf(GP_DEBUG_LOW, "core", "\tis %s a library? ", buf); - /* try to open the library */ - if (is_library(buf) == GP_OK) { - gp_debug_printf(GP_DEBUG_LOW, "core", "yes"); - load_camera_list(buf); - } else { - gp_debug_printf(GP_DEBUG_LOW, "core", "no. reason: %s", GP_SYSTEM_DLERROR()); - } - } - } while (de); - - return (GP_OK); -} - -int load_cameras() { - - int x, y, z; - CameraAbilities *t; - - /* Where should we search for camera libraries? */ - - /* The installed camera library directory */ - load_cameras_search(CAMLIBS); - - /* Current directory */ - /* load_cameras_search("."); */ - - /* Sort the camera list */ - for (x=0; xcount-1; x++) { - for (y=x+1; ycount; y++) { - z = strcmp(glob_abilities_list->abilities[x]->model, - glob_abilities_list->abilities[y]->model); - if (z > 0) { - t = glob_abilities_list->abilities[x]; - glob_abilities_list->abilities[x] = glob_abilities_list->abilities[y]; - glob_abilities_list->abilities[y] = t; - } - } - } - -/* MUCH too verbose. - if (glob_debug) { - gp_debug_printf(GP_DEBUG_LOW, "core", "Loaded camera list"); - gp_abilities_list_dump(glob_abilities_list); - } -*/ - - return GP_OK; -} - -int close_library(Camera *camera) -{ - GP_SYSTEM_DLCLOSE(camera->library_handle); - - return GP_OK; -} - diff --git a/libgphoto2/library.h b/libgphoto2/library.h deleted file mode 100644 index b7a46cd73..000000000 --- a/libgphoto2/library.h +++ /dev/null @@ -1,4 +0,0 @@ -int load_cameras(); -int is_library (char *library_filename); -int load_library (Camera *camera); -int close_library (Camera *camera); diff --git a/libgphoto2/list.c b/libgphoto2/list.c new file mode 100644 index 000000000..dfb818a0e --- /dev/null +++ b/libgphoto2/list.c @@ -0,0 +1,64 @@ +/* list.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 "gphoto2-list.h" + +#include +#include + +#include "gphoto2-result.h" + +CameraList *gp_list_new () +{ + CameraList *list; + + list = (CameraList*)malloc (sizeof (CameraList)); + if (!list) + return NULL; + + memset (list, 0, sizeof (CameraList)); + return (list); +} + +int gp_list_free (CameraList *list) +{ + if (list) + free (list); + return (GP_OK); +} + +int gp_list_append (CameraList *list, char *name) +{ + strcpy (list->entry[list->count].name, name); + + list->count += 1; + + return (GP_OK); +} + +int gp_list_count (CameraList *list) +{ + return (list->count); +} + +CameraListEntry *gp_list_entry (CameraList *list, int entrynum) +{ + return (&list->entry [entrynum]); +} diff --git a/libgphoto2/lists.c b/libgphoto2/lists.c deleted file mode 100644 index 8d3809f53..000000000 --- a/libgphoto2/lists.c +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include -#include - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "util.h" - -CameraList *gp_list_new () -{ - CameraList *list; - - list = (CameraList*)malloc (sizeof (CameraList)); - if (!list) - return NULL; - - memset (list, 0, sizeof (CameraList)); - return (list); -} - -int gp_list_free (CameraList *list) -{ - if (list) - free (list); - return (GP_OK); -} - -int gp_list_append (CameraList *list, char *name) -{ - strcpy (list->entry[list->count].name, name); - - list->count += 1; - - return (GP_OK); -} - -int gp_list_count (CameraList *list) -{ - return (list->count); -} - -CameraListEntry *gp_list_entry (CameraList *list, int entrynum) -{ - return (&list->entry[entrynum]); -} - -CameraAbilities *gp_abilities_new () -{ - CameraAbilities *abilities; - - abilities = (CameraAbilities*)malloc (sizeof(CameraAbilities)); - if (!abilities) - return (NULL); - - return (abilities); -} - -int gp_abilities_free (CameraAbilities *abilities) -{ - free (abilities); - - return (GP_OK); -} - - -CameraAbilitiesList *gp_abilities_list_new () -{ - CameraAbilitiesList *list; - - list = (CameraAbilitiesList*)malloc (sizeof (CameraAbilitiesList)); - if (!list) - return (NULL); - list->count = 0; - list->abilities = NULL; - - return (list); -} - -int gp_abilities_list_free (CameraAbilitiesList *list) -{ - int x; - - /* TODO: OS/2 Port crashes here... maybe compiler setting */ - - - for (x = 0; x < list->count; x++) - free (list->abilities[x]); - - free (list); - return (GP_OK); -} - -int gp_abilities_list_dump (CameraAbilitiesList *list) -{ - int x; - - for (x = 0; x < list->count; x++) { - gp_debug_printf (GP_DEBUG_LOW, "core", "Camera #%i:", x); - gp_abilities_dump (list->abilities[x]); - } - - return (GP_OK); -} - -int gp_abilities_list_append (CameraAbilitiesList *list, - CameraAbilities *abilities) -{ - if (!list->abilities) - list->abilities = (CameraAbilities**)malloc ( - sizeof (CameraAbilities*)); - else - list->abilities = (CameraAbilities**)realloc (list->abilities, - sizeof (CameraAbilities*) * (list->count + 1)); - if (!list->abilities) - return (GP_ERROR_NO_MEMORY); - - list->abilities[list->count] = abilities; - list->count += 1; - - return (GP_OK); -} diff --git a/libgphoto2/port.c b/libgphoto2/port.c deleted file mode 100644 index 9353f3a57..000000000 --- a/libgphoto2/port.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -#ifdef HAVE_CONFIG_H -#include -#endif - -/* deprecated with libgphoto2_port */ \ No newline at end of file diff --git a/libgphoto2/result.c b/libgphoto2/result.c new file mode 100644 index 000000000..06e23d732 --- /dev/null +++ b/libgphoto2/result.c @@ -0,0 +1,73 @@ +/* gphoto2-result.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 "gphoto2-result.h" + +#include +#ifdef ENABLE_NLS +# include +# undef _ +# define _(String) dgettext (PACKAGE, String) +# ifdef gettext_noop +# define N_(String) gettext_noop (String) +# else +# define N_(String) (String) +# endif +#else +# define _(String) (String) +# define N_(String) (String) +#endif + +static char *result_string[] = { + /* GP_ERROR_BAD_PARAMETERS -100 */ N_("Bad parameters"), + /* GP_ERROR_IO -101 */ N_("I/O problem"), + /* GP_ERROR_CORRUPTED_DATA -102 */ N_("Corrupted data"), + /* GP_ERROR_FILE_EXISTS -103 */ N_("File exists"), + /* GP_ERROR_NO_MEMORY -104 */ N_("Insufficient memory"), + /* GP_ERROR_MODEL_NOT_FOUND -105 */ N_("Unknown model"), + /* GP_ERROR_NOT_SUPPORTED -106 */ N_("Unsupported operation"), + /* GP_ERROR_DIRECTORY_NOT_FOUND -107 */ N_("Directory not found"), + /* GP_ERROR_FILE_NOT_FOUND -108 */ N_("File not found"), + /* GP_ERROR_DIRECTORY_EXISTS -109 */ N_("Directory exists"), + /* GP_ERROR_NO_CAMERA_FOUND -110 */ N_("No cameras were detected") +}; + +char * +gp_result_as_string (int result) +{ + /* Really an error? */ + if (result > 0) + return _("Unknown error"); + + /* IOlib error? Pass through. */ + if ((result <= 0) && (result >= -99)) + return gp_port_result_as_string (result); + + /* Camlib error? You should have called gp_camera_result_as_string... */ + if (result <= -1000) + return _("Unknown camera library error"); + + /* Do we have an error description? */ + if ((-result - 100) < (int) (sizeof (result_string) / + sizeof (*result_string))) + return _(result_string [-result - 100]); + + return _("Unknown error"); +} diff --git a/libgphoto2/settings.c b/libgphoto2/setting.c similarity index 73% rename from libgphoto2/settings.c rename to libgphoto2/setting.c index 3943a8f9f..88bfc9bf6 100644 --- a/libgphoto2/settings.c +++ b/libgphoto2/setting.c @@ -1,12 +1,47 @@ +/* setting.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 "gphoto2-setting.h" + #include #include #include -#include +#include "gphoto2-result.h" +#include "gphoto2-core.h" -#include "settings.h" -#include "globals.h" -#include "util.h" +typedef struct { + /* key = value settings */ + char id[256]; + char key[256]; + char value[256]; +} Setting; + +/* Currently loaded settings */ +int glob_setting_count = 0; +Setting glob_setting[512]; + +extern int glob_debug; + +static int save_settings (void); +static int dump_settings (void); int gp_setting_get (char *id, char *key, char *value) { @@ -40,20 +75,20 @@ int gp_setting_set (char *id, char *key, char *value) if ((strcmp(glob_setting[x].id, id)==0) && (strcmp(glob_setting[x].key, key)==0)) { strcpy(glob_setting[x].value, value); - save_settings(glob_setting, glob_setting_count); + save_settings (); return (GP_OK); } } strcpy(glob_setting[glob_setting_count].id, id); strcpy(glob_setting[glob_setting_count].key, key); strcpy(glob_setting[glob_setting_count++].value, value); - save_settings(glob_setting, glob_setting_count); + save_settings (); return (GP_OK); } -int verify_settings (char *settings_file) { - +int verify_settings (char *settings_file) +{ FILE *f; char buf[1024]; int x, equals; @@ -87,8 +122,8 @@ int verify_settings (char *settings_file) { return (GP_OK); } -int load_settings () { - +int load_settings (void) +{ FILE *f; char buf[1024], *id, *key, *value; @@ -128,14 +163,15 @@ int load_settings () { } } if (glob_debug) - dump_settings(); + dump_settings (); return (GP_OK); } -int save_settings () { - +static int +save_settings (void) +{ FILE *f; char buf[1024]; int x=0; @@ -163,9 +199,10 @@ int save_settings () { return (GP_OK); } -int dump_settings () { - +static int dump_settings (void) +{ int x; + gp_debug_printf(GP_DEBUG_LOW, "core", "All settings:"); for (x=0; x +#include +#include #include #define CHECK(f) {int res = f; if (res < 0) {printf ("ERROR: %s\n", gp_result_as_string (res)); exit (1);}}