1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

Make port structure opaque.

This commit is contained in:
Martin Ling 2013-11-23 17:11:19 +00:00
parent 70cd37def2
commit 1c5aae9dc5
2 changed files with 35 additions and 12 deletions

View File

@ -226,18 +226,7 @@ enum sp_signal {
}; };
/** A serial port. */ /** A serial port. */
struct sp_port { struct sp_port;
/** Name used to open the port. */
char *name;
/** @cond 0 */
/** OS-specific port handle. */
#ifdef _WIN32
HANDLE hdl;
#else
int fd;
#endif
/** @endcond */
};
/** Configuration for a serial port. */ /** Configuration for a serial port. */
struct sp_port_config { struct sp_port_config {
@ -281,6 +270,21 @@ struct sp_port_config {
*/ */
enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_ptr); enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_ptr);
/**
* Get the name of a port.
*
* The name returned is whatever is normally used to refer to a port on the
* current operating system; e.g. for Windows it will usually be a "COMn"
* device name, and for Unix it will be a device path beginning with "/dev/".
*
* @param port Pointer to port structure.
*
* @return The port name, or NULL if an invalid port is passed. The name
* string is part of the port structure and may not be used after the
* port structure has been freed.
*/
char *sp_get_port_name(const struct sp_port *port);
/** /**
* Free a port structure obtained from sp_get_port_by_name() or sp_copy_port(). * Free a port structure obtained from sp_get_port_by_name() or sp_copy_port().
*/ */

View File

@ -58,6 +58,15 @@
#include "libserialport.h" #include "libserialport.h"
struct sp_port {
char *name;
#ifdef _WIN32
HANDLE hdl;
#else
int fd;
#endif
};
struct port_data { struct port_data {
#ifdef _WIN32 #ifdef _WIN32
DCB dcb; DCB dcb;
@ -184,6 +193,16 @@ enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_p
RETURN_OK(); RETURN_OK();
} }
char *sp_get_port_name(const struct sp_port *port)
{
TRACE("%p", port);
if (!port)
return NULL;
RETURN_VALUE("%s", port->name);
}
enum sp_return sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr) enum sp_return sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr)
{ {
TRACE("%p, %p", port, copy_ptr); TRACE("%p, %p", port, copy_ptr);