organizing code
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@1014 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
## Process this file with automake to generate a GNU Makefile
|
||||
|
||||
gphotoheaddir = $(prefix)/include/gphoto2
|
||||
gphotohead_HEADERS= gphoto2.h \
|
||||
gphoto2-core.h \
|
||||
gphoto2-datatypes.h \
|
||||
gphoto2-interface.h \
|
||||
gphoto2-library.h
|
||||
gphotohead_HEADERS= \
|
||||
gphoto2.h \
|
||||
gphoto2-camera.h \
|
||||
gphoto2-core.h \
|
||||
gphoto2-datatypes.h \
|
||||
gphoto2-file.h \
|
||||
gphoto2-filesys.h \
|
||||
gphoto2-library.h \
|
||||
gphoto2-lists.h \
|
||||
gphoto2-settings.h \
|
||||
gphoto2-widget.h
|
||||
|
||||
42
include/gphoto2-camera.h
Normal file
42
include/gphoto2-camera.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Header file for gPhoto2
|
||||
|
||||
Author: Scott Fritzinger <scottf@unr.edu>
|
||||
|
||||
This library is covered by the LGPL.
|
||||
*/
|
||||
|
||||
int gp_camera_count ();
|
||||
int gp_camera_name (int camera_number, char *camera_name);
|
||||
|
||||
int gp_camera_abilities (int camera_number, CameraAbilities *abilities);
|
||||
int gp_camera_abilities_by_name (char *camera_name, CameraAbilities *abilities);
|
||||
|
||||
int gp_camera_new (Camera **camera, int camera_number, CameraPortInfo *port);
|
||||
int gp_camera_new_by_name (Camera **camera, char *camera_name, CameraPortInfo *port);
|
||||
|
||||
int gp_camera_free (Camera *camera);
|
||||
|
||||
int gp_camera_folder_list (Camera *camera, CameraList *list, char *folder);
|
||||
int gp_camera_file_list (Camera *camera, CameraList *list, char *folder);
|
||||
|
||||
int gp_camera_file_get (Camera *camera, CameraFile *file,
|
||||
char *folder, char *filename);
|
||||
int gp_camera_file_get_preview (Camera *camera, CameraFile *file,
|
||||
char *folder, char *filename);
|
||||
|
||||
int gp_camera_file_put (Camera *camera, CameraFile *file, char *folder);
|
||||
int gp_camera_file_delete (Camera *camera, char *folder, char *filename);
|
||||
|
||||
int gp_camera_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info);
|
||||
|
||||
int gp_camera_summary (Camera *camera, CameraText *summary);
|
||||
int gp_camera_manual (Camera *camera, CameraText *manual);
|
||||
int gp_camera_about (Camera *camera, CameraText *about);
|
||||
|
||||
int gp_camera_config_get (Camera *camera, CameraWidget *window);
|
||||
int gp_camera_config_set (Camera *camera, CameraSetting *setting, int count);
|
||||
|
||||
int gp_camera_status (Camera *camera, char *status);
|
||||
int gp_camera_message (Camera *camera, char *message);
|
||||
int gp_camera_confirm (Camera *camera, char *message);
|
||||
int gp_camera_progress (Camera *camera, CameraFile *file, float percentage);
|
||||
@@ -184,6 +184,8 @@ typedef struct {
|
||||
long int size;
|
||||
char *data;
|
||||
int bytes_read;
|
||||
|
||||
int session;
|
||||
} CameraFile;
|
||||
|
||||
/* Entry in a folder on the camera */
|
||||
@@ -279,6 +281,8 @@ typedef struct Camera {
|
||||
|
||||
void *camlib_data;
|
||||
void *frontend_data;
|
||||
|
||||
int session;
|
||||
} Camera;
|
||||
|
||||
/* Interface function pointers */
|
||||
|
||||
17
include/gphoto2-file.h
Normal file
17
include/gphoto2-file.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/* Header file for gPhoto2
|
||||
|
||||
Author: Scott Fritzinger <scottf@unr.edu>
|
||||
|
||||
This library is covered by the LGPL.
|
||||
*/
|
||||
|
||||
CameraFile* gp_file_new ();
|
||||
|
||||
int gp_file_save (CameraFile *file, char *filename);
|
||||
int gp_file_open (CameraFile *file, char *filename);
|
||||
|
||||
int gp_file_clean (CameraFile *file);
|
||||
int gp_file_free (CameraFile *file);
|
||||
|
||||
int gp_file_append (CameraFile *file, char *data, int size);
|
||||
int gp_file_get_last_chunk (CameraFile *file, char **data, int *size);
|
||||
32
include/gphoto2-filesys.h
Normal file
32
include/gphoto2-filesys.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* Header file for gPhoto2
|
||||
|
||||
Author: Scott Fritzinger <scottf@unr.edu>
|
||||
|
||||
This library is covered by the LGPL.
|
||||
*/
|
||||
|
||||
|
||||
/* NOTE: These functions are provided for cameras that do not support filenames. */
|
||||
/* This sets up an emulation layer to let those cameras work properly with the */
|
||||
/* filename-centric gPhoto2 API. */
|
||||
|
||||
CameraFilesystem* gp_filesystem_new ();
|
||||
int gp_filesystem_free (CameraFilesystem *fs);
|
||||
|
||||
int gp_filesystem_populate (CameraFilesystem *fs, char *folder,
|
||||
char *format, int count);
|
||||
|
||||
int gp_filesystem_append (CameraFilesystem *fs, char *folder,
|
||||
char *filename);
|
||||
|
||||
int gp_filesystem_format (CameraFilesystem *fs);
|
||||
int gp_filesystem_delete (CameraFilesystem *fs, char *folder,
|
||||
char *filename);
|
||||
|
||||
int gp_filesystem_count (CameraFilesystem *fs, char *folder);
|
||||
|
||||
|
||||
char* gp_filesystem_name (CameraFilesystem *fs, char *folder,
|
||||
int filenumber);
|
||||
int gp_filesystem_number (CameraFilesystem *fs, char *folder,
|
||||
char *filename);
|
||||
@@ -1,22 +0,0 @@
|
||||
/* Header file for gPhoto 0.5-Dev
|
||||
|
||||
Author: Scott Fritzinger <scottf@unr.edu>
|
||||
|
||||
This library is covered by the LGPL.
|
||||
*/
|
||||
|
||||
|
||||
/* Functions required to be provided by the front-end interface
|
||||
---------------------------------------------------------------- */
|
||||
|
||||
/* Displays the current status on an operation in the camera */
|
||||
int gp_interface_status (Camera *camera, char *status);
|
||||
|
||||
/* Displays a percentage done in the current operation */
|
||||
int gp_interface_progress (Camera *camera, CameraFile *file, float percentage);
|
||||
|
||||
/* Displays a message (error, very important info) */
|
||||
int gp_interface_message (Camera *camera, char *message);
|
||||
|
||||
/* Displays a configuration */
|
||||
int gp_interface_confirm (Camera *camera, char *message);
|
||||
26
include/gphoto2-lists.h
Normal file
26
include/gphoto2-lists.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/* Header file for gPhoto2
|
||||
|
||||
Author: Scott Fritzinger <scottf@unr.edu>
|
||||
|
||||
This library is covered by the LGPL.
|
||||
*/
|
||||
|
||||
CameraList* gp_list_new ();
|
||||
int gp_list_free (CameraList *list);
|
||||
|
||||
int gp_list_count (CameraList *list);
|
||||
|
||||
int gp_list_append (CameraList *list, char *name, CameraListType type);
|
||||
|
||||
CameraListEntry* gp_list_entry (CameraList *list, int entrynum);
|
||||
|
||||
CameraAbilities* gp_abilities_new ();
|
||||
int gp_abilities_free (CameraAbilities *abilities);
|
||||
|
||||
CameraAbilitiesList* gp_abilities_list_new ();
|
||||
int gp_abilities_list_free (CameraAbilitiesList *list);
|
||||
|
||||
int gp_abilities_list_dump (CameraAbilitiesList *list);
|
||||
|
||||
int gp_abilities_list_append (CameraAbilitiesList *list,
|
||||
CameraAbilities *abilities);
|
||||
11
include/gphoto2-settings.h
Normal file
11
include/gphoto2-settings.h
Normal file
@@ -0,0 +1,11 @@
|
||||
/* Header file for gPhoto2
|
||||
|
||||
Author: Scott Fritzinger <scottf@unr.edu>
|
||||
|
||||
This library is covered by the LGPL.
|
||||
*/
|
||||
|
||||
|
||||
int gp_setting_set (char *id, char *key, char *value);
|
||||
|
||||
int gp_setting_get (char *id, char *key, char *value);
|
||||
34
include/gphoto2-widget.h
Normal file
34
include/gphoto2-widget.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* Header file for gPhoto2
|
||||
|
||||
Author: Scott Fritzinger <scottf@unr.edu>
|
||||
|
||||
This library is covered by the LGPL.
|
||||
*/
|
||||
|
||||
CameraWidget* gp_widget_new (CameraWidgetType type, char *label);
|
||||
int gp_widget_free (CameraWidget *widget);
|
||||
|
||||
int gp_widget_append (CameraWidget *parent, CameraWidget *child);
|
||||
int gp_widget_prepend (CameraWidget *parent, CameraWidget *child);
|
||||
|
||||
int gp_widget_child_count(CameraWidget *parent);
|
||||
|
||||
CameraWidget* gp_widget_child(CameraWidget *parent, int child_number);
|
||||
CameraWidget* gp_widget_child_by_label(CameraWidget *parent, char *child_label);
|
||||
|
||||
int gp_widget_type (CameraWidget *widget);
|
||||
char* gp_widget_label(CameraWidget *widget);
|
||||
|
||||
int gp_widget_value_set (CameraWidget *widget, char *value);
|
||||
char* gp_widget_value_get (CameraWidget *widget);
|
||||
|
||||
int gp_widget_range_set (CameraWidget *range, float low, float high,
|
||||
float increment);
|
||||
int gp_widget_range_get (CameraWidget *range, float *low, float *high,
|
||||
float *increment);
|
||||
|
||||
int gp_widget_choice_add (CameraWidget *widget, char *choice);
|
||||
int gp_widget_choice_count (CameraWidget *widget);
|
||||
char* gp_widget_choice (CameraWidget *widget, int choice_number);
|
||||
|
||||
int gp_widget_dump (CameraWidget *widget);
|
||||
@@ -18,7 +18,13 @@
|
||||
|
||||
#include <gpio.h>
|
||||
#include <gphoto2-datatypes.h>
|
||||
#include <gphoto2-camera.h>
|
||||
#include <gphoto2-core.h>
|
||||
#include <gphoto2-file.h>
|
||||
#include <gphoto2-filesys.h>
|
||||
#include <gphoto2-library.h>
|
||||
#include <gphoto2-lists.h>
|
||||
#include <gphoto2-settings.h>
|
||||
#include <gphoto2-widget.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,15 +12,18 @@ LDFLAGS = @LDFLAGS@ -g `gpio-config --libs`
|
||||
|
||||
libgphoto2_la_LDFLAGS = -version-info 0:0:0
|
||||
libgphoto2_la_SOURCES = \
|
||||
core.c core.h \
|
||||
exif.c exif.h \
|
||||
fs.c fs.h \
|
||||
file.c file.h \
|
||||
globals.h \
|
||||
library.c library.h \
|
||||
settings.c settings.h \
|
||||
util.c util.h \
|
||||
widget.c widget.h
|
||||
camera.c \
|
||||
core.c core.h \
|
||||
exif.c exif.h \
|
||||
file.c \
|
||||
filesys.c \
|
||||
globals.h \
|
||||
library.c library.h \
|
||||
lists.c \
|
||||
port.c \
|
||||
settings.c settings.h \
|
||||
util.c util.h \
|
||||
widget.c
|
||||
|
||||
confexecdir = $(libdir)
|
||||
confexec_DATA = libgphoto2Conf.sh
|
||||
|
||||
349
libgphoto2/camera.c
Normal file
349
libgphoto2/camera.c
Normal file
@@ -0,0 +1,349 @@
|
||||
#include <gpio.h>
|
||||
#include <gphoto2.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "globals.h"
|
||||
#include "library.h"
|
||||
#include "settings.h"
|
||||
#include "util.h"
|
||||
|
||||
int gp_camera_init (Camera *camera, CameraInit *init);
|
||||
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 (camera_number > glob_abilities_list->count)
|
||||
return (GP_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=0;
|
||||
while (x < glob_abilities_list->count) {
|
||||
if (strcmp(glob_abilities_list->abilities[x]->model, camera_name)==0)
|
||||
return (gp_camera_abilities(x, abilities));
|
||||
x++;
|
||||
}
|
||||
|
||||
return (GP_ERROR);
|
||||
|
||||
}
|
||||
|
||||
int gp_camera_new (Camera **camera, int camera_number, CameraPortInfo *settings)
|
||||
{
|
||||
|
||||
CameraInit ci;
|
||||
|
||||
if (camera_number >= glob_abilities_list->count)
|
||||
return (GP_ERROR);
|
||||
|
||||
*camera = (Camera*)malloc(sizeof(Camera));
|
||||
|
||||
/* Initialize the members */
|
||||
strcpy((*camera)->model, glob_abilities_list->abilities[camera_number]->model);
|
||||
(*camera)->debug = glob_debug;
|
||||
(*camera)->port = (CameraPortInfo*)malloc(sizeof(CameraPortInfo));
|
||||
(*camera)->abilities = (CameraAbilities*)malloc(sizeof(CameraAbilities));
|
||||
(*camera)->functions = (CameraFunctions*)malloc(sizeof(CameraFunctions));
|
||||
(*camera)->library_handle = NULL;
|
||||
(*camera)->camlib_data = NULL;
|
||||
(*camera)->frontend_data = NULL;
|
||||
|
||||
memcpy((*camera)->port, settings, sizeof(CameraPortInfo));
|
||||
|
||||
(*camera)->session = glob_session_camera++;
|
||||
|
||||
if (load_library(*camera, glob_abilities_list->abilities[camera_number]->model)==GP_ERROR) {
|
||||
gp_camera_free(*camera);
|
||||
return (GP_ERROR);
|
||||
}
|
||||
|
||||
/* Initialize the camera library */
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "Initializing \"%s\" (%s)...",
|
||||
glob_abilities_list->abilities[camera_number]->model,
|
||||
glob_abilities_list->abilities[camera_number]->library);
|
||||
strcpy(ci.model, glob_abilities_list->abilities[camera_number]->model);
|
||||
memcpy(&ci.port_settings, settings, sizeof(CameraPortInfo));
|
||||
|
||||
if (gp_camera_init(*camera, &ci)==GP_ERROR) {
|
||||
gp_camera_free(*camera);
|
||||
*camera=NULL;
|
||||
return (GP_ERROR);
|
||||
}
|
||||
|
||||
return(GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_free(Camera *camera)
|
||||
{
|
||||
gp_camera_exit(camera);
|
||||
|
||||
if (camera->port)
|
||||
free(camera->port);
|
||||
if (camera->abilities)
|
||||
free(camera->abilities);
|
||||
if (camera->functions)
|
||||
free(camera->functions);
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_new_by_name (Camera **camera, char *camera_name, CameraPortInfo *settings)
|
||||
{
|
||||
int x=0;
|
||||
|
||||
while (x < glob_abilities_list->count) {
|
||||
if (strcmp(glob_abilities_list->abilities[x]->model, camera_name)==0)
|
||||
return (gp_camera_new(camera, x, settings));
|
||||
x++;
|
||||
}
|
||||
|
||||
return (GP_ERROR);
|
||||
}
|
||||
|
||||
int gp_camera_init (Camera *camera, CameraInit *init)
|
||||
{
|
||||
int x;
|
||||
CameraPortInfo info;
|
||||
|
||||
if (camera->functions->init == NULL)
|
||||
return(GP_ERROR);
|
||||
|
||||
for (x=0; x<gp_port_count(); x++) {
|
||||
gp_port_info(x, &info);
|
||||
if (strcmp(info.path, init->port_settings.path)==0)
|
||||
init->port_settings.type = info.type;
|
||||
}
|
||||
|
||||
return(camera->functions->init(camera, init));
|
||||
}
|
||||
|
||||
int gp_camera_exit (Camera *camera)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (camera->functions->exit == NULL)
|
||||
return(GP_ERROR);
|
||||
|
||||
ret = camera->functions->exit(camera);
|
||||
close_library(camera);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int gp_camera_folder_list(Camera *camera, CameraList *list, char *folder)
|
||||
{
|
||||
CameraListEntry t;
|
||||
int x, ret, y, z;
|
||||
|
||||
/* Initialize the folder list to a known state */
|
||||
list->count = 0;
|
||||
|
||||
if (camera->functions->folder_list == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
ret = camera->functions->folder_list(camera, list, folder);
|
||||
|
||||
if (ret == GP_ERROR)
|
||||
return (GP_ERROR);
|
||||
|
||||
/* Sort the folder list */
|
||||
for (x=0; x<list->count-1; x++) {
|
||||
for (y=x+1; y<list->count; y++) {
|
||||
z = strcmp(list->entry[x].name, list->entry[y].name);
|
||||
if (z > 0) {
|
||||
memcpy(&t, &list->entry[x], sizeof(t));
|
||||
memcpy(&list->entry[x], &list->entry[y], sizeof(t));
|
||||
memcpy(&list->entry[y], &t, sizeof(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_file_list(Camera *camera, CameraList *list, char *folder)
|
||||
{
|
||||
CameraListEntry t;
|
||||
int x, ret, y, z;
|
||||
|
||||
/* Initialize the folder list to a known state */
|
||||
list->count = 0;
|
||||
|
||||
if (camera->functions->file_list == NULL)
|
||||
return (GP_ERROR);
|
||||
ret = camera->functions->file_list(camera, list, folder);
|
||||
if (ret == GP_ERROR)
|
||||
return (GP_ERROR);
|
||||
|
||||
/* Sort the file list */
|
||||
for (x=0; x<list->count-1; x++) {
|
||||
for (y=x+1; y<list->count; y++) {
|
||||
z = strcmp(list->entry[x].name, list->entry[y].name);
|
||||
if (z > 0) {
|
||||
memcpy(&t, &list->entry[x], sizeof(t));
|
||||
memcpy(&list->entry[x], &list->entry[y], sizeof(t));
|
||||
memcpy(&list->entry[y], &t, sizeof(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_file_get (Camera *camera, CameraFile *file,
|
||||
char *folder, char *filename)
|
||||
{
|
||||
if (camera->functions->file_get == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
gp_file_clean(file);
|
||||
|
||||
return (camera->functions->file_get(camera, file, folder, filename));
|
||||
}
|
||||
|
||||
int gp_camera_file_get_preview (Camera *camera, CameraFile *file,
|
||||
char *folder, char *filename)
|
||||
{
|
||||
if (camera->functions->file_get_preview == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
gp_file_clean(file);
|
||||
|
||||
return (camera->functions->file_get_preview(camera, file, folder, filename));
|
||||
}
|
||||
|
||||
int gp_camera_file_put (Camera *camera, CameraFile *file, char *folder)
|
||||
{
|
||||
if (camera->functions->file_put == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
return (camera->functions->file_put(camera, file, folder));
|
||||
}
|
||||
|
||||
int gp_camera_file_delete (Camera *camera, char *folder, char *filename)
|
||||
{
|
||||
|
||||
if (camera->functions->file_delete == NULL)
|
||||
return (GP_ERROR);
|
||||
return (camera->functions->file_delete(camera, folder, filename));
|
||||
}
|
||||
|
||||
int gp_camera_config_get (Camera *camera, CameraWidget *window)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (camera->functions->config_get == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
ret = camera->functions->config_get(camera, window);
|
||||
|
||||
if (glob_debug)
|
||||
gp_widget_dump(window);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int gp_camera_config_set (Camera *camera, CameraSetting *setting, int count)
|
||||
{
|
||||
int x;
|
||||
|
||||
if (glob_debug) {
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "Dumping CameraSetting");
|
||||
for (x=0; x<count; x++)
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "\"%s\" = \"%s\"", setting[x].name, setting[x].value);
|
||||
}
|
||||
|
||||
if (camera->functions->config_set == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
return(camera->functions->config_set(camera, setting, count));
|
||||
}
|
||||
|
||||
int gp_camera_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info)
|
||||
{
|
||||
if (camera->functions->capture == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
gp_file_clean(file);
|
||||
|
||||
return(camera->functions->capture(camera, file, info));
|
||||
}
|
||||
|
||||
int gp_camera_summary (Camera *camera, CameraText *summary)
|
||||
{
|
||||
if (camera->functions->summary == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
return(camera->functions->summary(camera, summary));
|
||||
}
|
||||
|
||||
int gp_camera_manual (Camera *camera, CameraText *manual)
|
||||
{
|
||||
if (camera->functions->manual == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
return(camera->functions->manual(camera, manual));
|
||||
}
|
||||
|
||||
int gp_camera_about (Camera *camera, CameraText *about)
|
||||
{
|
||||
if (camera->functions->about == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
return(camera->functions->about(camera, about));
|
||||
}
|
||||
|
||||
int gp_camera_status (Camera *camera, char *status)
|
||||
{
|
||||
if (gp_fe_status)
|
||||
gp_fe_status(camera, status);
|
||||
return(GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_progress (Camera *camera, CameraFile *file, float percentage)
|
||||
{
|
||||
if (gp_fe_progress)
|
||||
gp_fe_progress(camera, file, percentage);
|
||||
|
||||
return(GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_message (Camera *camera, char *message)
|
||||
{
|
||||
if (gp_fe_message)
|
||||
gp_fe_message(camera, message);
|
||||
return(GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_confirm (Camera *camera, char *message)
|
||||
{
|
||||
if (!gp_fe_confirm)
|
||||
/* return YES. dangerous? */
|
||||
return 1;
|
||||
return(gp_fe_confirm(camera, message));
|
||||
}
|
||||
@@ -1,16 +1,5 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <direct.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <gpio.h>
|
||||
#include <gphoto2.h>
|
||||
@@ -24,31 +13,27 @@
|
||||
#include "settings.h"
|
||||
#include "util.h"
|
||||
|
||||
/* Some globals
|
||||
---------------------------------------------------------------- */
|
||||
|
||||
/* Debug level */
|
||||
int glob_debug=0;
|
||||
|
||||
/* Camera List */
|
||||
/* ------------------------------------------------ */
|
||||
CameraAbilitiesList *glob_abilities_list;
|
||||
|
||||
/* Currently loaded settings */
|
||||
/* ------------------------------------------------ */
|
||||
int glob_setting_count = 0;
|
||||
Setting glob_setting[512];
|
||||
|
||||
/* Core functions (for front-ends)
|
||||
---------------------------------------------------------------- */
|
||||
|
||||
int gp_camera_init (Camera *camera, CameraInit *init);
|
||||
int gp_camera_exit (Camera *camera);
|
||||
/* 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;
|
||||
|
||||
|
||||
int gp_init (int debug)
|
||||
{
|
||||
char buf[1024];
|
||||
@@ -123,437 +108,6 @@ void gp_debug_printf(int level, char *id, char *format, ...)
|
||||
}
|
||||
}
|
||||
|
||||
int gp_port_count()
|
||||
{
|
||||
return (gpio_get_device_count());
|
||||
}
|
||||
|
||||
int gp_port_info(int port_number, CameraPortInfo *info)
|
||||
{
|
||||
gpio_device_info i;
|
||||
|
||||
if (gpio_get_device_info(port_number, &i)==GPIO_ERROR)
|
||||
return (GP_ERROR);
|
||||
|
||||
/* Translate to gPhoto types */
|
||||
switch (i.type) {
|
||||
case GPIO_DEVICE_SERIAL:
|
||||
info->type = GP_PORT_SERIAL;
|
||||
break;
|
||||
case GPIO_DEVICE_PARALLEL:
|
||||
info->type = GP_PORT_PARALLEL;
|
||||
break;
|
||||
case GPIO_DEVICE_USB:
|
||||
info->type = GP_PORT_USB;
|
||||
break;
|
||||
case GPIO_DEVICE_IEEE1394:
|
||||
info->type = GP_PORT_IEEE1394;
|
||||
break;
|
||||
case GPIO_DEVICE_NETWORK:
|
||||
info->type = GP_PORT_NETWORK;
|
||||
break;
|
||||
default:
|
||||
info->type = GP_PORT_NONE;
|
||||
}
|
||||
strcpy(info->name, i.name);
|
||||
strcpy(info->path, i.path);
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_count ()
|
||||
{
|
||||
return(glob_abilities_list->count);
|
||||
}
|
||||
|
||||
int gp_camera_name (int camera_number, char *camera_name)
|
||||
{
|
||||
if (camera_number > glob_abilities_list->count)
|
||||
return (GP_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=0;
|
||||
while (x < glob_abilities_list->count) {
|
||||
if (strcmp(glob_abilities_list->abilities[x]->model, camera_name)==0)
|
||||
return (gp_camera_abilities(x, abilities));
|
||||
x++;
|
||||
}
|
||||
|
||||
return (GP_ERROR);
|
||||
|
||||
}
|
||||
|
||||
int gp_camera_new (Camera **camera, int camera_number, CameraPortInfo *settings)
|
||||
{
|
||||
|
||||
CameraInit ci;
|
||||
|
||||
if (camera_number >= glob_abilities_list->count)
|
||||
return (GP_ERROR);
|
||||
|
||||
*camera = (Camera*)malloc(sizeof(Camera));
|
||||
|
||||
/* Initialize the members */
|
||||
strcpy((*camera)->model, glob_abilities_list->abilities[camera_number]->model);
|
||||
(*camera)->debug = glob_debug;
|
||||
(*camera)->port = (CameraPortInfo*)malloc(sizeof(CameraPortInfo));
|
||||
(*camera)->abilities = (CameraAbilities*)malloc(sizeof(CameraAbilities));
|
||||
(*camera)->functions = (CameraFunctions*)malloc(sizeof(CameraFunctions));
|
||||
(*camera)->library_handle = NULL;
|
||||
(*camera)->camlib_data = NULL;
|
||||
(*camera)->frontend_data = NULL;
|
||||
|
||||
memcpy((*camera)->port, settings, sizeof(CameraPortInfo));
|
||||
|
||||
if (load_library(*camera, glob_abilities_list->abilities[camera_number]->model)==GP_ERROR) {
|
||||
gp_camera_free(*camera);
|
||||
return (GP_ERROR);
|
||||
}
|
||||
|
||||
/* Initialize the camera library */
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "Initializing \"%s\" (%s)...",
|
||||
glob_abilities_list->abilities[camera_number]->model,
|
||||
glob_abilities_list->abilities[camera_number]->library);
|
||||
strcpy(ci.model, glob_abilities_list->abilities[camera_number]->model);
|
||||
memcpy(&ci.port_settings, settings, sizeof(CameraPortInfo));
|
||||
|
||||
if (gp_camera_init(*camera, &ci)==GP_ERROR) {
|
||||
gp_camera_free(*camera);
|
||||
*camera=NULL;
|
||||
return (GP_ERROR);
|
||||
}
|
||||
|
||||
return(GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_free(Camera *camera)
|
||||
{
|
||||
gp_camera_exit(camera);
|
||||
|
||||
if (camera->port)
|
||||
free(camera->port);
|
||||
if (camera->abilities)
|
||||
free(camera->abilities);
|
||||
if (camera->functions)
|
||||
free(camera->functions);
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_new_by_name (Camera **camera, char *camera_name, CameraPortInfo *settings)
|
||||
{
|
||||
int x=0;
|
||||
|
||||
while (x < glob_abilities_list->count) {
|
||||
if (strcmp(glob_abilities_list->abilities[x]->model, camera_name)==0)
|
||||
return (gp_camera_new(camera, x, settings));
|
||||
x++;
|
||||
}
|
||||
|
||||
return (GP_ERROR);
|
||||
}
|
||||
|
||||
int gp_camera_init (Camera *camera, CameraInit *init)
|
||||
{
|
||||
int x;
|
||||
CameraPortInfo info;
|
||||
|
||||
if (camera->functions->init == NULL)
|
||||
return(GP_ERROR);
|
||||
|
||||
for (x=0; x<gp_port_count(); x++) {
|
||||
gp_port_info(x, &info);
|
||||
if (strcmp(info.path, init->port_settings.path)==0)
|
||||
init->port_settings.type = info.type;
|
||||
}
|
||||
|
||||
return(camera->functions->init(camera, init));
|
||||
}
|
||||
|
||||
int gp_camera_exit (Camera *camera)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (camera->functions->exit == NULL)
|
||||
return(GP_ERROR);
|
||||
|
||||
ret = camera->functions->exit(camera);
|
||||
close_library(camera);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int gp_camera_folder_list(Camera *camera, CameraList *list, char *folder)
|
||||
{
|
||||
CameraListEntry t;
|
||||
int x, ret, y, z;
|
||||
|
||||
/* Initialize the folder list to a known state */
|
||||
list->count = 0;
|
||||
|
||||
if (camera->functions->folder_list == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
ret = camera->functions->folder_list(camera, list, folder);
|
||||
|
||||
if (ret == GP_ERROR)
|
||||
return (GP_ERROR);
|
||||
|
||||
/* Sort the folder list */
|
||||
for (x=0; x<list->count-1; x++) {
|
||||
for (y=x+1; y<list->count; y++) {
|
||||
z = strcmp(list->entry[x].name, list->entry[y].name);
|
||||
if (z > 0) {
|
||||
memcpy(&t, &list->entry[x], sizeof(t));
|
||||
memcpy(&list->entry[x], &list->entry[y], sizeof(t));
|
||||
memcpy(&list->entry[y], &t, sizeof(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_file_list(Camera *camera, CameraList *list, char *folder)
|
||||
{
|
||||
CameraListEntry t;
|
||||
int x, ret, y, z;
|
||||
|
||||
/* Initialize the folder list to a known state */
|
||||
list->count = 0;
|
||||
|
||||
if (camera->functions->file_list == NULL)
|
||||
return (GP_ERROR);
|
||||
ret = camera->functions->file_list(camera, list, folder);
|
||||
if (ret == GP_ERROR)
|
||||
return (GP_ERROR);
|
||||
|
||||
/* Sort the file list */
|
||||
for (x=0; x<list->count-1; x++) {
|
||||
for (y=x+1; y<list->count; y++) {
|
||||
z = strcmp(list->entry[x].name, list->entry[y].name);
|
||||
if (z > 0) {
|
||||
memcpy(&t, &list->entry[x], sizeof(t));
|
||||
memcpy(&list->entry[x], &list->entry[y], sizeof(t));
|
||||
memcpy(&list->entry[y], &t, sizeof(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
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, CameraListType type)
|
||||
{
|
||||
strcpy(list->entry[list->count].name, name);
|
||||
list->entry[list->count].type = type;
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
int gp_camera_file_get (Camera *camera, CameraFile *file,
|
||||
char *folder, char *filename)
|
||||
{
|
||||
if (camera->functions->file_get == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
gp_file_clean(file);
|
||||
|
||||
return (camera->functions->file_get(camera, file, folder, filename));
|
||||
}
|
||||
|
||||
int gp_camera_file_get_preview (Camera *camera, CameraFile *file,
|
||||
char *folder, char *filename)
|
||||
{
|
||||
if (camera->functions->file_get_preview == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
gp_file_clean(file);
|
||||
|
||||
return (camera->functions->file_get_preview(camera, file, folder, filename));
|
||||
}
|
||||
|
||||
int gp_camera_file_put (Camera *camera, CameraFile *file, char *folder)
|
||||
{
|
||||
if (camera->functions->file_put == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
return (camera->functions->file_put(camera, file, folder));
|
||||
}
|
||||
|
||||
int gp_camera_file_delete (Camera *camera, char *folder, char *filename)
|
||||
{
|
||||
|
||||
if (camera->functions->file_delete == NULL)
|
||||
return (GP_ERROR);
|
||||
return (camera->functions->file_delete(camera, folder, filename));
|
||||
}
|
||||
|
||||
int gp_camera_config_get (Camera *camera, CameraWidget *window)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (camera->functions->config_get == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
ret = camera->functions->config_get(camera, window);
|
||||
|
||||
if (glob_debug)
|
||||
gp_widget_dump(window);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int gp_camera_config_set (Camera *camera, CameraSetting *setting, int count)
|
||||
{
|
||||
int x;
|
||||
|
||||
if (glob_debug) {
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "Dumping CameraSetting");
|
||||
for (x=0; x<count; x++)
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "\"%s\" = \"%s\"", setting[x].name, setting[x].value);
|
||||
}
|
||||
|
||||
if (camera->functions->config_set == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
return(camera->functions->config_set(camera, setting, count));
|
||||
}
|
||||
|
||||
int gp_camera_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info)
|
||||
{
|
||||
if (camera->functions->capture == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
gp_file_clean(file);
|
||||
|
||||
return(camera->functions->capture(camera, file, info));
|
||||
}
|
||||
|
||||
int gp_camera_summary (Camera *camera, CameraText *summary)
|
||||
{
|
||||
if (camera->functions->summary == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
return(camera->functions->summary(camera, summary));
|
||||
}
|
||||
|
||||
int gp_camera_manual (Camera *camera, CameraText *manual)
|
||||
{
|
||||
if (camera->functions->manual == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
return(camera->functions->manual(camera, manual));
|
||||
}
|
||||
|
||||
int gp_camera_about (Camera *camera, CameraText *about)
|
||||
{
|
||||
if (camera->functions->about == NULL)
|
||||
return (GP_ERROR);
|
||||
|
||||
return(camera->functions->about(camera, about));
|
||||
}
|
||||
|
||||
/* Configuration file functions (for front-ends and libraries)
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
int gp_setting_get (char *id, char *key, char *value)
|
||||
{
|
||||
int x;
|
||||
|
||||
if (!id || !key)
|
||||
return (GP_ERROR);
|
||||
|
||||
for (x=0; x<glob_setting_count; x++) {
|
||||
if ((strcmp(glob_setting[x].id, id)==0) &&
|
||||
(strcmp(glob_setting[x].key, key)==0)) {
|
||||
strcpy(value, glob_setting[x].value);
|
||||
return (GP_OK);
|
||||
}
|
||||
}
|
||||
strcpy(value, "");
|
||||
return(GP_ERROR);
|
||||
}
|
||||
|
||||
int gp_setting_set (char *id, char *key, char *value)
|
||||
{
|
||||
int x;
|
||||
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "(%s) Setting key \"%s\" to value \"%s\"",
|
||||
id,key,value);
|
||||
|
||||
if (!id || !key)
|
||||
return (GP_ERROR);
|
||||
|
||||
for (x=0; x<glob_setting_count; x++) {
|
||||
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);
|
||||
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);
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
|
||||
/* Front-end interaction functions (libraries calls these!)
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
int gp_frontend_register(CameraStatus status, CameraProgress progress,
|
||||
CameraMessage message, CameraConfirm confirm) {
|
||||
|
||||
@@ -564,106 +118,3 @@ int gp_frontend_register(CameraStatus status, CameraProgress progress,
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_status (Camera *camera, char *status)
|
||||
{
|
||||
if (gp_fe_status)
|
||||
gp_fe_status(camera, status);
|
||||
return(GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_progress (Camera *camera, CameraFile *file, float percentage)
|
||||
{
|
||||
if (gp_fe_progress)
|
||||
gp_fe_progress(camera, file, percentage);
|
||||
|
||||
return(GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_message (Camera *camera, char *message)
|
||||
{
|
||||
if (gp_fe_message)
|
||||
gp_fe_message(camera, message);
|
||||
return(GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_confirm (Camera *camera, char *message)
|
||||
{
|
||||
if (!gp_fe_confirm)
|
||||
/* return YES. dangerous? */
|
||||
return 1;
|
||||
return(gp_fe_confirm(camera, message));
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
list->abilities[list->count] = abilities;
|
||||
list->count += 1;
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <gphoto2.h>
|
||||
#include "file.h"
|
||||
|
||||
|
||||
CameraFile* gp_file_new () {
|
||||
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
/* Debug setting */
|
||||
/* ------------------------------------------------ */
|
||||
extern int glob_debug;
|
||||
#include "core.h"
|
||||
|
||||
/* Camera List */
|
||||
/* ------------------------------------------------ */
|
||||
/* Debug setting */
|
||||
extern int glob_debug;
|
||||
|
||||
/* Camera List */
|
||||
extern CameraAbilitiesList *glob_abilities_list;
|
||||
|
||||
/* Currently loaded settings */
|
||||
/* ------------------------------------------------ */
|
||||
/* number of settings found */
|
||||
extern int glob_setting_count;
|
||||
/* setting key/value list */
|
||||
extern Setting glob_setting[512];
|
||||
|
||||
/* Currently loaded settings */
|
||||
extern int glob_setting_count;
|
||||
extern Setting glob_setting[512];
|
||||
|
||||
/* Session counters */
|
||||
extern int glob_session_camera;
|
||||
extern int glob_session_file;
|
||||
|
||||
/* Callback function pointers */
|
||||
extern CameraStatus gp_fe_status;
|
||||
extern CameraProgress gp_fe_progress;
|
||||
extern CameraMessage gp_fe_message;
|
||||
extern CameraConfirm gp_fe_confirm;
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
|
||||
#include <gphoto2.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "globals.h"
|
||||
#include "library.h"
|
||||
#include "util.h"
|
||||
#include "globals.h"
|
||||
|
||||
int is_library(char *library_filename) {
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
int load_cameras();
|
||||
int is_library (char *library_filename);
|
||||
int load_library (Camera *camera, char *camera_name);
|
||||
|
||||
118
libgphoto2/lists.c
Normal file
118
libgphoto2/lists.c
Normal file
@@ -0,0 +1,118 @@
|
||||
#include <gpio.h>
|
||||
#include <gphoto2.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
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, CameraListType type)
|
||||
{
|
||||
strcpy(list->entry[list->count].name, name);
|
||||
list->entry[list->count].type = type;
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
list->abilities[list->count] = abilities;
|
||||
list->count += 1;
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
44
libgphoto2/port.c
Normal file
44
libgphoto2/port.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <gpio.h>
|
||||
#include <gphoto2.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
int gp_port_count()
|
||||
{
|
||||
return (gpio_get_device_count());
|
||||
}
|
||||
|
||||
int gp_port_info(int port_number, CameraPortInfo *info)
|
||||
{
|
||||
gpio_device_info i;
|
||||
|
||||
if (gpio_get_device_info(port_number, &i)==GPIO_ERROR)
|
||||
return (GP_ERROR);
|
||||
|
||||
/* Translate to gPhoto types */
|
||||
switch (i.type) {
|
||||
case GPIO_DEVICE_SERIAL:
|
||||
info->type = GP_PORT_SERIAL;
|
||||
break;
|
||||
case GPIO_DEVICE_PARALLEL:
|
||||
info->type = GP_PORT_PARALLEL;
|
||||
break;
|
||||
case GPIO_DEVICE_USB:
|
||||
info->type = GP_PORT_USB;
|
||||
break;
|
||||
case GPIO_DEVICE_IEEE1394:
|
||||
info->type = GP_PORT_IEEE1394;
|
||||
break;
|
||||
case GPIO_DEVICE_NETWORK:
|
||||
info->type = GP_PORT_NETWORK;
|
||||
break;
|
||||
default:
|
||||
info->type = GP_PORT_NONE;
|
||||
}
|
||||
strcpy(info->name, i.name);
|
||||
strcpy(info->path, i.path);
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
@@ -1,10 +1,56 @@
|
||||
#include <gphoto2.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "core.h"
|
||||
|
||||
#include <gphoto2.h>
|
||||
|
||||
#include "settings.h"
|
||||
#include "globals.h"
|
||||
#include "util.h"
|
||||
|
||||
int gp_setting_get (char *id, char *key, char *value)
|
||||
{
|
||||
int x;
|
||||
|
||||
if (!id || !key)
|
||||
return (GP_ERROR);
|
||||
|
||||
for (x=0; x<glob_setting_count; x++) {
|
||||
if ((strcmp(glob_setting[x].id, id)==0) &&
|
||||
(strcmp(glob_setting[x].key, key)==0)) {
|
||||
strcpy(value, glob_setting[x].value);
|
||||
return (GP_OK);
|
||||
}
|
||||
}
|
||||
strcpy(value, "");
|
||||
return(GP_ERROR);
|
||||
}
|
||||
|
||||
int gp_setting_set (char *id, char *key, char *value)
|
||||
{
|
||||
int x;
|
||||
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "(%s) Setting key \"%s\" to value \"%s\"",
|
||||
id,key,value);
|
||||
|
||||
if (!id || !key)
|
||||
return (GP_ERROR);
|
||||
|
||||
for (x=0; x<glob_setting_count; x++) {
|
||||
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);
|
||||
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);
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int verify_settings (char *settings_file) {
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gphoto2.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
int gp_abilities_dump (CameraAbilities *abilities) {
|
||||
|
||||
Reference in New Issue
Block a user