OSDN Git Service

Add get_dvd function
authorwifiextender <router@archlinux.info>
Tue, 23 Aug 2016 13:21:52 +0000 (15:21 +0200)
committerwifiextender <router@archlinux.info>
Tue, 23 Aug 2016 13:21:52 +0000 (15:21 +0200)
README.md
bootstrap
m4/dvd.m4 [new file with mode: 0644]
src/common.c
src/include/functions_constants.h
src/linux_functions.c
src/options.c
src/prototypes/common.h

index b1fbaf3..8bb1d84 100644 (file)
--- a/README.md
+++ b/README.md
@@ -57,6 +57,8 @@ The order of supplied options will dictate how, where and what system informatio
 | -O           | --driveavail| The available drive storage                                        |
 | -g           | --battery   | The remaining battery charge                                       |
 | -F           | --drivemodel| The vendor name of your drive [argument - sda]                     |
+| -z           | --dvdstr    | The vendor and model name of your cdrom/dvdrom                     |
+| -S           | --statio    | Read and written MBs to the drive so far [argument - sda]          |
 | -p           | --packages  | The number of installed packages                                   |
 | -P           | --kernsys   | The kernel name                                                    |
 | -q           | --kernode   | The network node hostname                                          |
@@ -84,7 +86,6 @@ The order of supplied options will dictate how, where and what system informatio
 | -h           | --nicdrv    | The NIC driver [argument - eth0]                                   |
 | -H           | --nicver    | The NIC version [argument - eth0]                                  |
 | -j           | --nicfw     | The NIC firmware [argument - eth0]                                 |
-| -S           | --statio    | Read and written MBs to the drive so far [argument - sda]          |
 
 The following options are available only in Linux: `-FhHGe`.
 
@@ -110,6 +111,7 @@ It's up to you to decide which features suit you best.
 | --with-oss     | --without-oss       | To get the sound volume level in FreeBSD.                                                  |
 | --with-net     | --without-net       | Enable the internet related options.                                                       |
 | --with-pci     | --without-pci       | To get the NIC vendor and model                                                            |
+| --with-dvd     | --without-dvd       | To get the cdrom/dvdrom vendor and model                                                   |
 | --with-colours | --without-colours   | Colorize the output data.                                                                  |
 | icons=/tmp     |                     | Use xbm icons that can be used by dzen2 for example. Discarded when **--with-x11** is used |
 | --with-mpd     | --without-mpd       | To see the currently played song name (if any).                                            |
@@ -118,7 +120,7 @@ It's up to you to decide which features suit you best.
 By default, if **no** options are passed, the program will be compiled with/without:
 
 ```bash
---without-alsa --without-x11 --without-mpd --with-colours --with-net --with-pci
+--without-alsa --without-x11 --without-mpd --with-colours --with-net --with-pci --without-dvd
 ```
 
 ---
@@ -260,7 +262,14 @@ To get the sound volume level:
 * alsa-utils
 * alsa-lib
 
-Then pass **--with-alsa** to configure. FreeBSD users can use the baked OSS instead, pass **--without-alsa --with-oss** instead.
+Then pass **--with-alsa** to configure. FreeBSD users can use the baked OSS instead, pass **--without-alsa --with-oss** to configure instead.
+
+To get the vendor and model name of your cdrom/dvdrom/blu-ray:
+
+* libcdio
+* libcddb
+
+In linux **--without-dvd** will still compile the program with dvd support. Except it will be limited only to dvd support, it will try to parse the sr0 vendor and model name detected by the kernel.
 
 To see the currently played song name:
 
