Commit 735064d3 authored by spiiroin's avatar spiiroin

Merge branch 'jb36841_use_ssu_sysinfo' into 'master'

Use ssusysinfo instead of SSU D-Bus interface

See merge request !21
parents 43c89f3b 536e0e4f
...@@ -97,6 +97,7 @@ PKG_CHECK_MODULES([USB_MODED], [ ...@@ -97,6 +97,7 @@ PKG_CHECK_MODULES([USB_MODED], [
gio-2.0 gio-2.0
libudev libudev
libkmod libkmod
ssu-sysinfo
]) ])
AC_SUBST(USB_MODED_LIBS) AC_SUBST(USB_MODED_LIBS)
......
...@@ -15,6 +15,7 @@ BuildRequires: pkgconfig(udev) ...@@ -15,6 +15,7 @@ BuildRequires: pkgconfig(udev)
BuildRequires: pkgconfig(libkmod) BuildRequires: pkgconfig(libkmod)
BuildRequires: doxygen BuildRequires: doxygen
BuildRequires: pkgconfig(libsystemd-daemon) BuildRequires: pkgconfig(libsystemd-daemon)
BuildRequires: pkgconfig(ssu-sysinfo)
Requires: lsof Requires: lsof
Requires: usb-moded-configs Requires: usb-moded-configs
......
...@@ -21,129 +21,43 @@ ...@@ -21,129 +21,43 @@
*/ */
#include <glib.h> #include <glib.h>
#include <ssusysinfo.h>
#include <dbus/dbus.h>
#include "usb_moded-ssu.h" #include "usb_moded-ssu.h"
#include "usb_moded-log.h" #include "usb_moded-log.h"
#include "usb_moded-dbus-private.h"
/** SSU D-Bus service name */
#define SSU_DBUS_SERVICE "org.nemo.ssu"
/** Default SSU D-Bus object path */ /** Cached ssu-sysinfo handle */
#define SSU_DBUS_OBJECT "/org/nemo/ssu" static ssusysinfo_t *ssu_instance = 0;
/** SSU D-Bus interface */ /** Flag for ssu-sysinfo instance has been initialized */
#define SSU_DBUS_INTERFACE "org.nemo.ssu" static gboolean ssu_intialized = FALSE;
/** SSU displayName D-Bus method call */ /** Atexit callback for releasing cached ssu-sysinfo handle */
#define SSU_DBUS_GET_DISPLAY_NAME "displayName" static void ssu_free_handle(void)
/** SsuDisplayType enum adapted from ssu c++ headers */
typedef enum
{ {
/** Manufacturer, like ACME Corp. /* Make sure instance does not get created on exit path */
* Board mappings key "deviceManufacturer" */ ssu_intialized = TRUE;
SsuDeviceManufacturer = 0,
/** Marketed device name, like Pogoblaster 3000.
* Board mappings key "prettyModel" */
SsuDeviceModel = 1,
/** Type designation, like NCC-1701. /* Release existing instance */
* Beard mappings key "deviceDesignation" */ ssusysinfo_delete(ssu_instance),
SsuDeviceDesignation = 2, ssu_instance = 0;
} SsuDisplayType; }
/** Wrapper for making synchronous org.nemo.ssu.displayName() method calls /** Helper for obtaining ssu-sysinfo handle on demand
* *
* Caller must release non-null return value with g_free(). * @return ssu-sysinfo, or NULL in case of errors
*
* @param type_id display name type to query
*
* @return human readable string, or NULL in case of errors
*/ */
static gchar * static ssusysinfo_t *ssu_get_handle(void)
usb_moded_get_ssu_display_name(SsuDisplayType type_id)
{ {
gchar *res = 0; /* Attempt only once */
DBusConnection *con = 0; if( !ssu_intialized ) {
DBusMessage *req = 0; ssu_intialized = TRUE;
DBusMessage *rsp = 0; ssu_instance = ssusysinfo_create();
dbus_int32_t arg = type_id; atexit(ssu_free_handle);
const char *val = 0; }
DBusError err = DBUS_ERROR_INIT; return ssu_instance;
if( !(con = usb_moded_dbus_get_connection()) ) {
log_err("not connected to system bus");
goto EXIT;
}
req = dbus_message_new_method_call(SSU_DBUS_SERVICE,
SSU_DBUS_OBJECT,
SSU_DBUS_INTERFACE,
SSU_DBUS_GET_DISPLAY_NAME);
if( !req ) {
log_err("could not create method call message");
goto EXIT;
}
if( !dbus_message_append_args(req,
DBUS_TYPE_INT32, &arg,
DBUS_TYPE_INVALID) ) {
log_err("could not add method call parameters");
goto EXIT;
}
rsp = dbus_connection_send_with_reply_and_block(con, req, -1, &err);
if( !rsp ) {
/* Be less verbose with failures that are expected
* if ssu service is not installed on the device. */
if( !strcmp(err.name, DBUS_ERROR_SERVICE_UNKNOWN) ) {
log_debug("%s D-Bus service is not available",
SSU_DBUS_SERVICE);
}
else {
log_err("did not get reply: %s: %s",
err.name, err.message);
}
goto EXIT;
}
if( dbus_set_error_from_message(&err, rsp) ) {
log_err("got error reply: %s: %s", err.name, err.message);
goto EXIT;
}
if( !dbus_message_get_args(rsp, &err,
DBUS_TYPE_STRING, &val,
DBUS_TYPE_INVALID) ) {
log_err("could not parse reply: %s: %s",
err.name, err.message);
goto EXIT;
}
res = g_strdup(val);
EXIT:
dbus_error_free(&err);
if( rsp )
dbus_message_unref(rsp);
if( req )
dbus_message_unref(req);
if( con )
dbus_connection_unref(con);
log_debug("ssu displayName(%d) -> %s", type_id, res ?: "N/A");
return res;
} }
/** Query device manufacturer name from the SSU D-Bus service /** Read device manufacturer name from the SSU configuration
* *
* Caller must release non-null return value with g_free(). * Caller must release non-null return value with g_free().
* *
...@@ -152,10 +66,15 @@ EXIT: ...@@ -152,10 +66,15 @@ EXIT:
gchar * gchar *
ssu_get_manufacturer_name(void) ssu_get_manufacturer_name(void)
{ {
return usb_moded_get_ssu_display_name(SsuDeviceManufacturer); gchar *res = 0;
const char *val = ssusysinfo_device_manufacturer(ssu_get_handle());
if( val && strcmp(val, "UNKNOWN") )
res = g_strdup(val);
log_debug("%s() -> %s", __FUNCTION__, res ?: "N/A");
return res;
} }
/** Query device model name from the SSU D-Bus service /** Read device model name from the SSU configuration
* *
* Caller must release non-null return value with g_free(). * Caller must release non-null return value with g_free().
* *
...@@ -164,5 +83,10 @@ ssu_get_manufacturer_name(void) ...@@ -164,5 +83,10 @@ ssu_get_manufacturer_name(void)
gchar * gchar *
ssu_get_product_name(void) ssu_get_product_name(void)
{ {
return usb_moded_get_ssu_display_name(SsuDeviceModel); gchar *res = 0;
const char *val = ssusysinfo_device_pretty_name(ssu_get_handle());
if( val && strcmp(val, "UNKNOWN") )
res = g_strdup(val);
log_debug("%s() -> %s", __FUNCTION__, res ?: "N/A");
return res;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment