[PATCH 0/9] Refactor devices build

Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/9] Refactor devices build

Ladislav Michl
Hi there,

this is next version of "Refactor devices build" patch broken into
pieces. It is compile tested on Linux only (with exception of unixirda
as IrDA support was removed from kernel with commit d64c2a76123f
"staging: irda: remove the irda network stack and drivers" and even
https://www.irda.org/ site turned into some obscure EMF Blockers
selling stuff).

Comments and suggestions welcome. Especially those suggesting unified
device function prototypes ;-)

Ladislav Michl (9):
  Move device_script into separate file
  Cleanup device includes
  configure.ac: do not mix library and device support checks
  Remove nowhere used device_reset()
  Remove misleading comments from tcp device
  dku2libusb: move definitions into C file
  dku2libusb: whitespace cleanup
  libfunctions: reimplement gn_lib_is_connectiontype_supported
  Refactor devices build

 common/Makefile.am                            |   1 +
 common/device.c                               | 397 +++++++++---------
 common/devices/Makefile.am                    |  57 +--
 common/devices/bluetooth.c                    |  31 --
 common/devices/dku2libusb.c                   | 110 +++--
 common/devices/irda.c                         |  27 --
 common/devices/osxbluetooth.m                 |   8 +-
 common/devices/socketphonet.c                 |  38 +-
 common/devices/tcp.c                          |  42 --
 common/devices/unixbluetooth.c                |  13 +-
 common/devices/unixirda.c                     |   8 +-
 common/devices/winbluetooth.c                 |  10 +-
 common/devices/winirda.c                      |   7 +-
 common/forkscript.c                           |  63 +++
 common/libfunctions.c                         |  54 +--
 configure.ac                                  | 109 +++--
 include/device.h                              |   1 -
 .../devices/{unixbluetooth.h => bluetooth.h}  |   8 +-
 include/devices/dku2libusb.h                  |  84 ----
 include/devices/linuxirda.h                   |   1 -
 include/devices/serial.h                      |   2 -
 include/devices/tcp.h                         |   2 -
 include/devices/unixirda.h                    |  15 -
 include/gnokii-internal.h                     |   2 +
 include/gnokii/data.h                         |  15 +-
 25 files changed, 463 insertions(+), 642 deletions(-)
 delete mode 100644 common/devices/bluetooth.c
 delete mode 100644 common/devices/irda.c
 create mode 100644 common/forkscript.c
 rename include/devices/{unixbluetooth.h => bluetooth.h} (82%)
 delete mode 100644 include/devices/unixirda.h

--
2.25.0


_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/9] Move device_script into separate file

Ladislav Michl
---
 common/Makefile.am        |  1 +
 common/device.c           | 59 ++----------------------------------
 common/forkscript.c       | 63 +++++++++++++++++++++++++++++++++++++++
 include/gnokii-internal.h |  2 ++
 4 files changed, 68 insertions(+), 57 deletions(-)
 create mode 100644 common/forkscript.c

diff --git a/common/Makefile.am b/common/Makefile.am
index 5e6be928..a762ada7 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -29,6 +29,7 @@ libgnokii_la_SOURCES = \
  gsm-statemachine.c \
  cfgreader.c \
  device.c \
+ forkscript.c \
  vcard.c \
  vcal.c \
  gnvcal.c \
diff --git a/common/device.c b/common/device.c
index 68257955..9b895708 100644
--- a/common/device.c
+++ b/common/device.c
@@ -27,66 +27,11 @@
 #include "devices/dku2libusb.h"
 #include "devices/socketphonet.h"
 
-#include <errno.h>
-#include <sys/wait.h>
-
 GNOKII_API int device_getfd(struct gn_statemachine *state)
 {
  return state->device.fd;
 }
 
-/* Script handling: */
-static void device_script_cfgfunc(const char *section, const char *key, const char *value)
-{
- setenv(key, value, 1); /* errors ignored */
-}
-
-int device_script(int fd, const char *section, struct gn_statemachine *state)
-{
- pid_t pid;
- const char *scriptname;
- int status;
-
- if (!strcmp(section, "connect_script"))
- scriptname = state->config.connect_script;
- else
- scriptname = state->config.disconnect_script;
- if (scriptname[0] == '\0')
- return 0;
-
- errno = 0;
- switch ((pid = fork())) {
- case -1:
- fprintf(stderr, _("device_script(\"%s\"): fork() failure: %s!\n"), scriptname, strerror(errno));
- return -1;
-
- case 0: /* child */
- cfg_foreach(section, device_script_cfgfunc);
- errno = 0;
- if (dup2(fd, 0) != 0 || dup2(fd, 1) != 1 || close(fd)) {
- fprintf(stderr, _("device_script(\"%s\"): file descriptor preparation failure: %s\n"), scriptname, strerror(errno));
- _exit(-1);
- }
- /* FIXME: close all open descriptors - how to track them?
- */
- execl("/bin/sh", "sh", "-c", scriptname, NULL);
- fprintf(stderr, _("device_script(\"%s\"): script execution failure: %s\n"), scriptname, strerror(errno));
- _exit(-1);
- /* NOTREACHED */
-
- default:
- if (pid == waitpid(pid, &status, 0 /* options */) && WIFEXITED(status) && !WEXITSTATUS(status))
- return 0;
- fprintf(stderr, _("device_script(\"%s\"): child script execution failure: %s, exit code=%d\n"), scriptname,
- (WIFEXITED(status) ? _("normal exit") : _("abnormal exit")),
- (WIFEXITED(status) ? WEXITSTATUS(status) : -1));
- errno = EIO;
- return -1;
-
- }
- /* NOTREACHED */
-}
-
 int device_open(const char *file, int with_odd_parity, int with_async,
  int with_hw_handshake, gn_connection_type device_type,
  struct gn_statemachine *state)
