summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <gp@n-dimensional.de>2006-08-18 16:43:14 +0000
committerHans Ulrich Niedermann <gp@n-dimensional.de>2006-08-18 16:43:14 +0000
commit4adadbf835e8f55205c582a0a734c9979dfcc68a (patch)
tree03f42266d5cb0972f544915a52020edcf9b0709f
parentd11858adbd01d201b928fcbb4d763392773b1de5 (diff)
downloadlibgphoto2-4adadbf835e8f55205c582a0a734c9979dfcc68a.tar.gz
Add infrastructure to read/write enums as human readable strings (internal!)
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@9103 67ed7778-7388-44ab-90cf-0a291f65f57c
-rw-r--r--libgphoto2/gphoto2-abilities-list.c64
-rw-r--r--libgphoto2/gphoto2-abilities-list.h35
-rw-r--r--libgphoto2/libgphoto2.sym6
-rw-r--r--libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c14
-rw-r--r--libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.h5
-rw-r--r--libgphoto2_port/libgphoto2_port/gphoto2-port-log.c97
-rw-r--r--libgphoto2_port/libgphoto2_port/gphoto2-port-log.h40
-rw-r--r--libgphoto2_port/libgphoto2_port/libgphoto2_port.sym7
8 files changed, 259 insertions, 9 deletions
diff --git a/libgphoto2/gphoto2-abilities-list.c b/libgphoto2/gphoto2-abilities-list.c
index 8892b67fa..404f85382 100644
--- a/libgphoto2/gphoto2-abilities-list.c
+++ b/libgphoto2/gphoto2-abilities-list.c
@@ -22,6 +22,8 @@
* Boston, MA 02111-1307, USA.
*/
+#define _GPHOTO2_INTERNAL_CODE
+
#include "config.h"
#include "gphoto2-abilities-list.h"
@@ -65,15 +67,6 @@
/** \internal */
#define CHECK_MEM(m) {if (!(m)) return (GP_ERROR_NO_MEMORY);}
-/**
- * Name of the environment variable which may contain the path where
- * to look for the camlibs. If this environment variable is not defined,
- * use the compiled-in default constant.
- *
- * \internal Internal use only.
- */
-#define CAMLIBDIR_ENV "CAMLIBS"
-
/** \internal */
struct _CameraAbilitiesList {
int count;
@@ -644,6 +637,59 @@ gp_abilities_list_get_abilities (CameraAbilitiesList *list, int index,
}
+#ifdef _GPHOTO2_INTERNAL_CODE
+
+/* enum CameraOperation */
+const StringFlagItem gpi_camera_operation_map[] = {
+ { "none", GP_OPERATION_NONE },
+ { "capture_image", GP_OPERATION_CAPTURE_IMAGE },
+ { "capture_video", GP_OPERATION_CAPTURE_VIDEO },
+ { "capture_audio", GP_OPERATION_CAPTURE_AUDIO },
+ { "capture_preview", GP_OPERATION_CAPTURE_PREVIEW },
+ { "config", GP_OPERATION_CONFIG },
+ { NULL, 0 },
+};
+
+/* enum CameraFileOperation */
+const StringFlagItem gpi_file_operation_map[] = {
+ { "none", GP_FILE_OPERATION_NONE },
+ { "delete", GP_FILE_OPERATION_DELETE },
+ { "preview", GP_FILE_OPERATION_PREVIEW },
+ { "raw", GP_FILE_OPERATION_RAW },
+ { "audio", GP_FILE_OPERATION_AUDIO },
+ { "exif", GP_FILE_OPERATION_EXIF },
+ { NULL, 0 },
+};
+
+/* enum CameraFolderOperation */
+const StringFlagItem gpi_folder_operation_map[] = {
+ { "none", GP_FOLDER_OPERATION_NONE },
+ { "delete_all", GP_FOLDER_OPERATION_DELETE_ALL },
+ { "put_file", GP_FOLDER_OPERATION_PUT_FILE },
+ { "make_dir", GP_FOLDER_OPERATION_MAKE_DIR },
+ { "remove_dir", GP_FOLDER_OPERATION_REMOVE_DIR },
+ { NULL, 0 },
+};
+
+/* enum GphotoDeviceType */
+const StringFlagItem gpi_gphoto_device_type_map[] = {
+ { "still_camera", GP_DEVICE_STILL_CAMERA },
+ { "audio_player", GP_DEVICE_AUDIO_PLAYER },
+ { NULL, 0 },
+};
+
+/* enum CameraDriverStatus */
+const StringFlagItem gpi_camera_driver_status_map[] = {
+ { "production", GP_DRIVER_STATUS_PRODUCTION },
+ { "testing", GP_DRIVER_STATUS_TESTING },
+ { "experimental", GP_DRIVER_STATUS_EXPERIMENTAL },
+ { "deprecated", GP_DRIVER_STATUS_DEPRECATED },
+ { NULL, 0 },
+};
+
+#endif /* _GPHOTO2_INTERNAL_CODE */
+
+
/*
* Local Variables:
* c-file-style:"linux"
diff --git a/libgphoto2/gphoto2-abilities-list.h b/libgphoto2/gphoto2-abilities-list.h
index 44b971760..601b36cee 100644
--- a/libgphoto2/gphoto2-abilities-list.h
+++ b/libgphoto2/gphoto2-abilities-list.h
@@ -29,6 +29,8 @@
#include <gphoto2-list.h>
#include <gphoto2-port-info-list.h>
+#include <gphoto2-port-log.h>
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@@ -76,6 +78,26 @@ typedef enum {
} CameraFolderOperation;
+#ifdef _GPHOTO2_INTERNAL_CODE
+
+ /* enum CameraOperation */
+ extern const StringFlagItem gpi_camera_operation_map[];
+
+ /* enum CameraFileOperation */
+ extern const StringFlagItem gpi_file_operation_map[];
+
+ /* enum CameraFolderOperation */
+ extern const StringFlagItem gpi_folder_operation_map[];
+
+ /* enum GphotoDeviceType */
+ extern const StringFlagItem gpi_gphoto_device_type_map[];
+
+ /* enum CameraDriverStatus */
+ extern const StringFlagItem gpi_camera_driver_status_map[];
+
+#endif /* _GPHOTO2_INTERNAL_CODE */
+
+
/**
* \brief Describes the properties of a specific camera.
*
@@ -150,6 +172,19 @@ int gp_abilities_list_get_abilities (CameraAbilitiesList *list, int index,
const char *gp_message_codeset (const char *);
+
+/**
+ * Name of the environment variable which may contain the path where
+ * to look for the camlibs. If this environment variable is not defined,
+ * use the compiled-in default constant.
+ *
+ * \internal Internal use only.
+ */
+#ifdef _GPHOTO2_INTERNAL_CODE
+#define CAMLIBDIR_ENV "CAMLIBS"
+#endif /* _GPHOTO2_INTERNAL_CODE */
+
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/libgphoto2/libgphoto2.sym b/libgphoto2/libgphoto2.sym
index 8d909dbe6..5387bfa7e 100644
--- a/libgphoto2/libgphoto2.sym
+++ b/libgphoto2/libgphoto2.sym
@@ -175,3 +175,9 @@ gpi_jpeg_chunk_print
gpi_jpeg_add_marker
gpi_jpeg_write
gpi_jpeg_destroy
+gpi_camera_operation_map
+gpi_file_operation_map
+gpi_folder_operation_map
+gpi_gphoto_device_type_map
+gpi_camera_driver_status_map
+gpi_gphoto_port_type_map
diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c
index ed1108cfc..356358bee 100644
--- a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c
+++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c
@@ -18,6 +18,8 @@
* Boston, MA 02111-1307, USA.
*/
+#define _GPHOTO2_INTERNAL_CODE
+
#include "config.h"
#include "gphoto2-port-info-list.h"
@@ -463,3 +465,15 @@ gp_port_info_list_get_info (GPPortInfoList *list, int n, GPPortInfo *info)
return (GP_OK);
}
+
+
+#ifdef _GPHOTO2_INTERNAL_CODE
+const StringFlagItem gpi_gphoto_port_type_map[] = {
+ { "none", GP_PORT_NONE },
+ { "serial", GP_PORT_SERIAL },
+ { "usb", GP_PORT_USB },
+ { "disk", GP_PORT_DISK },
+ { "ptpip", GP_PORT_PTPIP },
+ { NULL, 0 },
+};
+#endif /* _GPHOTO2_INTERNAL_CODE */
diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.h b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.h
index 293a6b3de..8125220e7 100644
--- a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.h
+++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.h
@@ -45,6 +45,11 @@ struct _GPPortInfo {
extern "C" {
#endif /* __cplusplus */
+#ifdef _GPHOTO2_INTERNAL_CODE
+#include <gphoto2-port-log.h>
+extern const StringFlagItem gpi_gphoto_port_type_map[];
+#endif
+
/* Internals are private */
typedef struct _GPPortInfoList GPPortInfoList;
diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c b/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c
index 5117d2447..a0036e8ac 100644
--- a/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c
+++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c
@@ -18,6 +18,8 @@
* Boston, MA 02111-1307, USA.
*/
+#define _GPHOTO2_INTERNAL_CODE
+
#include "config.h"
#include "gphoto2-port-log.h"
@@ -341,3 +343,98 @@ gp_log (GPLogLevel level, const char *domain, const char *format, ...)
{
}
#endif /* DISABLE_DEBUGGING */
+
+
+#ifdef _GPHOTO2_INTERNAL_CODE
+
+void
+gpi_enum_to_string(unsigned int _enum,
+ const StringFlagItem *map,
+ string_item_func func, void *data)
+{
+ int i;
+ for (i=0; map[i].str != NULL; i++) {
+ if (_enum == map[i].flag) {
+ func(map[i].str, data);
+ break;
+ }
+ }
+}
+
+int
+gpi_string_to_enum(const char *str,
+ unsigned int *result,
+ const StringFlagItem *map)
+{
+ int i;
+ for (i=0; map[i].str != NULL; i++) {
+ if (0==strcmp(map[i].str, str)) {
+ (*result) = map[i].flag;
+ return 0;
+ }
+ }
+ return 1;
+}
+
+void
+gpi_flags_to_string_list(unsigned int flags,
+ const StringFlagItem *map,
+ string_item_func func, void *data)
+{
+ int i;
+ for (i=0; map[i].str != NULL; i++) {
+ if ((flags == 0) && (map[i].flag == 0)) {
+ func(map[i].str, data);
+ break;
+ } else if (0 != (flags & map[i].flag)) {
+ func(map[i].str, data);
+ }
+ }
+}
+
+unsigned int
+gpi_string_to_flag(const char *str,
+ const StringFlagItem *map)
+{
+ int i;
+ for (i=0; map[i].str != NULL; i++) {
+ if (0==strcmp(map[i].str, str)) {
+ return map[i].flag;
+ }
+ }
+ return 0;
+}
+
+int
+gpi_string_or_to_flags(const char *str,
+ unsigned int *flags,
+ const StringFlagItem *map)
+{
+ int i;
+ int found = 0;
+ for (i=0; map[i].str != NULL; i++) {
+ if (0==strcmp(map[i].str, str)) {
+ (*flags) |= map[i].flag;
+ found = 1;
+ }
+ }
+ if (found) {
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+unsigned int
+gpi_string_list_to_flags(const char *str[],
+ const StringFlagItem *map)
+{
+ int i;
+ unsigned int flags = 0;
+ for (i=0; str[i] != NULL; i++) {
+ flags |= gpi_string_to_flag(str[i], map);
+ }
+ return flags;
+}
+
+#endif /* _GPHOTO2_INTERNAL_CODE */
diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-log.h b/libgphoto2_port/libgphoto2_port/gphoto2-port-log.h
index 588dee952..3dd28557e 100644
--- a/libgphoto2_port/libgphoto2_port/gphoto2-port-log.h
+++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-log.h
@@ -144,4 +144,44 @@ void gp_log_data (const char *domain, const char *data, unsigned int size);
#endif /* DISABLE_DEBUGGING */
+#ifdef _GPHOTO2_INTERNAL_CODE
+
+ typedef struct StringFlagItem {
+ char *str;
+ unsigned int flag;
+ } StringFlagItem;
+
+ typedef void (*string_item_func) (const char *str, void *data);
+
+ void
+ gpi_enum_to_string(const unsigned int _enum,
+ const StringFlagItem *map,
+ string_item_func func, void *data);
+
+ int
+ gpi_string_to_enum(const char *str,
+ unsigned int *result,
+ const StringFlagItem *map);
+
+ void
+ gpi_flags_to_string_list(const unsigned int flags,
+ const StringFlagItem *map,
+ string_item_func func, void *data);
+
+ int
+ gpi_string_or_to_flags(const char *str,
+ unsigned int *flags,
+ const StringFlagItem *map);
+
+ unsigned int
+ gpi_string_to_flag(const char *str,
+ const StringFlagItem *map);
+
+ unsigned int
+ gpi_string_list_to_flags(const char *str[],
+ const StringFlagItem *map);
+
+#endif /* _GPHOTO2_INTERNAL_CODE */
+
+
#endif /* __GPHOTO2_PORT_LOG_H__ */
diff --git a/libgphoto2_port/libgphoto2_port/libgphoto2_port.sym b/libgphoto2_port/libgphoto2_port/libgphoto2_port.sym
index b5b357e25..bf34a03e7 100644
--- a/libgphoto2_port/libgphoto2_port/libgphoto2_port.sym
+++ b/libgphoto2_port/libgphoto2_port/libgphoto2_port.sym
@@ -53,3 +53,10 @@ gp_system_filename
gp_system_closedir
gp_system_is_file
gp_system_is_dir
+gpi_gphoto_port_type_map
+gpi_enum_to_string
+gpi_string_to_enum
+gpi_string_to_flag
+gpi_string_or_to_flags
+gpi_string_list_to_flags
+gpi_flags_to_string_list