index ba8da6b..148f784 100644 (file)
--- a/bootstrap
+++ b/bootstrap
@@ -102,6 +102,7 @@ _gen_files() {
   TEST_X11
   TEST_ALSA
   TEST_MPD
+  TEST_DVD
   TEST_TYPEZ
   TEST_CFLAGZ
 
@@ -159,7 +160,7 @@ _gen_files() {
 
     bin_PROGRAMS = '${progName}'
 
-    '${progName}'_LDADD = $(X_LIBS) $(ALSA_LIBS) $(MPD_LIBS) $(PCI_LIBS) '${bsdLibs}'
+    '${progName}'_LDADD = $(X_LIBS) $(ALSA_LIBS) $(MPD_LIBS) $(PCI_LIBS) $(DVD_LIBS) '${bsdLibs}'
 
     '${progName}'_SOURCES = '${src_files[@]}'
 
diff --git a/m4/dvd.m4 b/m4/dvd.m4
new file mode 100644 (file)
index 0000000..c20c5a7
--- /dev/null
+++ b/m4/dvd.m4
@@ -0,0 +1,92 @@
+dnl Copyright 08/23/2016
+dnl Aaron Caffrey https://github.com/wifiextender
+
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+dnl MA 02110-1301, USA.
+
+
+dnl TEST_DVD() function in configure.ac
+dnl
+dnl Substitute the linker flags -lcdio to the
+dnl the variable 'DVD_LIBS' if the user enabled
+dnl the --with-dvd switch
+AC_DEFUN([TEST_DVD],[
+  DVD_LIBS=""
+
+  AC_ARG_WITH([dvd],
+    AS_HELP_STRING([--with-dvd],
+      [dvd linker flag to show the vendor and model name of your cd/dvdrom]),
+    [],
+    [with_dvd=no]
+  )
+
+  AS_IF([test "x$with_dvd" = "xyes"], [
+    AC_CHECK_HEADERS([cdio/cdio.h], [
+      DVD_LIBS="-lcdio"
+      ],[
+        ERR_MUST_INSTALL([libcdio])
+      ])
+
+    AC_CHECK_HEADERS([ \
+      cdio/cdio.h      \
+      cdio/mmc.h       \
+    ], [
+      DVD_LIBS="-lcdio"
+      ],[
+        ERR_MUST_INSTALL([libcdio])
+      ])
+
+    m4_foreach([LiB], [
+        cdio_open        ,
+        mmc_get_hwinfo   ,
+        cdio_destroy
+      ],[
+        AC_CHECK_LIB(cdio,LiB,[],[
+          ERR([Missing core cdio function.])
+        ])
+    ])
+  ])
+
+  AC_SUBST(DVD_LIBS)
+
+  AS_IF([test "x$with_dvd" = "xyes"], [
+    AC_LINK_IFELSE([
+      AC_LANG_SOURCE([[
+        #include <stdio.h>
+        #include <stdlib.h>
+        #include <cdio/cdio.h>
+        #include <cdio/mmc.h>
+        int main(void) {
+          CdIo_t *p_cdio = cdio_open(NULL, DRIVER_DEVICE);
+          cdio_hwinfo_t hwinfo;
+          if (NULL == p_cdio) {
+            return 0;
+          }
+          if (mmc_get_hwinfo(p_cdio, &hwinfo)) {
+            printf("%s %s\n", hwinfo.psz_vendor, hwinfo.psz_model);
+          }
+          if (NULL != p_cdio) {
+            cdio_destroy(p_cdio);
+          }
+          return 0;
+        }
+      ]])
+    ],[],[
+        LINK_FAILED([cdio])
+      ]
+    )
+  ])
+
+])
index 2c4d073..c1c9244 100644 (file)
 #include "include/freebzd.h"
 #endif /* __FreeBSD__ */
 
+#if defined(HAVE_CDIO_CDIO_H)
+#include <cdio/cdio.h>
+#include <cdio/mmc.h>
+#endif /* HAVE_CDIO_CDIO_H */
+
+
 #if defined(__linux__)
 static uint_fast16_t glob_packages(const char *);
 #endif /* __linux__ */
@@ -362,3 +368,67 @@ get_fans(char *str1) {
     FILL_STR_ARR(1, str1, (y != x ? buffer : NOT_FOUND));
   }
 }
+
+
+#if defined(HAVE_CDIO_CDIO_H)
+/*
+  CdIo_t *p_cdio = NULL;
+  cdio_hwinfo_t hwinfo;
+  driver_id_t driver_id = DRIVER_DEVICE;
+  char **device_list = cdio_get_devices_ret(&driver_id);
+  char **d = device_list;
+
+  if (NULL != d) {
+    for (; NULL != *d; d++) {
+      p_cdio = cdio_open(NULL, driver_id);
+      if (mmc_get_hwinfo(p_cdio, &hwinfo)) {
+        printf("%s %s\n", hwinfo.psz_vendor, hwinfo.psz_model);
+      }
+      if (NULL != p_cdio) {
+        cdio_destroy(p_cdio);
+      }
+    }
+  }
+  if (NULL != device_list) {
+    cdio_free_device_list(device_list);
+  }
+*/
+void
+get_dvd(char *str1) {
+  CdIo_t *p_cdio = cdio_open(NULL, DRIVER_DEVICE);
+  cdio_hwinfo_t hwinfo;
+
+  FILL_STR_ARR(1, str1, "Null");
+  if (NULL == p_cdio) {
+    FUNC_FAILED("cdio_open()");
+  }
+  if (mmc_get_hwinfo(p_cdio, &hwinfo)) {
+    FILL_STR_ARR(2, str1, hwinfo.psz_vendor, hwinfo.psz_model);
+  }
+  if (NULL != p_cdio) {
+    cdio_destroy(p_cdio);
+  }
+}
+#else
+
+#if defined(__linux__)
+void
+get_dvd(char *str1) {
+  FILE *fp;
+  char vendor[100], model[100];
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-result"
+  OPEN_X(fp, DVD_VEND, "%s", vendor);
+#pragma GCC diagnostic pop
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-result"
+  OPEN_X(fp, DVD_MODEL, "%s", model);
+#pragma GCC diagnostic pop
+
+  FILL_STR_ARR(2, str1, vendor, model);
+}
+#endif /* __linux__ */
+
+#endif /* HAVE_CDIO_CDIO_H */
index 7e47a13..9b87f2c 100644 (file)
@@ -32,7 +32,7 @@
 #define USINT "%"PRIu8
 #define SCAN_UFINT "%"SCNuFAST16
 #define SCAN_ULINT "%"SCNuLEAST32
-#define SCAN_UINTX "%"PRIxMAX
+#define SCAN_UINTX "%"PRIxMAX /* hex */
 
 /* stay away from va_list */
 #define FILL_ARR(x, z, ...) (snprintf(x, VLA, z, __VA_ARGS__))
 #define NIC_VEND(x, z)  (NIC_NUM(x, z, "vendor"))
 #define NIC_MODEL(x, z) (NIC_NUM(x, z, "device"))
 
+/* The cdrom/dvdrom vendor and model */
+#define DVD_DIR(x) ("/sys/class/block/sr0/device/"x)
+#define DVD_VEND DVD_DIR("vendor")
+#define DVD_MODEL DVD_DIR("model")
+
 /* exit with error */
 #define CANNOT_OPEN "Could not open"
 #define ERR "Error:"
index 24f4dfb..84b4dd1 100644 (file)
@@ -136,7 +136,7 @@ get_voltage(char *str1) {
 void 
 get_mobo(char *str1) {
   FILE *fp;
-  char vendor[VLA], name[VLA];
+  char vendor[100], name[100];
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wunused-result"
index 45985b4..3b9dee1 100644 (file)
@@ -52,8 +52,10 @@ static const struct argp_option options[] = {
   { .name = "drivetotal",   .key = 'n',                .doc = "The total drive storage."                                 },
   { .name = "drivefree",    .key = 'N',                .doc = "The free drive storage."                                  },
   { .name = "driveavail",   .key = 'O',                .doc = "The available drive storage."                             },
+  { .name = "dvdstr",       .key = 'z',                .doc = "The vendor and model name of your cdrom/dvdrom."          },
   { .name = "battery",      .key = 'g',                .doc = "The remaining battery charge."                            },
   { .name = "drivemodel",   .key = 'F', .arg = "sda",  .doc = "The vendor name of your drive."                           },
+  { .name = "statio",       .key = 'S', .arg = "sda",  .doc = "Read and written MBs to the drive so far."                },
   { .name = "packages",     .key = 'p',                .doc = "The number of installed packages."                        },
   { .name = "kernsys",      .key = 'P',                .doc = "The kernel name."                                         },
   { .name = "kernode",      .key = 'q',                .doc = "The network node hostname."                               },
@@ -85,7 +87,6 @@ static const struct argp_option options[] = {
 #else
   { .name = "nicgw",        .key = 'j', .arg = "re0", .doc = "The NIC gateway address."                                  },
 #endif /* __linux__ */
-  { .name = "statio",       .key = 'S', .arg = "sda",  .doc = "Read and written MBs to the drive so far."                },
   { .doc = NULL }
 };
 struct arguments {
@@ -121,6 +122,10 @@ parse_opt(int key, char *arg, struct argp_state *state) {
 
     NEW_LABEL('T', char cpu_temp[VLA], cpu_temp, FMT_TEMP);
 
+#if defined(HAVE_CDIO_CDIO_H) || defined(__linux__)
+    NEW_LABEL('z', char dvd[VLA], dvd, FMT_KERN);
+#endif /* HAVE_CDIO_CDIO_H || __linux__ */
+
     NEW_RAM_LABEL('J', char ram_total[VLA], ram_total, 1, FMT_RAM2, RAM_STR);
 
     NEW_RAM_LABEL('K', char ram_free[VLA], ram_free, 2, FMT_RAM2, RAM_STR);
index 969a08d..ed791f5 100644 (file)
@@ -34,4 +34,8 @@ void get_fans(char *);
 void set_status(const char *);
 #endif
 
+#if defined(HAVE_CDIO_CDIO_H) || defined(__linux__)
+void get_dvd(char *);
+#endif /* HAVE_CDIO_CDIO_H || __linux__ */
+
 #endif /* COMMON_H_ */