diff options
author | Marcus Meissner <marcus@jet.franken.de> | 2008-03-15 21:45:48 +0000 |
---|---|---|
committer | Marcus Meissner <marcus@jet.franken.de> | 2008-03-15 21:45:48 +0000 |
commit | 3c26841fa08d4f7c82ea7b4004a954f6fe146f17 (patch) | |
tree | 77e49b5d592507d3aa7e03ef5117c4dcd5850e5e /libgphoto2_port/libgphoto2_port | |
parent | f50fb2ec5e87a8538befd8909ae6243711d49baa (diff) | |
download | libgphoto2-3c26841fa08d4f7c82ea7b4004a954f6fe146f17.tar.gz |
GPPortInfo struct abstracted into a private struct.
- libgphoto2_port rewritten for new GPPortInfo.
- camlibs/directory and camlibs/ptp2 adjusted.
- libgphoto2/ adjusted for the changed GPPortInfo list handling.
- configure.ac adjusted, NEWS adjusted
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@10990 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'libgphoto2_port/libgphoto2_port')
-rw-r--r-- | libgphoto2_port/libgphoto2_port/Makefile.am | 1 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c | 205 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/gphoto2-port.c | 69 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/libgphoto2_port.ver | 53 |
4 files changed, 175 insertions, 153 deletions
diff --git a/libgphoto2_port/libgphoto2_port/Makefile.am b/libgphoto2_port/libgphoto2_port/Makefile.am index 5f271f52f..9ea61e30e 100644 --- a/libgphoto2_port/libgphoto2_port/Makefile.am +++ b/libgphoto2_port/libgphoto2_port/Makefile.am @@ -39,6 +39,7 @@ libgphoto2_port_la_LIBADD = \ libgphoto2_port_la_SOURCES = \ gphoto2-port-info-list.c \ + gphoto2-port-info.h \ gphoto2-port-log.c \ gphoto2-port-version.c \ gphoto2-port.c \ diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c index bbfd80d98..1bcfbffab 100644 --- a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c +++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c @@ -23,11 +23,6 @@ #include "config.h" -#ifdef HAVE_ASM_SYMVERS -# define __LIBGPHOTO2_INCLUDE_OLD_VERSIONS -# define __LIBGPHOTO2_INCLUDE_OLD_VERSIONS_INFOLIST -#endif - #include <gphoto2/gphoto2-port-info-list.h> #include <stdlib.h> @@ -45,6 +40,8 @@ #include <gphoto2/gphoto2-port-library.h> #include <gphoto2/gphoto2-port-log.h> +#include "gphoto2-port-info.h" + #ifdef ENABLE_NLS # include <libintl.h> # undef _ @@ -185,30 +182,15 @@ gp_port_info_list_append (GPPortInfoList *list, GPPortInfo info) list->info = new_info; list->count++; - memcpy (&(list->info[list->count - 1]), &info, sizeof (GPPortInfo)); + list->info[list->count - 1] = info; /* Ignore generic entries */ for (generic = i = 0; i < list->count; i++) - if (!strlen (list->info[i].name)) + if (!strlen (list->info[i]->name)) generic++; return (list->count - 1 - generic); } -#ifdef __LIBGPHOTO2_INCLUDE_OLD_VERSIONS -int -gp_port_info_list_append_v240 (GPPortInfoList *list, GPPortInfo_v240 info) -{ - GPPortInfo newinfo; - int ret; - - newinfo.type = info.type; - strcpy (newinfo.name,info.name); - strncpy (newinfo.path,info.path, sizeof(newinfo.path)); - strcpy (newinfo.library_filename,info.library_filename); - ret = gp_port_info_list_append_v250 (list, newinfo); - return ret; -} -#endif static int foreach_func (const char *filename, lt_ptr data) @@ -243,7 +225,7 @@ foreach_func (const char *filename, lt_ptr data) type = lib_type (); for (j = 0; j < list->count; j++) - if (list->info[j].type == type) + if (list->info[j]->type == type) break; if (j != list->count) { gp_log (GP_LOG_DEBUG, "gphoto2-port-info-list", @@ -270,9 +252,9 @@ foreach_func (const char *filename, lt_ptr data) for (j = old_size; j < list->count; j++){ gp_log (GP_LOG_DEBUG, "gphoto2-port-info-list", _("Loaded '%s' ('%s') from '%s'."), - list->info[j].name, list->info[j].path, + list->info[j]->name, list->info[j]->path, filename); - strcpy (list->info[j].library_filename, filename); + list->info[j]->library_filename = strdup (filename); } } @@ -338,7 +320,7 @@ gp_port_info_list_count (GPPortInfoList *list) /* Ignore generic entries */ count = list->count; for (i = 0; i < list->count; i++) - if (!strlen (list->info[i].name)) + if (!strlen (list->info[i]->name)) count--; gp_log (GP_LOG_DEBUG, "gphoto2-port-info-list", _("%i regular entries " @@ -376,9 +358,9 @@ gp_port_info_list_lookup_path (GPPortInfoList *list, const char *path) /* Exact match? */ for (generic = i = 0; i < list->count; i++) - if (!strlen (list->info[i].name)) + if (!strlen (list->info[i]->name)) generic++; - else if (!strcmp (list->info[i].path, path)) + else if (!strcmp (list->info[i]->path, path)) return (i - generic); /* Regex match? */ @@ -387,24 +369,24 @@ gp_port_info_list_lookup_path (GPPortInfoList *list, const char *path) for (i = 0; i < list->count; i++) { GPPortInfo newinfo; - if (strlen (list->info[i].name)) + if (strlen (list->info[i]->name)) continue; gp_log (GP_LOG_DEBUG, "gphoto2-port-info-list", - _("Trying '%s'..."), list->info[i].path); + _("Trying '%s'..."), list->info[i]->path); /* Compile the pattern */ #ifdef HAVE_GNU_REGEX memset (&pattern, 0, sizeof (pattern)); - rv = re_compile_pattern (list->info[i].path, - strlen (list->info[i].path), &pattern); + rv = re_compile_pattern (list->info[i]->path, + strlen (list->info[i]->path), &pattern); if (rv) { gp_log (GP_LOG_DEBUG, "gphoto2-port-info-list", "%s", rv); continue; } #else - result = regcomp (&pattern, list->info[i].path, REG_ICASE); + result = regcomp (&pattern, list->info[i]->path, REG_ICASE); if (result) { char buf[1024]; if (regerror (result, &pattern, buf, sizeof (buf))) @@ -435,9 +417,11 @@ gp_port_info_list_lookup_path (GPPortInfoList *list, const char *path) continue; } #endif - memcpy (&newinfo, &list->info[i], sizeof(newinfo)); - strncpy (newinfo.path, path, sizeof (newinfo.path)); - strncpy (newinfo.name, _("Generic Port"), sizeof (newinfo.name)); + gp_port_info_new (&newinfo); + gp_port_info_set_type (newinfo, list->info[i]->type); + newinfo->library_filename = strdup(list->info[i]->library_filename); + gp_port_info_set_name (newinfo, _("Generic Port")); + gp_port_info_set_path (newinfo, path); CR (result = gp_port_info_list_append (list, newinfo)); return result; } @@ -466,9 +450,9 @@ gp_port_info_list_lookup_name (GPPortInfoList *list, const char *name) /* Ignore generic entries */ for (generic = i = 0; i < list->count; i++) - if (!strlen (list->info[i].name)) + if (!strlen (list->info[i]->name)) generic++; - else if (!strcmp (list->info[i].name, name)) + else if (!strcmp (list->info[i]->name, name)) return (i - generic); return (GP_ERROR_UNKNOWN_PORT); @@ -480,7 +464,7 @@ gp_port_info_list_lookup_name (GPPortInfoList *list, const char *name) * \param n the index of the entry * \param info the returned information * - * Retreives an entry from the list and stores it into info. + * Returns a pointer to the current port entry. * * \return a gphoto2 error code **/ @@ -499,60 +483,123 @@ gp_port_info_list_get_info (GPPortInfoList *list, int n, GPPortInfo *info) /* Ignore generic entries */ for (i = 0; i <= n; i++) - if (!strlen (list->info[i].name)) { + if (!strlen (list->info[i]->name)) { n++; if (n >= list->count) return (GP_ERROR_BAD_PARAMETERS); } - memcpy (info, &(list->info[n]), sizeof (GPPortInfo)); - + *info = list->info[n]; return (GP_OK); } -#ifdef __LIBGPHOTO2_INCLUDE_OLD_VERSIONS + /** - * \brief Get port information of specific entry - * \param list a #GPPortInfoList - * \param n the index of the entry - * \param info the returned information + * \brief Get name of a specific port entry + * \param info a #GPPortInfo + * \param name a pointer to a char* which will receive the name * - * Retreives an entry from the list and stores it into info. - * This is the version used before libgphoto2 2.5.0 + * Retreives the name of the passed in GPPortInfo, by reference. * * \return a gphoto2 error code **/ int -gp_port_info_list_get_info_v240 (GPPortInfoList *list, int n, GPPortInfo_v240 *info) -{ - int ret; - GPPortInfo newinfo; - - ret = gp_port_info_list_get_info_v250 (list, n, &newinfo); - if (ret != GP_OK) - return ret; - info->type = newinfo.type; - strcpy(info->name, newinfo.name); /* same size */ - /* FIXME: handle overflows by error return? */ - strncpy(info->path, newinfo.path, sizeof(info->path)); /* larger size */ - strcpy(info->library_filename, newinfo.library_filename); /* same size */ - return (GP_OK); +gp_port_info_get_name (GPPortInfo info, char **name) { + *name = info->name; + return GP_OK; } -#endif -#ifdef _GPHOTO2_INTERNAL_CODE /** - * \brief Internal map between GP_PORT and name - * - * Internal map between the GP_PORT_xxx enumeration and - * string names (usb,serial,disk,ptpip,...). - */ -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 */ + * \brief Set name of a specific port entry + * \param info a #GPPortInfo + * \param name a char* pointer which will receive the name + * + * Sets the name of the passed in GPPortInfo + * This is a libgphoto2_port internal function. + * + * \return a gphoto2 error code + **/ +int +gp_port_info_set_name (GPPortInfo info, const char *name) { + info->name = strdup (name); + return GP_OK; +} + +/** + * \brief Get path of a specific port entry + * \param info a #GPPortInfo + * \param path a pointer to a char* which will receive the path + * + * Retreives the path of the passed in GPPortInfo, by reference. + * + * \return a gphoto2 error code + **/ +int +gp_port_info_get_path (GPPortInfo info, char **path) { + *path = info->path; + return GP_OK; +} + +/** + * \brief Set path of a specific port entry + * \param info a #GPPortInfo + * \param path a char* pointer which will receive the path + * + * Sets the path of the passed in GPPortInfo + * This is a libgphoto2_port internal function. + * + * \return a gphoto2 error code + **/ +int +gp_port_info_set_path (GPPortInfo info, const char *path) { + info->path = strdup (path); + return GP_OK; +} + +/** + * \brief Get type of a specific port entry + * \param info a #GPPortInfo + * \param type a pointer to a GPPortType variable which will receive the type + * + * Retreives the type of the passed in GPPortInfo + * + * \return a gphoto2 error code + **/ +int +gp_port_info_get_type (GPPortInfo info, GPPortType *type) { + *type = info->type; + return GP_OK; +} + +/** + * \brief Set type of a specific port entry + * \param info a #GPPortInfo + * \param type a GPPortType variable which will has the type + * + * Sets the type of the passed in GPPortInfo + * This is a libgphoto2_port internal function. + * + * \return a gphoto2 error code + **/ +int +gp_port_info_set_type (GPPortInfo info, GPPortType type) { + info->type = type; + return GP_OK; +} + +/** + * \brief Create a new portinfo + * \param info pointer to a #GPPortInfo + * + * Allocates and initializes a GPPortInfo structure. + * This is a libgphoto2_port internal function. + * + * \return a gphoto2 error code + **/ +int +gp_port_info_new (GPPortInfo *info) { + *info = calloc (sizeof(struct _GPPortInfo),1); + if (!*info) + return GP_ERROR_NO_MEMORY; + return GP_OK; +} diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port.c b/libgphoto2_port/libgphoto2_port/gphoto2-port.c index 2228e1c70..62818fb9c 100644 --- a/libgphoto2_port/libgphoto2_port/gphoto2-port.c +++ b/libgphoto2_port/libgphoto2_port/gphoto2-port.c @@ -32,15 +32,12 @@ #include <ltdl.h> -#ifdef HAVE_ASM_SYMVERS -# define __LIBGPHOTO2_INCLUDE_OLD_VERSIONS -# define __LIBGPHOTO2_INCLUDE_OLD_VERSIONS_PORT -#endif - #include <gphoto2/gphoto2-port-result.h> #include <gphoto2/gphoto2-port-library.h> #include <gphoto2/gphoto2-port-log.h> +#include "gphoto2-port-info.h" + #ifdef ENABLE_NLS # include <libintl.h> # undef _ @@ -67,7 +64,7 @@ struct _GPPortPrivateCore { char error[2048]; /**< Internal kept error message. */ - GPPortInfo info; /**< Internal port information of this port. */ + struct _GPPortInfo info; /**< Internal port information of this port. */ GPPortOperations *ops; /**< Internal port operations. */ lt_dlhandle lh; /**< Internal libtool library handle. */ }; @@ -150,8 +147,12 @@ gp_port_set_info (GPPort *port, GPPortInfo info) CHECK_NULL (port); - memcpy (&port->pc->info, &info, sizeof (GPPortInfo)); - port->type = info.type; + port->pc->info.name = strdup (info->name); + port->pc->info.path = strdup (info->path); + port->pc->info.type = info->type; + port->pc->info.library_filename = strdup (info->library_filename); + + port->type = info->type; /* Clean up */ if (port->pc->ops) { @@ -165,10 +166,10 @@ gp_port_set_info (GPPort *port, GPPortInfo info) } lt_dlinit (); - port->pc->lh = lt_dlopenext (info.library_filename); + port->pc->lh = lt_dlopenext (info->library_filename); if (!port->pc->lh) { gp_log (GP_LOG_ERROR, "gphoto2-port", _("Could not load " - "'%s' ('%s')."), info.library_filename, + "'%s' ('%s')."), info->library_filename, lt_dlerror ()); lt_dlexit (); return (GP_ERROR_LIBRARY); @@ -179,7 +180,7 @@ gp_port_set_info (GPPort *port, GPPortInfo info) if (!ops_func) { gp_log (GP_LOG_ERROR, "gphoto2-port", _("Could not find " "'gp_port_library_operations' in '%s' ('%s')"), - info.library_filename, lt_dlerror ()); + info->library_filename, lt_dlerror ()); lt_dlclose (port->pc->lh); lt_dlexit (); port->pc->lh = NULL; @@ -189,10 +190,8 @@ gp_port_set_info (GPPort *port, GPPortInfo info) gp_port_init (port); /* Initialize the settings to some default ones */ - switch (info.type) { + switch (info->type) { case GP_PORT_SERIAL: - strncpy (port->settings.serial.port, info.path, - sizeof (port->settings.serial.port)); port->settings.serial.speed = 0; port->settings.serial.bits = 8; port->settings.serial.parity = 0; @@ -200,7 +199,7 @@ gp_port_set_info (GPPort *port, GPPortInfo info) gp_port_set_timeout (port, 500); break; case GP_PORT_USB: - strncpy (port->settings.usb.port, info.path, + strncpy (port->settings.usb.port, info->path, sizeof (port->settings.usb.port)); port->settings.usb.inep = -1; port->settings.usb.outep = -1; @@ -209,11 +208,6 @@ gp_port_set_info (GPPort *port, GPPortInfo info) port->settings.usb.altsetting = -1; gp_port_set_timeout (port, 5000); break; - case GP_PORT_DISK: - strncpy(port->settings.disk.mountpoint, - strchr(info.path, ':') + 1, - sizeof(port->settings.disk.mountpoint)); - break; default: /* Nothing in here */ break; @@ -223,20 +217,6 @@ gp_port_set_info (GPPort *port, GPPortInfo info) return (GP_OK); } -#ifdef __LIBGPHOTO2_INCLUDE_OLD_VERSIONS -int -gp_port_set_info_v240 (GPPort *port, GPPortInfo_v240 info) -{ - GPPortInfo newinfo; - - newinfo.type = info.type; - strcpy (newinfo.name, info.name); - strncpy(newinfo.path, info.path, sizeof(newinfo.path)); - strcpy (newinfo.library_filename, info.library_filename); - return gp_port_set_info_v250 (port, newinfo); -} -#endif - /** * \brief Retreives information about the port. * @@ -251,29 +231,10 @@ gp_port_get_info (GPPort *port, GPPortInfo *info) { CHECK_NULL (port && info); - memcpy (info, &port->pc->info, sizeof (GPPortInfo)); - + *info = &port->pc->info; return (GP_OK); } -#ifdef __LIBGPHOTO2_INCLUDE_OLD_VERSIONS -int -gp_port_get_info_v240 (GPPort *port, GPPortInfo_v240 *info) -{ - int ret; - GPPortInfo newinfo; - - ret = gp_port_get_info_v250 (port, &newinfo); - if (ret != GP_OK) - return ret; - info->type = newinfo.type; - strcpy (info->name, newinfo.name); - strncpy (info->path, newinfo.path, sizeof(info->path)); - strcpy (info->library_filename, newinfo.library_filename); - return GP_OK; -} -#endif - /** * \brief Open a port. * \param port a #GPPort diff --git a/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver b/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver index 0fb369521..aab84a844 100644 --- a/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver +++ b/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver @@ -1,11 +1,10 @@ -LIBGPHOTO2_0_0 { +LIBGPHOTO2_5_0 { global: gp_log; gp_log_add_func; gp_log_data; gp_log_remove_func; gp_logv; - gp_port_message_codeset; gp_port_check_int; gp_port_check_int_fast; gp_port_close; @@ -16,6 +15,9 @@ LIBGPHOTO2_0_0 { gp_port_get_pin; gp_port_get_settings; gp_port_get_timeout; + gp_port_info_get_name; + gp_port_info_get_path; + gp_port_info_get_type; gp_port_info_list_append; gp_port_info_list_count; gp_port_info_list_free; @@ -25,6 +27,7 @@ LIBGPHOTO2_0_0 { gp_port_info_list_lookup_path; gp_port_info_list_new; gp_port_library_version; + gp_port_message_codeset; gp_port_new; gp_port_open; gp_port_read; @@ -42,21 +45,27 @@ LIBGPHOTO2_0_0 { gp_port_usb_clear_halt; gp_port_usb_find_device; gp_port_usb_find_device_by_class; + gp_port_usb_msg_class_read; + gp_port_usb_msg_class_write; gp_port_usb_msg_interface_read; gp_port_usb_msg_interface_write; gp_port_usb_msg_read; gp_port_usb_msg_write; - gp_port_usb_msg_class_write; - gp_port_usb_msg_class_read; gp_port_write; + gp_system_closedir; + gp_system_filename; + gp_system_is_dir; + gp_system_is_file; gp_system_mkdir; - gp_system_rmdir; gp_system_opendir; gp_system_readdir; - gp_system_filename; - gp_system_closedir; - gp_system_is_file; - gp_system_is_dir; + gp_system_rmdir; + local: + *; +}; + +# These are only supposed to be used by libgphoto2 internally. +LIBGPHOTO2_INTERNAL { gpi_gphoto_port_type_map; gpi_enum_to_string; gpi_string_to_enum; @@ -64,18 +73,22 @@ LIBGPHOTO2_0_0 { gpi_string_or_to_flags; gpi_string_list_to_flags; gpi_flags_to_string_list; - local: - *; -}; -LIBGPHOTO2_5_0 { - # The asm(".symver ...") constructs will put stuff into this node, - # it needs to stay. - # Currently used by: - # gp_port_set_info, gp_port_get_info, - # gp_port_info_list_append, gp_port_info_list_get_info + gp_port_info_new; + gp_port_info_set_name; + gp_port_info_set_path; + gp_port_info_set_type; +}; - # Add new exported functions here too! -} LIBGPHOTO2_0_0; +#LIBGPHOTO2_6_0 { +# global: +# # The asm(".symver ...") constructs will put stuff into this node, +# # it needs to stay. +# # Currently used by: +# # gp_port_set_info, gp_port_get_info, +# # gp_port_info_list_append, gp_port_info_list_get_info +# +# # Add new exported functions here too! +#} LIBGPHOTO2_5_0; # here comes the next version... |