@@ -131,7 +76,7 @@ int device_open(const char *file, int with_odd_parity, int with_async,
  /*
  * handle config file connect_script:
  */
- if (device_script(state->device.fd, "connect_script", state) == -1) {
+ if (device_script(state->device.fd, 1, state) == -1) {
  dprintf("gnokii open device: connect_script failure\n");
  device_close(state);
  return 0;
@@ -147,7 +92,7 @@ void device_close(struct gn_statemachine *state)
  /*
  * handle config file disconnect_script:
  */
- if (device_script(state->device.fd, "disconnect_script", state) == -1)
+ if (device_script(state->device.fd, 0, state) == -1)
  dprintf("gnokii device close: disconnect_script failure\n");
 
  switch (state->device.type) {
diff --git a/common/forkscript.c b/common/forkscript.c
new file mode 100644
index 00000000..b094ea5f
--- /dev/null
+++ b/common/forkscript.c
@@ -0,0 +1,63 @@
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "cfgreader.h"
+#include "gnokii-internal.h"
+
+/* Script handling: */
+static void device_script_cfgfunc(const char *section, const char *key, const char *value)
+{
+ setenv(key, value, 1); /* errors ignored */
+}
+
+int device_script(int fd, int connect, struct gn_statemachine *state)
+{
+ const char *scriptname, *section;
+ int status;
+ pid_t pid;
+
+ if (connect) {
+ scriptname = state->config.connect_script;
+ section = "connect_script";
+ } else {
+ scriptname = state->config.disconnect_script;
+ section = "disconnect_script";
+ }
+ if (scriptname[0] == '\0')
+ return 0;
+
+ errno = 0;
+ switch ((pid = fork())) {
+ case -1:
+ fprintf(stderr, _("device_script(\"%s\"): fork() failure: %s!\n"), scriptname, strerror(errno));
+ return -1;
+
+ case 0: /* child */
+ cfg_foreach(section, device_script_cfgfunc);
+ errno = 0;
+ if (dup2(fd, 0) != 0 || dup2(fd, 1) != 1 || close(fd)) {
+ fprintf(stderr, _("device_script(\"%s\"): file descriptor preparation failure: %s\n"), scriptname, strerror(errno));
+ _exit(-1);
+ }
+ /* FIXME: close all open descriptors - how to track them?
+ */
+ execl("/bin/sh", "sh", "-c", scriptname, NULL);
+ fprintf(stderr, _("device_script(\"%s\"): script execution failure: %s\n"), scriptname, strerror(errno));
+ _exit(-1);
+ /* NOTREACHED */
+
+ default:
+ if (pid == waitpid(pid, &status, 0 /* options */) && WIFEXITED(status) && !WEXITSTATUS(status))
+ return 0;
+ fprintf(stderr, _("device_script(\"%s\"): child script execution failure: %s, exit code=%d\n"), scriptname,
+ (WIFEXITED(status) ? _("normal exit") : _("abnormal exit")),
+ (WIFEXITED(status) ? WEXITSTATUS(status) : -1));
+ errno = EIO;
+ return -1;
+
+ }
+ /* NOTREACHED */
+}
diff --git a/include/gnokii-internal.h b/include/gnokii-internal.h
index c4f6d625..212b0a75 100644
--- a/include/gnokii-internal.h
+++ b/include/gnokii-internal.h
@@ -176,6 +176,8 @@ int utf8_base64_encode(char *dest, int destlen, const char *src, int inlen);
 int add_slashes(char *dest, char *src, int maxlen, int len);
 int strip_slashes(char *dest, const char *src, int maxlen, int len);
 
+int device_script(int fd, int connect, struct gn_statemachine *state);
+
 /* authentication for at driver */
 gn_error do_auth(gn_auth_type auth_type, struct gn_statemachine *state);
 
--
2.25.0


_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/9] Cleanup device includes

Ladislav Michl
In reply to this post by Ladislav Michl
Device include files now do not need to include anything but gnokii.h
---
 include/devices/linuxirda.h     | 1 -
 include/devices/serial.h        | 2 --
 include/devices/tcp.h           | 2 --
 include/devices/unixbluetooth.h | 2 --
 4 files changed, 7 deletions(-)

diff --git a/include/devices/linuxirda.h b/include/devices/linuxirda.h
index 25cdc1a9..d3913941 100644
--- a/include/devices/linuxirda.h
+++ b/include/devices/linuxirda.h
@@ -36,7 +36,6 @@
 #ifndef __gnokii_linuxirda_h
 #define __gnokii_linuxirda_h
 
-#include "config.h"
 #include "compat.h"
 
 /* Hint bit positions for first hint byte */
diff --git a/include/devices/serial.h b/include/devices/serial.h
index cb56a823..320b37e7 100644
--- a/include/devices/serial.h
+++ b/include/devices/serial.h
@@ -13,8 +13,6 @@
 #ifndef __devices_serial_h
 #define __devices_serial_h
 
-#include "compat.h"
-#include "misc.h"
 #include "gnokii.h"
 
 int serial_open(const char *file, int oflag);
diff --git a/include/devices/tcp.h b/include/devices/tcp.h
index 0e3786e7..6226e734 100644
--- a/include/devices/tcp.h
+++ b/include/devices/tcp.h
@@ -13,8 +13,6 @@
 #ifndef __devices_tcp_h
 #define __devices_tcp_h
 
-#include "compat.h"
-#include "misc.h"
 #include "gnokii.h"
 
 int tcp_opendevice(const char *file, int with_async, struct gn_statemachine *state);
diff --git a/include/devices/unixbluetooth.h b/include/devices/unixbluetooth.h
index 81cad19b..db4171e9 100644
--- a/include/devices/unixbluetooth.h
+++ b/include/devices/unixbluetooth.h
@@ -14,8 +14,6 @@
 #ifndef _gnokii_unix_bluetooth_h
 #define _gnokii_unix_bluetooth_h
 
-#include "compat.h"
-#include "misc.h"
 #include "gnokii.h"
 
 int bluetooth_open(const char *addr, uint8_t channel, struct gn_statemachine *state);
--
2.25.0


_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

[PATCH 3/9] configure.ac: do not mix library and device support checks

Ladislav Michl
In reply to this post by Ladislav Michl
---
 configure.ac | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/configure.ac b/configure.ac
index c4ca15af..512a620d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -356,6 +356,26 @@ AC_ARG_WITH(readline,
 AC_SUBST(TERMLIBS)
 AC_SUBST(TERMLDFLAGS)
 
+dnl ======================== Checks for gethostbyname support
+AC_CHECK_FUNC(gethostbyname, ,
+ AC_CHECK_LIB(nsl, gethostbyname, TCP_LIBS="-lnsl"
+     AC_SUBST(TCP_LIBS)))
+dnl Haiku requires -lnetwork for socket functions
+AC_CHECK_FUNC(gethostbyname, ,
+ AC_CHECK_LIB(network, gethostbyname, TCP_LIBS="-lnetwork"
+     AC_SUBST(TCP_LIBS)))
+
+dnl ======================== Defines location for gettext
+AC_ARG_WITH(gettext,
+ [  --with-gettext=DIR      specifies the base gettext],
+ [ if test x$withval = xyes; then
+ AC_MSG_WARN(Usage is: --with-gettext=DIR)
+  else
+ CFLAGS="$CFLAGS -I$withval"
+  fi
+ ]
+)
+
 dnl ======================== Check for libical
 AC_ARG_WITH(libical,
    [  --with-libical=DIR      specifies the base libical],
@@ -454,15 +474,6 @@ if test "$enable_phonet" = "yes"; then
  #include <linux/phonet.h>])
 fi
 
-dnl ======================== Checks for gethostbyname support
-AC_CHECK_FUNC(gethostbyname, ,
- AC_CHECK_LIB(nsl, gethostbyname, TCP_LIBS="-lnsl"
-     AC_SUBST(TCP_LIBS)))
-dnl Haiku requires -lnetwork for socket functions
-AC_CHECK_FUNC(gethostbyname, ,
- AC_CHECK_LIB(network, gethostbyname, TCP_LIBS="-lnetwork"
-     AC_SUBST(TCP_LIBS)))
-
 dnl ======================== Checks for Linux IrDA support
 USE_IRDA="no"
 AC_ARG_ENABLE(irda,
@@ -479,17 +490,6 @@ if test "$enable_irda" = "yes"; then
  #include <linux/types.h>])
 fi
 
-dnl ======================== Defines location for gettext
-AC_ARG_WITH(gettext,
- [  --with-gettext=DIR      specifies the base gettext],
- [ if test x$withval = xyes; then
- AC_MSG_WARN(Usage is: --with-gettext=DIR)
-  else
- CFLAGS="$CFLAGS -I$withval"
-  fi
- ]
-)
-
 dnl ======================== Checks for Bluetooth support
 USE_BLUETOOTH="no"
 AC_ARG_WITH(bluetooth,
--
2.25.0


_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

[PATCH 4/9] Remove nowhere used device_reset()

Ladislav Michl
In reply to this post by Ladislav Michl
---
 common/device.c  | 5 -----
 include/device.h | 1 -
 2 files changed, 6 deletions(-)

diff --git a/common/device.c b/common/device.c
index 9b895708..e82db111 100644
--- a/common/device.c
+++ b/common/device.c
@@ -127,11 +127,6 @@ void device_close(struct gn_statemachine *state)
  state->device.device_instance = NULL;
 }
 
-void device_reset(struct gn_statemachine *state)
-{
- return;
-}
-
 void device_setdtrrts(int dtr, int rts, struct gn_statemachine *state)
 {
  switch (state->device.type) {
diff --git a/include/device.h b/include/device.h
index d45f32b7..8e84e074 100644
--- a/include/device.h
+++ b/include/device.h
@@ -26,7 +26,6 @@ int device_open(const char *file, int with_odd_parity, int with_async,
  int with_hw_handshake, gn_connection_type device_type,
  struct gn_statemachine *state);
 void device_close(struct gn_statemachine *state);
-void device_reset(struct gn_statemachine *state);
 
 void device_setdtrrts(int dtr, int rts, struct gn_statemachine *state);
 void device_changespeed(int speed, struct gn_statemachine *state);
--
2.25.0


_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

[PATCH 5/9] Remove misleading comments from tcp device

Ladislav Michl
In reply to this post by Ladislav Michl
---
 common/devices/tcp.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/common/devices/tcp.c b/common/devices/tcp.c
index af9ed7ee..e2bcde46 100644
--- a/common/devices/tcp.c
+++ b/common/devices/tcp.c
@@ -40,8 +40,6 @@
 #  define O_NONBLOCK  0
 #endif
 
-/* Open the serial port and store the settings. */
-
 static int tcp_open(const char *file)
 {
  int fd;
@@ -138,9 +136,6 @@ int tcp_close(int fd, struct gn_statemachine *state)
  return close(fd);
 }
 
-/* Open a device with standard options.
- * Use value (-1) for "with_hw_handshake" if its specification is required from the user
- */
 int tcp_opendevice(const char *file, int with_async, struct gn_statemachine *state)
 {
  int fd;
@@ -193,16 +188,11 @@ int tcp_select(int fd, struct timeval *timeout, struct gn_statemachine *state)
  return serial_select(fd, timeout, state);
 }
 
-
-/* Read from serial device. */
-
 size_t tcp_read(int fd, __ptr_t buf, size_t nbytes, struct gn_statemachine *state)
 {
  return read(fd, buf, nbytes);
 }
 
-/* Write to serial device. */
-
 size_t tcp_write(int fd, const __ptr_t buf, size_t n, struct gn_statemachine *state)
 {
  return write(fd, buf, n);
--
2.25.0


_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

[PATCH 6/9] dku2libusb: move definitions into C file

Ladislav Michl
In reply to this post by Ladislav Michl
---
 common/devices/dku2libusb.c  | 78 +++++++++++++++++++++++++++++++++
 include/devices/dku2libusb.h | 84 ------------------------------------
 2 files changed, 78 insertions(+), 84 deletions(-)

diff --git a/common/devices/dku2libusb.c b/common/devices/dku2libusb.c
index 79dd9ad9..fe5fc4f3 100644
--- a/common/devices/dku2libusb.c
+++ b/common/devices/dku2libusb.c
@@ -57,6 +57,84 @@ int fbusdku2usb_select(struct timeval *timeout, struct gn_statemachine *state)
 
 #else
 
+#include <usb.h>
+
+/* Information about a USB DKU2 FBUS interface present on the system */
+struct fbus_usb_interface_transport {
+ struct fbus_usb_interface_transport *prev, *next; /* Next and previous interfaces in the list */
+ struct usb_device *device; /* USB device that has the interface */
+ int configuration; /* Device configuration */
+ int configuration_description; /* Configuration string descriptor number */
+ int control_interface; /* DKU2 FBUS master interface */
+ int control_setting; /* DKU2 FBUS master interface setting */
+ int control_interface_description; /* DKU2 FBUS master interface string descriptor number
+ * If non-zero, use usb_get_string_simple() from
+ * libusb to retrieve human-readable description
+ */
+ int data_interface; /* DKU2 FBUS data/slave interface */
+ int data_idle_setting; /* DKU2 FBUS data/slave idle setting */
+ int data_interface_idle_description; /* DKU2 FBUS data/slave interface string descriptor number
+ * in idle setting */
+ int data_active_setting; /* DKU2 FBUS data/slave active setting */
+ int data_interface_active_description; /* DKU2 FBUS data/slave interface string descriptor number
+ * in active setting */
+ int data_endpoint_read; /* DKU2 FBUS data/slave interface read endpoint */
+ int data_endpoint_write; /* DKU2 FBUS data/slave interface write endpoint */
+ usb_dev_handle *dev_control; /* libusb handler for control interace */
+ usb_dev_handle *dev_data; /* libusb handler for data interface */
+};
+
+/* USB-specific FBUS interface information */
+typedef struct {
+ /* Manufacturer, e.g. Nokia */
+ char *manufacturer;
+ /* Product, e.g. Nokia 6680 */
+ char *product;
+ /* Product serial number */
+ char *serial;
+ /* USB device configuration description */
+ char *configuration;
+ /* Control interface description */
+ char *control_interface;
+ /* Idle data interface description, typically empty */
+ char *data_interface_idle;
+ /* Active data interface description, typically empty */
+ char *data_interface_active;
+ /* Internal information for the transport layer in the library */
+ struct fbus_usb_interface_transport *interface;
+} fbus_usb_interface;
+
+/* "Union Functional Descriptor" from CDC spec 5.2.3.X
+ * used to find data/slave DKU2 FBUS interface */
+#pragma pack(1)
+struct cdc_union_desc {
+ u_int8_t      bLength;
+ u_int8_t      bDescriptorType;
+ u_int8_t      bDescriptorSubType;
+
+ u_int8_t      bMasterInterface0;
+ u_int8_t      bSlaveInterface0;
+};
+#pragma pack()
+
+/* Nokia is the vendor we are interested in */
+#define NOKIA_VENDOR_ID 0x0421
+
+/* CDC class and subclass types */
+#define USB_CDC_CLASS 0x02
+#define USB_CDC_FBUS_SUBCLASS 0xfe
+
+/* class and subclass specific descriptor types */
+#define CDC_HEADER_TYPE 0x00
+#define CDC_UNION_TYPE 0x06
+#define CDC_FBUS_TYPE 0x15
+
+/* Interface descriptor */
+#define USB_DT_CS_INTERFACE 0x24
+
+#define USB_MAX_STRING_SIZE 256
+#define USB_FBUS_TIMEOUT 10000 /* 10 seconds */
+
 #define DEVINSTANCE(s) (*((fbus_usb_interface **)(&(s)->device.device_instance)))
 
 /*
diff --git a/include/devices/dku2libusb.h b/include/devices/dku2libusb.h
index be4d4ba4..7cc1cb90 100644
--- a/include/devices/dku2libusb.h
+++ b/include/devices/dku2libusb.h
@@ -16,94 +16,10 @@
 #ifndef _gnokii_dku2libusb_h
 #define _gnokii_dku2libusb_h
 
-#ifdef HAVE_LIBUSB
-#  include <usb.h>
-#endif
-
 #include "compat.h"
 #include "misc.h"
 #include "gnokii.h"
 
-#ifdef HAVE_LIBUSB
-
-/* Information about a USB DKU2 FBUS interface present on the system */
-struct fbus_usb_interface_transport {
- struct fbus_usb_interface_transport *prev, *next; /* Next and previous interfaces in the list */
- struct usb_device *device; /* USB device that has the interface */
- int configuration; /* Device configuration */
- int configuration_description; /* Configuration string descriptor number */
- int control_interface; /* DKU2 FBUS master interface */
- int control_setting; /* DKU2 FBUS master interface setting */
- int control_interface_description; /* DKU2 FBUS master interface string descriptor number
- * If non-zero, use usb_get_string_simple() from
- * libusb to retrieve human-readable description
- */
- int data_interface; /* DKU2 FBUS data/slave interface */
- int data_idle_setting; /* DKU2 FBUS data/slave idle setting */
- int data_interface_idle_description; /* DKU2 FBUS data/slave interface string descriptor number
- * in idle setting */
- int data_active_setting; /* DKU2 FBUS data/slave active setting */
- int data_interface_active_description; /* DKU2 FBUS data/slave interface string descriptor number
- * in active setting */
- int data_endpoint_read; /* DKU2 FBUS data/slave interface read endpoint */
- int data_endpoint_write; /* DKU2 FBUS data/slave interface write endpoint */
- usb_dev_handle *dev_control; /* libusb handler for control interace */
- usb_dev_handle *dev_data; /* libusb handler for data interface */
-};
-
-/* USB-specific FBUS interface information */
-typedef struct {
- /* Manufacturer, e.g. Nokia */
- char *manufacturer;
- /* Product, e.g. Nokia 6680 */
- char *product;
- /* Product serial number */
- char *serial;
- /* USB device configuration description */
- char *configuration;
- /* Control interface description */
- char *control_interface;
- /* Idle data interface description, typically empty */
- char *data_interface_idle;
- /* Active data interface description, typically empty */
- char *data_interface_active;
- /* Internal information for the transport layer in the library */
- struct fbus_usb_interface_transport *interface;
-} fbus_usb_interface;
-
-/* "Union Functional Descriptor" from CDC spec 5.2.3.X
- * used to find data/slave DKU2 FBUS interface */
-#pragma pack(1)
-struct cdc_union_desc {
- u_int8_t      bLength;
- u_int8_t      bDescriptorType;
- u_int8_t      bDescriptorSubType;
-
- u_int8_t      bMasterInterface0;
- u_int8_t      bSlaveInterface0;
-};
-#pragma pack()
-
-/* Nokia is the vendor we are interested in */
-#define NOKIA_VENDOR_ID 0x0421
-
-/* CDC class and subclass types */
-#define USB_CDC_CLASS 0x02
-#define USB_CDC_FBUS_SUBCLASS 0xfe
-
-/* class and subclass specific descriptor types */
-#define CDC_HEADER_TYPE 0x00
-#define CDC_UNION_TYPE 0x06
-#define CDC_FBUS_TYPE 0x15
-
-/* Interface descriptor */
-#define USB_DT_CS_INTERFACE 0x24
-
-#define USB_MAX_STRING_SIZE 256
-#define USB_FBUS_TIMEOUT 10000 /* 10 seconds */
-
-#endif
-
 int fbusdku2usb_open(struct gn_statemachine *state);
 int fbusdku2usb_close(struct gn_statemachine *state);
 int fbusdku2usb_write(const __ptr_t bytes, int size, struct gn_statemachine *state);
--
2.25.0


_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

[PATCH 7/9] dku2libusb: whitespace cleanup

Ladislav Michl
In reply to this post by Ladislav Michl
---
 common/devices/dku2libusb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/devices/dku2libusb.c b/common/devices/dku2libusb.c
index fe5fc4f3..0a6eb8a1 100644
--- a/common/devices/dku2libusb.c
+++ b/common/devices/dku2libusb.c
@@ -469,7 +469,7 @@ static int usbfbus_connect_request(struct gn_statemachine *state)
  return 1;
 
 err3:
- usb_release_interface(DEVINSTANCE(state)->interface->dev_data, DEVINSTANCE(state)->interface->data_interface);
+ usb_release_interface(DEVINSTANCE(state)->interface->dev_data, DEVINSTANCE(state)->interface->data_interface);
 err2:
  usb_release_interface(DEVINSTANCE(state)->interface->dev_data, DEVINSTANCE(state)->interface->control_interface);
 err1:
@@ -501,7 +501,7 @@ static int usbfbus_disconnect_request(struct gn_statemachine *state)
  ret = usb_close(DEVINSTANCE(state)->interface->dev_data);
  if (ret < 0)
  dprintf("Can't close data interface %d\n", ret);
- return ret;
+ return ret;
 }
 
 int fbusdku2usb_open(struct gn_statemachine *state)
--
2.25.0


_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

[PATCH 8/9] libfunctions: reimplement gn_lib_is_connectiontype_supported

Ladislav Michl
In reply to this post by Ladislav Michl
We already do have a list of supported connectionis in connectiontypes
array, so use it here as well. This removes another #ifdeffery
and fixed bug where condition for TCP was inverted.
---
 common/libfunctions.c | 54 ++++---------------------------------------
 1 file changed, 5 insertions(+), 49 deletions(-)

diff --git a/common/libfunctions.c b/common/libfunctions.c
index d72cf4aa..3db61b1e 100644
--- a/common/libfunctions.c
+++ b/common/libfunctions.c
@@ -542,55 +542,11 @@ GNOKII_API const char *gn_lib_get_connection_name(gn_connection_type ct)
 
 GNOKII_API int gn_lib_is_connectiontype_supported(gn_connection_type ct)
 {
- switch (ct) {
- case GN_CT_Serial:
- case GN_CT_DAU9P:
- case GN_CT_DLR3P:
- case GN_CT_M2BUS:
- case GN_CT_Tekram:
- return 1;
- case GN_CT_Infrared:
- case GN_CT_Irda:
-#ifdef HAVE_IRDA
- return 1;
-#else
- return 0;
-#endif
- case GN_CT_Bluetooth:
-#ifdef HAVE_BLUETOOTH
- return 1;
-#else
- return 0;
-#endif
- case GN_CT_DKU2: /* FIXME: How to detect this? */
- return 1;
- case GN_CT_DKU2LIBUSB:
-#ifdef HAVE_LIBUSB
- return 1;
-#else
- return 0;
-#endif
- case GN_CT_PCSC:
-#ifdef HAVE_PCSC
- return 1;
-#else
- return 0;
-#endif
- case GN_CT_TCP:
-#ifndef WIN32
- return 0;
-#else
- return 1;
-#endif
- case GN_CT_SOCKETPHONET:
-#ifndef HAVE_SOCKETPHONET
- return 0;
-#else
- return 1;
-#endif
- default:
- return 0;
- }
+ int i;
+ for (i = 0; i < sizeof(connectiontypes)/sizeof(connectiontypes[0]); i++)
+ if (ct == connectiontypes[i].ct)
+ return 1;
+ return 0;
 }
 
 GNOKII_API gn_error gn_lib_search_one_connected_phone(struct gn_statemachine **state)
--
2.25.0


_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

[PATCH 9/9] Refactor devices build

Ladislav Michl
In reply to this post by Ladislav Michl
Introduce basic device plugin architecture, which allows to
remove #ifdefs from device drivers and compile them only when
selected and also remove stub functions returning -1 for not
compiled drivers.
As some function prototypes differs between device drivers,
use _ prefixed compatibility wrappers which are expected
to vanish again with one by one driver unification.
Once there, move device detection code in configure.ac to live
in one place.
---
 common/device.c                               | 345 ++++++++++--------
 common/devices/Makefile.am                    |  57 +--
 common/devices/bluetooth.c                    |  31 --
 common/devices/dku2libusb.c                   |  30 --
 common/devices/irda.c                         |  27 --
 common/devices/osxbluetooth.m                 |   8 +-
 common/devices/socketphonet.c                 |  38 +-
 common/devices/tcp.c                          |  32 --
 common/devices/unixbluetooth.c                |  13 +-
 common/devices/unixirda.c                     |   8 +-
 common/devices/winbluetooth.c                 |  10 +-
 common/devices/winirda.c                      |   7 +-
 configure.ac                                  |  69 ++--
 .../devices/{unixbluetooth.h => bluetooth.h}  |   6 +-
 include/devices/unixirda.h                    |  15 -
 include/gnokii/data.h                         |  15 +-
 16 files changed, 297 insertions(+), 414 deletions(-)
 delete mode 100644 common/devices/bluetooth.c
 delete mode 100644 common/devices/irda.c
 rename include/devices/{unixbluetooth.h => bluetooth.h} (86%)
 delete mode 100644 include/devices/unixirda.h

diff --git a/common/device.c b/common/device.c
index e82db111..2fb6b4c3 100644
--- a/common/device.c
+++ b/common/device.c
@@ -19,13 +19,172 @@
 #include "gnokii.h"
 #include "gnokii-internal.h"
 #include "device.h"
+
+#ifdef HAVE_BLUETOOTH
+#include "devices/bluetooth.h"
+static int
+_bluetooth_open(const char *file, int with_odd_parity, int with_async,
+ int with_hw_handshake, struct gn_statemachine *state)
+{
+ return bluetooth_open(state->config.port_device, state->config.rfcomm_cn, state);
+}
+
+const static gn_device_ops _bluetooth_ops = {
+ .open = _bluetooth_open,
+ .close = bluetooth_close,
+ .select = bluetooth_select,
+ .read = bluetooth_read,
+ .write = bluetooth_write,
+};
+#  define bluetooth_ops &_bluetooth_ops
+#else
+#  define bluetooth_ops NULL
+#endif
+
+#ifdef HAVE_LIBUSB
+#include "devices/dku2libusb.h"
+static int
+_dku2libusb_open(const char *file, int with_odd_parity, int with_async,
+ int with_hw_handshake, struct gn_statemachine *state)
+{
+ return fbusdku2usb_open(state);
+}
+
+static int
+_dku2libusb_close(int fd, struct gn_statemachine *state)
+{
+ return fbusdku2usb_close(state);
+}
+
+static int
+_dku2usb_select(struct timeval *timeout, struct gn_statemachine *state);
+{
+ return fbusdku2usb_select(timeout, state);
+}
+
+static int
+_dku2usb_read(__ptr_t bytes, int size, struct gn_statemachine *state)
+{
+ return fbusdku2usb_read(bytes, size, state);
+}
+
+static int
+_dku2usb_write(int fd, const __ptr_t bytes, int size, struct gn_statemachine *state)
+{
+ return fbusdku2usb_write(bytes, size, state);
+}
+
+const static gn_device_ops _dku2libusb_ops = {
+ .open = _dku2libusb_open,
+ .close = _dku2usb_close,
+ .select = _dku2usb_select,
+ .read = _dku2usb_read,
+ .write = _dku2usb_write,
+};
+#  define dku2libusb_ops &_dku2libusb_ops
+#else
+#  define dku2libusb_ops NULL
+#endif
+
+#ifdef HAVE_IRDA
 #include "devices/irda.h"
-#include "devices/unixbluetooth.h"
-#include "devices/tcp.h"
+static int
+_irda_open(const char *file, int with_odd_parity, int with_async,
+   int with_hw_handshake, struct gn_statemachine *state)
+{
+ return irda_open(state);
+}
+
+const static gn_device_ops _irda_ops = {
+ .open = _irda_open,
+ .close = irda_close,
+ .select = irda_select,
+ .read = irda_read,
+ .write = irda_write,
+};
+#  define irda_ops &_irda_ops
+#else
+#  define irda_ops NULL
+#endif
+
 #include "devices/serial.h"
-#include "devices/tekram.h"
-#include "devices/dku2libusb.h"
+const static gn_device_ops _serial_ops = {
+ .open = serial_opendevice,
+ .close = serial_close,
+ .select = serial_select,
+ .read = serial_read,
+ .write = serial_write,
+ .nreceived = serial_nreceived,
+ .flush = serial_flush,
+ .changespeed = serial_changespeed,
+ .setdtrrts = serial_setdtrrts,
+};
+#define serial_ops &_serial_ops
+
+#ifdef HAVE_SOCKETPHONET
 #include "devices/socketphonet.h"
+static int
+_socketphonet_open(const char *file, int with_odd_parity, int with_async,
+   int with_hw_handshake, struct gn_statemachine *state)
+{
+ return socketphonet_open(file, with_async, state);
+}
+
+static int
+_socketphonet_close(int fd, struct gn_statemachine *state)
+{
+ return socketphonet_close(state);
+}
+
+const static gn_device_ops _phonet_ops = {
+ .open = _socketphonet_open,
+ .close = _socketphonet_close,
+ .select = socketphonet_select,
+ .read = socketphonet_read,
+ .write = socketphonet_write,
+};
+#  define phonet_ops &_phonet_ops
+#else
+#  define phonet_ops NULL
+#endif
+
+#ifndef WIN32
+#include "devices/tcp.h"
+static int
+_tcp_open(const char *file, int with_odd_parity, int with_async,
+  int with_hw_handshake, struct gn_statemachine *state)
+{
+ return tcp_opendevice(file, with_async, state);
+}
+
+const static gn_device_ops _tcp_ops = {
+ .open = _tcp_open,
+ .close = tcp_close,
+ .select = tcp_select,
+ .read = tcp_read,
+ .write = tcp_write,
+};
+#  define tcp_ops &_tcp_ops
+#else
+#  define tcp_ops NULL
+#endif
+
+#include "devices/tekram.h"
+static int
+_tekram_open(const char *file, int with_odd_parity, int with_async,
+     int with_hw_handshake, struct gn_statemachine *state)
+{
+ return tekram_open(file, state);
+}
+
+const static gn_device_ops _tekram_ops = {
+ .open = _tekram_open,
+ .close = tekram_close,
+ .select = tekram_select,
+ .read = tekram_read,
+ .write = tekram_write,
+};
+#define tekram_ops &_tekram_ops
 
 GNOKII_API int device_getfd(struct gn_statemachine *state)
 {
@@ -36,40 +195,46 @@ int device_open(const char *file, int with_odd_parity, int with_async,
  int with_hw_handshake, gn_connection_type device_type,
  struct gn_statemachine *state)
 {
- state->device.type = device_type;
+ state->device.ops = NULL;
  state->device.device_instance = NULL;
 
  dprintf("device: opening device %s\n", (device_type == GN_CT_DKU2LIBUSB) ? "USB" : file);
 
- switch (state->device.type) {
- case GN_CT_DKU2:
+ switch (device_type) {
  case GN_CT_Serial:
+ case GN_CT_DAU9P:
+ case GN_CT_DLR3P:
  case GN_CT_Infrared:
- state->device.fd = serial_opendevice(file, with_odd_parity, with_async, with_hw_handshake, state);
+ case GN_CT_M2BUS:
+ case GN_CT_DKU2:
+ state->device.ops = serial_ops;
  break;
  case GN_CT_Irda:
- state->device.fd = irda_open(state);
+ state->device.ops = irda_ops;
  break;
  case GN_CT_Bluetooth:
- state->device.fd = bluetooth_open(state->config.port_device, state->config.rfcomm_cn, state);
+ state->device.ops = bluetooth_ops;
  break;
  case GN_CT_Tekram:
- state->device.fd = tekram_open(file, state);
+ state->device.ops = tekram_ops;
  break;
  case GN_CT_TCP:
- state->device.fd = tcp_opendevice(file, with_async, state);
+ state->device.ops = tcp_ops;
  break;
  case GN_CT_DKU2LIBUSB:
- state->device.fd = fbusdku2usb_open(state);
+ state->device.ops = dku2libusb_ops;
  break;
  case GN_CT_SOCKETPHONET:
- state->device.fd = socketphonet_open(file, with_async, state);
+ state->device.ops = phonet_ops;
  break;
  default:
- state->device.fd = -1;
  break;
  }
 
+ if (!state->device.ops)
+ return 0;
+
+ state->device.fd = state->device.ops->open(file, with_odd_parity, with_async, with_hw_handshake, state);
  if (state->device.fd < 0)
  return 0;
 
@@ -95,33 +260,7 @@ void device_close(struct gn_statemachine *state)
  if (device_script(state->device.fd, 0, state) == -1)
  dprintf("gnokii device close: disconnect_script failure\n");
 
- switch (state->device.type) {
- case GN_CT_DKU2:
- case GN_CT_Serial:
- case GN_CT_Infrared:
- serial_close(state->device.fd, state);
- break;
- case GN_CT_Irda:
- irda_close(state->device.fd, state);
- break;
- case GN_CT_Bluetooth:
- bluetooth_close(state->device.fd, state);
- break;
- case GN_CT_Tekram:
- tekram_close(state->device.fd, state);
- break;
- case GN_CT_TCP:
- tcp_close(state->device.fd, state);
- break;
- case GN_CT_DKU2LIBUSB:
- fbusdku2usb_close(state);
- break;
- case GN_CT_SOCKETPHONET:
- socketphonet_close(state);
- break;
- default:
- break;
- }
+ state->device.ops->close(state->device.fd, state);
 
  free(state->device.device_instance);
  state->device.device_instance = NULL;
@@ -129,144 +268,48 @@ void device_close(struct gn_statemachine *state)
 
 void device_setdtrrts(int dtr, int rts, struct gn_statemachine *state)
 {
- switch (state->device.type) {
- case GN_CT_DKU2:
- case GN_CT_Serial:
- case GN_CT_Infrared:
+ if (state->device.ops->setdtrrts) {
  dprintf("device: setting RTS to %s and DTR to %s\n", rts ? "high" : "low", dtr ? "high" : "low");
- serial_setdtrrts(state->device.fd, dtr, rts, state);
- break;
- case GN_CT_Irda:
- case GN_CT_Bluetooth:
- case GN_CT_Tekram:
- case GN_CT_TCP:
- case GN_CT_DKU2LIBUSB:
- case GN_CT_SOCKETPHONET:
- default:
- break;
+ state->device.ops->setdtrrts(state->device.fd, dtr, rts, state);
  }
 }
 
 void device_changespeed(int speed, struct gn_statemachine *state)
 {
- switch (state->device.type) {
- case GN_CT_DKU2:
- case GN_CT_Serial:
- case GN_CT_Infrared:
+ if (state->device.ops->changespeed) {
  dprintf("device: setting speed to %d\n", speed);
- serial_changespeed(state->device.fd, speed, state);
- break;
- case GN_CT_Tekram:
- dprintf("device: setting speed to %d\n", speed);
- tekram_changespeed(state->device.fd, speed, state);
- break;
- case GN_CT_Irda:
- case GN_CT_Bluetooth:
- case GN_CT_TCP:
- case GN_CT_DKU2LIBUSB:
- case GN_CT_SOCKETPHONET:
- default:
- break;
+ state->device.ops->changespeed(state->device.fd, speed, state);
  }
 }
 
 size_t device_read(__ptr_t buf, size_t nbytes, struct gn_statemachine *state)
 {
- switch (state->device.type) {
- case GN_CT_DKU2:
- case GN_CT_Serial:
- case GN_CT_Infrared:
- return serial_read(state->device.fd, buf, nbytes, state);
- case GN_CT_Irda:
- return irda_read(state->device.fd, buf, nbytes, state);
- case GN_CT_Bluetooth:
- return bluetooth_read(state->device.fd, buf, nbytes, state);
- case GN_CT_Tekram:
- return tekram_read(state->device.fd, buf, nbytes, state);
- case GN_CT_TCP:
- return tcp_read(state->device.fd, buf, nbytes, state);
- case GN_CT_DKU2LIBUSB:
- return fbusdku2usb_read(buf, nbytes, state);
- case GN_CT_SOCKETPHONET:
- return socketphonet_read(state->device.fd, buf, nbytes, state);
- default:
- break;
- }
- return 0;
+ return state->device.ops->read(state->device.fd, buf, nbytes, state);
 }
 
 size_t device_write(const __ptr_t buf, size_t n, struct gn_statemachine *state)
 {
- switch (state->device.type) {
- case GN_CT_DKU2:
- case GN_CT_Serial:
- case GN_CT_Infrared:
- return serial_write(state->device.fd, buf, n, state);
- case GN_CT_Irda:
- return irda_write(state->device.fd, buf, n, state);
- case GN_CT_Bluetooth:
- return bluetooth_write(state->device.fd, buf, n, state);
- case GN_CT_Tekram:
- return tekram_write(state->device.fd, buf, n, state);
- case GN_CT_TCP:
- return tcp_write(state->device.fd, buf, n, state);
- case GN_CT_DKU2LIBUSB:
- return fbusdku2usb_write(buf, n, state);
- case GN_CT_SOCKETPHONET:
- return socketphonet_write(state->device.fd, buf, n, state);
- default:
- break;
- }
- return 0;
+ return state->device.ops->write(state->device.fd, buf, n, state);
 }
 
 int device_select(struct timeval *timeout, struct gn_statemachine *state)
 {
- switch (state->device.type) {
- case GN_CT_DKU2:
- case GN_CT_Serial:
- case GN_CT_Infrared:
- return serial_select(state->device.fd, timeout, state);
- case GN_CT_Irda:
- return irda_select(state->device.fd, timeout, state);
- case GN_CT_Bluetooth:
- return bluetooth_select(state->device.fd, timeout, state);
- case GN_CT_Tekram:
- return tekram_select(state->device.fd, timeout, state);
- case GN_CT_TCP:
- return tcp_select(state->device.fd, timeout, state);
- case GN_CT_DKU2LIBUSB:
- return fbusdku2usb_select(timeout, state);
- case GN_CT_SOCKETPHONET:
- return socketphonet_select(state->device.fd, timeout, state);
- default:
- break;
- }
- return -1;
+ return state->device.ops->select(state->device.fd, timeout, state);
 }
 
 gn_error device_nreceived(int *n, struct gn_statemachine *state)
 {
  *n = -1;
-
- switch (state->device.type) {
- case GN_CT_DKU2:
- case GN_CT_Serial:
- case GN_CT_Infrared:
- return serial_nreceived(state->device.fd, n, state);
- default:
+ if (!state->device.ops->nreceived)
  return GN_ERR_NOTSUPPORTED;
- }
+
+ return state->device.ops->nreceived(state->device.fd, n, state);
 }
 
 gn_error device_flush(struct gn_statemachine *state)
 {
- switch (state->device.type) {
- case GN_CT_DKU2:
- case GN_CT_Serial:
- case GN_CT_Infrared:
- return serial_flush(state->device.fd, state);
- default:
+ if (!state->device.ops->flush)
  return GN_ERR_NOTSUPPORTED;
- }
+
+ return state->device.ops->flush(state->device.fd, state);
 }
diff --git a/common/devices/Makefile.am b/common/devices/Makefile.am
index 860762e4..592c2b9d 100644
--- a/common/devices/Makefile.am
+++ b/common/devices/Makefile.am
@@ -1,34 +1,38 @@
 noinst_LTLIBRARIES = libDEVICES.la
 
-WIN32_FILES = \
- winserial.c \
- winirda.c \
- winbluetooth.c
-
-UNIX_FILES = \
- unixserial.c \
- unixirda.c \
- tcp.c \
- socketphonet.c
-
-if FOR_MAC
-UNIX_SPECIFIC_FILES = osxbluetooth.m
-else
-UNIX_SPECIFIC_FILES = unixbluetooth.c
+gnokii_devices = tekram.c
+if LIBUSB
+gnokii_devices += dku2libusb.c
+endif
+if !WIN32
+gnokii_devices += tcp.c
+endif
+if SOCKETPHONET
+gnokii_devices += socketphonet.c
+endif
+if OSXBLUETOOTH
+gnokii_devices += osxbluetooth.m
+endif
+if UNIXBLUETOOTH
+gnokii_devices += unixbluetooth.c
+endif
+if UNIXIRDA
+gnokii_devices += unixirda.c
+endif
+if !WIN32
+gnokii_devices += unixserial.c
+endif
+if WINBLUETOOTH
+gnokii_devices += winbluetooth.c
+endif
+if WINIRDA
+gnokii_devices += winirda.c
 endif
-
 if WIN32
-PLATFORM_FILES = $(WIN32_FILES)
-else
-PLATFORM_FILES = $(UNIX_FILES) $(UNIX_SPECIFIC_FILES)
+gnokii_devices += winserial.c
 endif
 
-libDEVICES_la_SOURCES = \
- $(PLATFORM_FILES) \
- tekram.c \
- irda.c \
- dku2libusb.c \
- bluetooth.c
+libDEVICES_la_SOURCES = $(gnokii_devices)
 
 libDEVICES_la_CFLAGS = \
  -I$(top_srcdir)/include
@@ -37,6 +41,3 @@ libDEVICES_la_LIBADD = \
  $(USB_LIBS) \
  $(BLUETOOTH_LIBS) \
  $(TCP_LIBS)
-
-EXTRA_DIST = $(WIN32_FILES) $(UNIX_FILES) $(UNIX_SPECIFIC_FILES)
-
diff --git a/common/devices/bluetooth.c b/common/devices/bluetooth.c
deleted file mode 100644
index dccf448b..00000000
--- a/common/devices/bluetooth.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-
-  G N O K I I
-
-  A Linux/Unix toolset and driver for the mobile phones.
-
-  This file is part of gnokii.
-
-  Copyright (C) 2002       Marcel Holtmann <[hidden email]>
-  Copyright (C) 2003       BORBELY Zoltan
-  Copyright (C) 2004       Pawel Kot, Phil Ashby
-
-  Fake definitions for the bluetooth handling functions.
-
-*/
-
-#include "config.h"
-#include "compat.h"
-#include "misc.h"
-#include "gnokii.h"
-#include "devices/unixbluetooth.h"
-
-#ifndef HAVE_BLUETOOTH
-
-int bluetooth_open(const char *addr, uint8_t channel, struct gn_statemachine *state) { return -1; }
-int bluetooth_close(int fd, struct gn_statemachine *state) { return -1; }
-int bluetooth_write(int fd, const __ptr_t bytes, int size, struct gn_statemachine *state) { return -1; }
-int bluetooth_read(int fd, __ptr_t bytes, int size, struct gn_statemachine *state) { return -1; }
-int bluetooth_select(int fd, struct timeval *timeout, struct gn_statemachine *state) { return -1; }
-
-#endif /* HAVE_BLUETOOTH */
diff --git a/common/devices/dku2libusb.c b/common/devices/dku2libusb.c
index 0a6eb8a1..87b2df18 100644
--- a/common/devices/dku2libusb.c
+++ b/common/devices/dku2libusb.c
@@ -29,34 +29,6 @@
 #  define ENODATA 61
 #endif
 
-#ifndef HAVE_LIBUSB
-int fbusdku2usb_open(struct gn_statemachine *state)
-{
- return -1;
-}
-
-int fbusdku2usb_close(struct gn_statemachine *state)
-{
- return -1;
-}
-
-int fbusdku2usb_write(const __ptr_t bytes, int size, struct gn_statemachine *state)
-{
- return -1;
-}
-
-int fbusdku2usb_read(__ptr_t bytes, int size, struct gn_statemachine *state)
-{
- return -1;
-}
-
-int fbusdku2usb_select(struct timeval *timeout, struct gn_statemachine *state)
-{
- return -1;
-}
-
-#else
-
 #include <usb.h>
 
 /* Information about a USB DKU2 FBUS interface present on the system */
@@ -540,5 +512,3 @@ int fbusdku2usb_select(struct timeval *timeout, struct gn_statemachine *state)
 {
  return 1;
 }
-
-#endif
diff --git a/common/devices/irda.c b/common/devices/irda.c
deleted file mode 100644
index 2674c2db..00000000
--- a/common/devices/irda.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- *
- * G N O K I I
- *
- * A Linux/Unix toolset and driver for the mobile phones.
- *
- * Copyright (C) 1999-2000  Hugh Blemings & Pavel Janík ml.
- * Copyright (C) 2000-2001  Marcel Holtmann <[hidden email]>
- * Copyright (C) 2004       Phil Ashby
- *
- * Fake definitions for irda handling functions.
- */
-
-#include "config.h"
-#include "compat.h"
-#include "misc.h"
-#include "gnokii.h"
-
-#ifndef HAVE_IRDA
-
-int irda_open(struct gn_statemachine *state) { return -1; }
-int irda_close(int fd, struct gn_statemachine *state) { return -1; }
-int irda_write(int fd, const __ptr_t bytes, int size, struct gn_statemachine *state) { return -1; }
-int irda_read(int fd, __ptr_t bytes, int size, struct gn_statemachine *state) { return -1; }
-int irda_select(int fd, struct timeval *timeout, struct gn_statemachine *state) { return -1; }
-
-#endif /* HAVE_IRDA */
diff --git a/common/devices/osxbluetooth.m b/common/devices/osxbluetooth.m
index 6216cc5c..1fc11295 100644
--- a/common/devices/osxbluetooth.m
+++ b/common/devices/osxbluetooth.m
@@ -10,14 +10,10 @@
 
 */
 
-#include "config.h"
-
-#ifdef HAVE_BLUETOOTH_MACOSX
-
 #include <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>
 #include <IOBluetooth/objc/IOBluetoothDevice.h>
 
-#include "devices/unixbluetooth.h"
+#include "devices/bluetooth.h"
 
 static NSMutableDictionary *queues;
 static int next_fd = 1;
@@ -179,5 +175,3 @@ int bluetooth_close(int fd, struct gn_statemachine *state)
     [queues removeObjectForKey:@(fd)];
     return 1;
 }
-
-#endif
diff --git a/common/devices/socketphonet.c b/common/devices/socketphonet.c
index 12bed8b2..1e119939 100644
--- a/common/devices/socketphonet.c
+++ b/common/devices/socketphonet.c
@@ -15,49 +15,17 @@
 
 */
 
-#include "config.h"
-#include "compat.h" /* for __ptr_t definition */
-#include "gnokii.h"
-
-#ifndef HAVE_SOCKETPHONET
-
-int socketphonet_close(struct gn_statemachine *state)
-{
- return -1;
-}
-
-int socketphonet_open(const char *iface, int with_async, struct gn_statemachine *state)
-{
- return -1;
-}
-
-size_t socketphonet_read(int fd, __ptr_t buf, size_t nbytes, struct gn_statemachine *state)
-{
- return -1;
-}
-
-size_t socketphonet_write(int fd, const __ptr_t buf, size_t n, struct gn_statemachine *state)
-{
- return -1;
-}
-
-int socketphonet_select(int fd, struct timeval *timeout, struct gn_statemachine *state)
-{
- return -1;
-}
-
-#else
-
 /* System header files */
 #include <sys/socket.h>
 #include <linux/phonet.h>
 
 /* Various header files */
+#include "config.h"
 #include "compat.h"
 #include "links/fbus-common.h"
 #include "links/fbus-phonet.h"
-#include "device.h"
 #include "devices/serial.h"
+#include "devices/socketphonet.h"
 #include "gnokii-internal.h"
 
 static struct sockaddr_pn addr = { .spn_family = AF_PHONET, .spn_dev = FBUS_DEVICE_PHONE };
@@ -159,5 +127,3 @@ int socketphonet_select(int fd, struct timeval *timeout, struct gn_statemachine
 {
  return serial_select(fd, timeout, state);
 }
-
-#endif /* HAVE_SOCKETPHONET */
diff --git a/common/devices/tcp.c b/common/devices/tcp.c
index e2bcde46..3afb4575 100644
--- a/common/devices/tcp.c
+++ b/common/devices/tcp.c
@@ -18,8 +18,6 @@
 #include "devices/tcp.h"
 #include "devices/serial.h"
 
-#ifndef WIN32
-
 #ifdef HAVE_SYS_IOCTL_H
 #  include <sys/ioctl.h>
 #endif
@@ -142,7 +140,6 @@ int tcp_opendevice(const char *file, int with_async, struct gn_statemachine *sta
  int retcode;
 
  /* Open device */
-
  fd = tcp_open(file);
 
  if (fd < 0)
@@ -197,32 +194,3 @@ size_t tcp_write(int fd, const __ptr_t buf, size_t n, struct gn_statemachine *st
 {
  return write(fd, buf, n);
 }
-
-#else /* WIN32 */
-
-int tcp_close(int fd, struct gn_statemachine *state)
-{
- return -1;
-}
-
-int tcp_opendevice(const char *file, int with_async, struct gn_statemachine *state)
-{
- return -1;
-}
-
-size_t tcp_read(int fd, __ptr_t buf, size_t nbytes, struct gn_statemachine *state)
-{
- return -1;
-}
-
-size_t tcp_write(int fd, const __ptr_t buf, size_t n, struct gn_statemachine *state)
-{
- return -1;
-}
-
-int tcp_select(int fd, struct timeval *timeout, struct gn_statemachine *state)
-{
- return -1;
-}
-
-#endif /* WIN32 */
diff --git a/common/devices/unixbluetooth.c b/common/devices/unixbluetooth.c
index 1ceb1228..e13c2e0b 100644
--- a/common/devices/unixbluetooth.c
+++ b/common/devices/unixbluetooth.c
@@ -16,13 +16,10 @@
 
 */
 
-#include "config.h"
 #include "compat.h"
 #include "misc.h"
 #include "gnokii.h"
-#include "devices/unixbluetooth.h"
-
-#if defined(HAVE_BLUETOOTH_BLUEZ) || defined(HAVE_BLUETOOTH_NETGRAPH) || defined(HAVE_BLUETOOTH_NETBT)
+#include "devices/bluetooth.h"
 
 #ifdef HAVE_BLUETOOTH_NETGRAPH /* FreeBSD / netgraph */
 
@@ -257,7 +254,7 @@ static int find_service_channel(bdaddr_t *adapter, bdaddr_t *device, int only_gn
  case SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET:
  if (channel == -1)
  break;
-
+
  SDP_GET8(type, start);
  switch (type) {
  case SDP_DATA_STR8:
@@ -295,7 +292,7 @@ static int find_service_channel(bdaddr_t *adapter, bdaddr_t *device, int only_gn
  break;
  }
  }
-
+
  if (strstr(name, "Nokia PC Suite") != NULL) {
  channel = -1;
  break;
@@ -501,7 +498,7 @@ int bluetooth_open(const char *addr, uint8_t channel, struct gn_statemachine *st
 
  dprintf("Using channel: %d\n", channel);
  raddr.rc_channel = channel;
-
+
  if (connect(fd, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) {
  perror(_("Can't connect"));
  close(fd);
@@ -541,5 +538,3 @@ int bluetooth_select(int fd, struct timeval *timeout, struct gn_statemachine *st
 
  return select(fd + 1, &readfds, NULL, NULL, timeout);
 }
-
-#endif /* HAVE_BLUETOOTH_BLUEZ || HAVE_BLUETOOTH_NETGRAPH || HAVE_BLUETOOTH_NETBT */
diff --git a/common/devices/unixirda.c b/common/devices/unixirda.c
index 1271041a..b2a9eac0 100644
--- a/common/devices/unixirda.c
+++ b/common/devices/unixirda.c
@@ -13,18 +13,14 @@
  *
  */
 
-#include "config.h"
 #include "compat.h"
 #include "misc.h"
 #include "gnokii.h"
-
-#ifdef HAVE_IRDA
+#include "devices/irda.h"
 
 #include <linux/types.h>
 #include <linux/irda.h>
 
-#include "devices/irda.h"
-
 #ifndef AF_IRDA
 #  define AF_IRDA 23
 #endif
@@ -171,5 +167,3 @@ int irda_select(int fd, struct timeval *timeout, struct gn_statemachine *state)
 
  return select(fd + 1, &readfds, NULL, NULL, timeout);
 }
-
-#endif /* HAVE_IRDA */
diff --git a/common/devices/winbluetooth.c b/common/devices/winbluetooth.c
index a898e2e6..7be40127 100644
--- a/common/devices/winbluetooth.c
+++ b/common/devices/winbluetooth.c
@@ -8,18 +8,14 @@
  *
  */
 
-#include "config.h"
-
-#ifdef HAVE_BLUETOOTH
-
 #include <winsock2.h>
 #include <mmsystem.h>
 #include <ws2bth.h>
 #include <bluetoothapis.h>
 
+#include "config.h"
 #include "compat.h"
-#include "gnokii.h"
-#include "misc.h"
+#include "devices/bluetooth.h"
 
 /* QTTY by Davide Libenzi ( Terminal interface to Symbian QConsole )
  * Copyright (C) 2004  Davide Libenzi
@@ -109,5 +105,3 @@ int bluetooth_select(int fd, struct timeval *timeout, struct gn_statemachine *st
 
  return select(0 /* ignored on Win32 */, &readfds, NULL, NULL, timeout);
 }
-
-#endif /* HAVE_BLUETOOTH */
diff --git a/common/devices/winirda.c b/common/devices/winirda.c
index 4bfed742..71018842 100644
--- a/common/devices/winirda.c
+++ b/common/devices/winirda.c
@@ -8,14 +8,11 @@
  *
  */
 
-#include "config.h"
-
-#ifdef HAVE_IRDA
-
 #define WIN32_LEAN_AND_MEAN
 #include <winsock.h>
 #include <mmsystem.h>
 
+#include "config.h"
 #include "compat.h"
 #include "misc.h"
 #include "devices/irda.h"
@@ -160,5 +157,3 @@ int irda_select(int fd, struct timeval *timeout, struct gn_statemachine *state)
 
  return select(0 /* ignored on Win32 */, &readfds, NULL, NULL, timeout);
 }
-
-#endif /* HAVE_IRDA */
diff --git a/configure.ac b/configure.ac
index 512a620d..e5e2c5ad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -458,39 +458,25 @@ if test "$enable_libusb" = "yes"; then
  ]
  )
 fi
+AM_CONDITIONAL([LIBUSB], [test $USE_LIBUSB = yes])
 
-dnl ======================== Checks for Linux Phonet support
+dnl ======================== Phonet switch
 USE_SOCKETPHONET="no"
 AC_ARG_ENABLE(phonet,
               AC_HELP_STRING([--disable-phonet],
                              [disable phonet support (default is autodetected)]
                             ),,
               [enable_phonet=yes])
-if test "$enable_phonet" = "yes"; then
- AC_CHECK_HEADER(linux/phonet.h,
- [AC_DEFINE(HAVE_SOCKETPHONET, 1, [Whether Phonet is available])
- USE_SOCKETPHONET="yes"],,
- [#include <sys/socket.h>
- #include <linux/phonet.h>])
-fi
 
-dnl ======================== Checks for Linux IrDA support
+dnl ======================== IrDA switch
 USE_IRDA="no"
 AC_ARG_ENABLE(irda,
               AC_HELP_STRING([--disable-irda],
                              [disable irda support (default is autodetected)]
                             ),,
               [enable_irda=yes])
-if test "$enable_irda" = "yes"; then
- AC_CHECK_HEADER(linux/irda.h,
- [AC_DEFINE(HAVE_IRDA, 1, [Whether IrDA is available])
- USE_IRDA="yes"],,
- [#include <sys/socket.h>
- #include <sys/ioctl.h>
- #include <linux/types.h>])
-fi
 
-dnl ======================== Checks for Bluetooth support
+dnl ======================== Bluetooth switch
 USE_BLUETOOTH="no"
 AC_ARG_WITH(bluetooth,
  [  --with-bluetooth=DIR    specifies the base libbluetooth],
@@ -524,10 +510,26 @@ linux*)
  AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
  AC_DEFINE(HAVE_BLUETOOTH_BLUEZ,[],[Compile on Linux])
  USE_BLUETOOTH="yes"
+ UNIX_BLUETOOTH="true"
  BLUETOOTH_LIBS="-lbluetooth"
  AC_SUBST(BLUETOOTH_LIBS)
  fi
  fi
+ if test "$enable_irda" = "yes"; then
+ AC_CHECK_HEADER(linux/irda.h,
+ [AC_DEFINE(HAVE_IRDA, 1, [Whether IrDA is available])
+ [USE_IRDA="yes" UNIX_IRDA="true"]],,
+ [#include <sys/socket.h>
+ #include <sys/ioctl.h>
+ #include <linux/types.h>])
+ fi
+ if test "$enable_phonet" = "yes"; then
+ AC_CHECK_HEADER(linux/phonet.h,
+ [AC_DEFINE(HAVE_SOCKETPHONET, 1, [Whether Phonet is available])
+ USE_SOCKETPHONET="yes"],,
+ [#include <sys/socket.h>
+ #include <linux/phonet.h>])
+ fi
  ;;
 dnl ======================== Checks for MacOSX Bluetooth support
 darwin*)
@@ -551,6 +553,7 @@ darwin*)
  AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
  AC_DEFINE(HAVE_BLUETOOTH_MACOSX,[],[Compile on Darwin / Mac OSX])
  USE_BLUETOOTH="yes"
+ OSX_BLUETOOTH="true"
  BLUETOOTH_LIBS="$PTHREAD_LIBS -Wl,-framework,CoreFoundation -Wl,-framework,IOBluetooth -Wl,-framework,Foundation"
  AC_SUBST(BLUETOOTH_LIBS)
  fi
@@ -572,6 +575,7 @@ freebsd)
  AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
  AC_DEFINE(HAVE_BLUETOOTH_NETGRAPH, [], [Compile on FreeBSD])
  USE_BLUETOOTH="yes"
+ UNIX_BLUETOOTH="true"
  AC_CHECK_LIB(bluetooth, bt_aton,
  [BLUETOOTH_LIBS="-lbluetooth" ac_cv_have_bt_lib=yes],
  ac_cv_have_bt_lib=no)
@@ -598,6 +602,7 @@ netbsd*)
  AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
  AC_DEFINE(HAVE_BLUETOOTH_NETBT, [], [Compile on NetBSD])
  USE_BLUETOOTH="yes"
+ UNIX_BLUETOOTH="true"
  CFLAGS="$CFLAGS -DCOMPAT_BLUEZ"
  AC_CHECK_LIB(bluetooth, bt_aton,
  [BLUETOOTH_LIBS="-lbluetooth" ac_cv_have_bt_lib=yes],
@@ -611,19 +616,37 @@ netbsd*)
  fi
  ;;
 
+dnl ======================== Checks for Windows devices
 cygwin32|cygwin|mingw32|mingw32msvc)
- AC_CHECK_HEADER(af_irda.h, [AC_DEFINE(HAVE_IRDA, 1, [Whether IrDA is available]) USE_IRDA="yes" LIBS="$LIBS -lwinmm"],, [#include <windows.h>])
- AC_CHECK_HEADER(ws2bth.h, [AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available]) USE_BLUETOOTH="yes"],, [#include <windows.h>])
+ if test "$enable_bluetooth" = "yes"; then
+ AC_CHECK_HEADER(ws2bth.h,
+ [AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available]) USE_BLUETOOTH="yes" WIN32_BLUETOOTH="true"],,
+ [#include <windows.h>])
+ fi
+ if test "$enable_irda" = "yes"; then
+ AC_CHECK_HEADER(af_irda.h,
+ [AC_DEFINE(HAVE_IRDA, 1, [Whether IrDA is available]) USE_IRDA="yes" WIN32_IRDA="true"],,
+ [#include <windows.h>])
+ fi
+ BLUETOOTH_LIBS=""
  if test x"$USE_IRDA" = "xyes" -o x"$USE_BLUETOOTH" = "xyes"; then
- LIBS="$LIBS -lws2_32"
+ BLUETOOTH_LIBS="-lws2_32"
  fi
+ if test x"$USE_IRDA" = "xyes"; then
+ BLUETOOTH_LIBS="$BLUETOOTH_LIBS -lwinmm"
+ fi
+ AC_SUBST(BLUETOOTH_LIBS)
  WIN32=1
  ;;
-
 esac
 
 AM_CONDITIONAL([WIN32], [test "x$WIN32" = "x1"])
-AM_CONDITIONAL([FOR_MAC], [test "x$FOR_MAC" = "x1"])
+AM_CONDITIONAL([SOCKETPHONET], [test "x$USE_SOCKETPHONET" = "xyes"])
+AM_CONDITIONAL([OSXBLUETOOTH], [test "x$OSX_BLUETOOTH" = "xtrue"])
+AM_CONDITIONAL([UNIXBLUETOOTH], [test "x$UNIX_BLUETOOTH" = "xtrue"])
+AM_CONDITIONAL([UNIXIRDA], [test "x$UNIX_IRDA" = "xtrue"])
+AM_CONDITIONAL([WINBLUETOOTH], [test "x$WIN32_BLUETOOTH" = "xtrue"])
+AM_CONDITIONAL([WINIRDA], [test "x$WIN32_IRDA" = "xtrue"])
 
 dnl ======================== Checks for X base support
 
diff --git a/include/devices/unixbluetooth.h b/include/devices/bluetooth.h
similarity index 86%
rename from include/devices/unixbluetooth.h
rename to include/devices/bluetooth.h
index db4171e9..a531cc03 100644
--- a/include/devices/unixbluetooth.h
+++ b/include/devices/bluetooth.h
@@ -11,8 +11,8 @@
 
 */
 
-#ifndef _gnokii_unix_bluetooth_h
-#define _gnokii_unix_bluetooth_h
+#ifndef _gnokii_bluetooth_h
+#define _gnokii_bluetooth_h
 
 #include "gnokii.h"
 
@@ -22,4 +22,4 @@ int bluetooth_write(int fd, const __ptr_t bytes, int size, struct gn_statemachin
 int bluetooth_read(int fd, __ptr_t bytes, int size, struct gn_statemachine *state);
 int bluetooth_select(int fd, struct timeval *timeout, struct gn_statemachine *state);
 
-#endif /* _gnokii_unix_bluetooth_h */
+#endif /* _gnokii_bluetooth_h */
diff --git a/include/devices/unixirda.h b/include/devices/unixirda.h
deleted file mode 100644
index 19b07ef4..00000000
--- a/include/devices/unixirda.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- *
- * G N O K I I
- *
- * A Linux/Unix toolset and driver for the mobile phones.
- *
- * Copyright (C) 1999, 2000 Hugh Blemings & Pavel Janík ml.
- * Copyright (C) 2000-2001  Marcel Holtmann <[hidden email]>
- *
- */
-
-#ifndef __unix_irda_h_
-#define __unix_irda_h_
-
-#endif
diff --git a/include/gnokii/data.h b/include/gnokii/data.h
index 9822c0b0..84f1624b 100644
--- a/include/gnokii/data.h
+++ b/include/gnokii/data.h
@@ -191,9 +191,22 @@ typedef struct {
  gn_auth_interactive_func_t auth_interactive;
 } gn_callback;
 
+typedef struct {
+ int (*open)(const char *file, int with_odd_parity, int with_async,
+    int with_hw_handshake, struct gn_statemachine *state);
+ void (*close)(int fd, struct gn_statemachine *state);
+ int (*select)(int fd, struct timeval *timeout, struct gn_statemachine *state);
+ size_t (*read)(int fd, __ptr_t buf, size_t nbytes, struct gn_statemachine *state);
+ size_t (*write)(int fd, const __ptr_t buf, size_t n, struct gn_statemachine *state);
+ gn_error (*nreceived)(int fd, int *n, struct gn_statemachine *state);
+ gn_error (*flush)(int fd, struct gn_statemachine *state);
+ gn_error (*changespeed)(int fd, int speed, struct gn_statemachine *state);
+ void (*setdtrrts)(int fd, int dtr, int rts, struct gn_statemachine *state);
+} gn_device_ops;
+
 typedef struct {
  int fd;
- gn_connection_type type;
+ const gn_device_ops *ops;
  void *device_instance;
 } gn_device;
 
--
2.25.0


_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 0/9] Refactor devices build

Pawel Kot
In reply to this post by Ladislav Michl
Hi Ladis,

On Sat, Jan 25, 2020 at 10:42 AM Ladislav Michl <[hidden email]> wrote:
> this is next version of "Refactor devices build" patch broken into
> pieces. It is compile tested on Linux only (with exception of unixirda
> as IrDA support was removed from kernel with commit d64c2a76123f
> "staging: irda: remove the irda network stack and drivers" and even
> https://www.irda.org/ site turned into some obscure EMF Blockers
> selling stuff).

Thanks. I will be looking into these over a couple of next days. Meanwhile I've pushed some changes required to (almost) compile successfully under Microsoft Visual Studio. Seems it doesn't break thinks under Linux and OS X.

Cheers,
--
Pawel Kot

_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 0/9] Refactor devices build

Ladislav Michl
On Sun, Jan 26, 2020 at 11:59:47PM +0100, Pawel Kot wrote:

> Hi Ladis,
>
> On Sat, Jan 25, 2020 at 10:42 AM Ladislav Michl <[hidden email]>
> wrote:
> > this is next version of "Refactor devices build" patch broken into
> > pieces. It is compile tested on Linux only (with exception of unixirda
> > as IrDA support was removed from kernel with commit d64c2a76123f
> > "staging: irda: remove the irda network stack and drivers" and even
> > https://www.irda.org/ site turned into some obscure EMF Blockers
> > selling stuff).
>
> Thanks. I will be looking into these over a couple of next days. Meanwhile
> I've pushed some changes required to (almost) compile successfully under
> Microsoft Visual Studio. Seems it doesn't break thinks under Linux and OS X.

Ah, so "Use posix_spawn to run external scripts" is in now... :) This serie
contains 1/9 as its replacement, so it will conflict. As it should be trivial
to solve I will not resend and wait for more comments.

Thanks,
        ladis

_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 0/9] Refactor devices build

Ladislav Michl
In reply to this post by Pawel Kot
Hi Pawel,

On Sun, Jan 26, 2020 at 11:59:47PM +0100, Pawel Kot wrote:
> Thanks. I will be looking into these over a couple of next days. Meanwhile
> I've pushed some changes required to (almost) compile successfully under
> Microsoft Visual Studio. Seems it doesn't break thinks under Linux and OS X.

Now looking at you changes... The snippet
#ifndef ssize_t
#  include <basetsd.h>
#  define ssize_t SSIZE_T
#endif
in snprintf.c does not look nice to me. I would:
1) put it into compat.h, to keep changes to upstream snprintf.c minimal.
2) use #if defined(_MSC_VER) to guard it (or combine with HAVE_SSIZE_T?)
3) or something like this:
--- a/include/compat.h
+++ b/include/compat.h
@@ -20,6 +20,8 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#elif defined(_MSC_VER)
+#  include "msvc-config.h"
 #else
 #  error "compat.h requires config.h"
 #endif
and solve Microsoft Visual Studio in it's own config. It could be even
versioned. Also sorry for not finding time to look at win32 stuff yet.

        ladis

_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 0/9] Refactor devices build

Pawel Kot
Hi,

On Mon, 27 Jan 2020 at 23:41, Ladislav Michl <[hidden email]> wrote:
Hi Pawel,

On Sun, Jan 26, 2020 at 11:59:47PM +0100, Pawel Kot wrote:
> Thanks. I will be looking into these over a couple of next days. Meanwhile
> I've pushed some changes required to (almost) compile successfully under
> Microsoft Visual Studio. Seems it doesn't break thinks under Linux and OS X.

Now looking at you changes... The snippet

Thanks for looking into it :)

#ifndef ssize_t
#  include <basetsd.h>
#  define ssize_t SSIZE_T
#endif
in snprintf.c does not look nice to me. I would:

Does not look nice to me either. Was actually pushing it to find some better ideas.

1) put it into compat.h, to keep changes to upstream snprintf.c minimal.

I would not do this. I’d like to keep common.h to include common things. I.e. frequently used. To be honest I think we have excessive stuff there.

2) use #if defined(_MSC_VER) to guard it (or combine with HAVE_SSIZE_T?)

That sounds much better.

3) or something like this:
--- a/include/compat.h
+++ b/include/compat.h
@@ -20,6 +20,8 @@

 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#elif defined(_MSC_VER)
+#  include "msvc-config.h"
 #else
 #  error "compat.h requires config.h"
 #endif
and solve Microsoft Visual Studio in it's own config. It could be even

Not sure about combining it with compat.h. I think separate header included where needed would work. Let me look at all things that would go there.

versioned. Also sorry for not finding time to look at win32 stuff yet.

Obviously - no worries here ;)

Cheers
Paweł 
--
Pawel Kot

_______________________________________________
gnokii-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/gnokii-users