ACK: [PATCH 1/2] lib + tests: make --pm-method logind dependant on glib version (LP: #1364998)

Alex Hung alex.hung at canonical.com
Thu Sep 4 08:14:25 UTC 2014


On 09/03/2014 11:15 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
> 
> Only make logind related code compile in if we have glib version
> 2.26 or higher.  This addresses older releases that support the
> older glib version.
> 
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/acpi/s3/s3.c                 | 11 ++++++++++-
>  src/acpi/s3power/s3power.c       | 11 ++++++++++-
>  src/acpi/s4/s4.c                 | 11 ++++++++++-
>  src/lib/include/fwts_pm_method.h |  7 +++++++
>  src/lib/src/fwts_framework.c     | 12 ++++++++++--
>  src/lib/src/fwts_pm_method.c     |  2 ++
>  6 files changed, 49 insertions(+), 5 deletions(-)
> 
> diff --git a/src/acpi/s3/s3.c b/src/acpi/s3/s3.c
> index 411d243..7aa420d 100644
> --- a/src/acpi/s3/s3.c
> +++ b/src/acpi/s3/s3.c
> @@ -61,11 +61,14 @@ static int s3_init(fwts_framework *fw)
>  /* Detect the best available power method */
>  static void detect_pm_method(fwts_pm_method_vars *fwts_settings)
>  {
> +#if FWTS_ENABLE_LOGIND
>  	if (s3_hybrid ?
>  		fwts_logind_can_hybrid_suspend(fwts_settings) :
>  		fwts_logind_can_suspend(fwts_settings))
>  		fwts_settings->fw->pm_method = FWTS_PM_LOGIND;
> -	else if (s3_hybrid ?
> +	else
> +#endif
> +	if (s3_hybrid ?
>  		fwts_sysfs_can_hybrid_suspend(fwts_settings) :
>  		fwts_sysfs_can_suspend(fwts_settings))
>  		fwts_settings->fw->pm_method = FWTS_PM_SYSFS;
> @@ -73,6 +76,7 @@ static void detect_pm_method(fwts_pm_method_vars *fwts_settings)
>  		fwts_settings->fw->pm_method = FWTS_PM_PMUTILS;
>  }
>  
> +#if FWTS_ENABLE_LOGIND
>  static int wrap_logind_do_suspend(fwts_pm_method_vars *fwts_settings,
>  	const int percent,
>  	int *duration,
> @@ -89,6 +93,7 @@ static int wrap_logind_do_suspend(fwts_pm_method_vars *fwts_settings,
>  
>  	return *duration > 0 ? 0 : 1;
>  }
> +#endif
>  
>  static int wrap_sysfs_do_suspend(fwts_pm_method_vars *fwts_settings,
>  	const int percent,
> @@ -165,6 +170,7 @@ static int s3_do_suspend_resume(fwts_framework *fw,
>  	}
>  
>  	switch (fw->pm_method) {
> +#if FWTS_ENABLE_LOGIND
>  		case FWTS_PM_LOGIND:
>  			fwts_log_info(fw, "Using logind as the default power method.");
>  			if (fwts_logind_init_proxy(fwts_settings) != 0) {
> @@ -173,6 +179,7 @@ static int s3_do_suspend_resume(fwts_framework *fw,
>  			}
>  			do_suspend = &wrap_logind_do_suspend;
>  			break;
> +#endif
>  		case FWTS_PM_PMUTILS:
>  			fwts_log_info(fw, "Using pm-utils as the default power method.");
>  			do_suspend = &wrap_pmutils_do_suspend;
> @@ -413,10 +420,12 @@ static int s3_test_multiple(fwts_framework *fw)
>  	int awake_delay = s3_min_delay * 1000;
>  	int delta = (int)(s3_delay_delta * 1000.0);
>  
> +#if FWTS_ENABLE_LOGIND
>  #if !GLIB_CHECK_VERSION(2,35,0)
>  	/* This is for backward compatibility with old glib versions */
>  	g_type_init();
>  #endif
> +#endif
>  
>  	if (s3_multiple == 1)
>  		fwts_log_info(fw, "Defaulted to 1 test, use --s3-multiple=N to run more S3 cycles\n");
> diff --git a/src/acpi/s3power/s3power.c b/src/acpi/s3power/s3power.c
> index c391fd9..f93ffd2 100644
> --- a/src/acpi/s3power/s3power.c
> +++ b/src/acpi/s3power/s3power.c
> @@ -118,14 +118,18 @@ static int s3power_init(fwts_framework *fw)
>  /* Detect the best available power method */
>  static void detect_pm_method(fwts_pm_method_vars *fwts_settings)
>  {
> +#if FWTS_ENABLE_LOGIND
>  	if (fwts_logind_can_suspend(fwts_settings))
>  		fwts_settings->fw->pm_method = FWTS_PM_LOGIND;
> -	else if (fwts_sysfs_can_suspend(fwts_settings))
> +	else
> +#endif
> +	if (fwts_sysfs_can_suspend(fwts_settings))
>  		fwts_settings->fw->pm_method = FWTS_PM_SYSFS;
>  	else
>  		fwts_settings->fw->pm_method = FWTS_PM_PMUTILS;
>  }
>  
> +#if FWTS_ENABLE_LOGIND
>  static int wrap_logind_do_suspend(fwts_pm_method_vars *fwts_settings,
>  	const int percent,
>  	int *duration,
> @@ -141,6 +145,7 @@ static int wrap_logind_do_suspend(fwts_pm_method_vars *fwts_settings,
>  
>  	return *duration > 0 ? 0 : 1;
>  }
> +#endif
>  
>  static int wrap_sysfs_do_suspend(fwts_pm_method_vars *fwts_settings,
>  	const int percent,
> @@ -247,10 +252,12 @@ static int s3power_test(fwts_framework *fw)
>  
>  	int (*do_suspend)(fwts_pm_method_vars *, const int, int*, const char*);
>  
> +#if FWTS_ENABLE_LOGIND
>  #if !GLIB_CHECK_VERSION(2,35,0)
>  	/* This is for backward compatibility with old glib versions */
>  	g_type_init();
>  #endif
> +#endif
>  
>  	fwts_settings = calloc(1, sizeof(fwts_pm_method_vars));
>  	if (fwts_settings == NULL)
> @@ -264,6 +271,7 @@ static int s3power_test(fwts_framework *fw)
>  	}
>  
>  	switch (fw->pm_method) {
> +#if FWTS_ENABLE_LOGIND
>  		case FWTS_PM_LOGIND:
>  			fwts_log_info(fw, "Using logind as the default power method.");
>  			if (fwts_logind_init_proxy(fwts_settings) != 0) {
> @@ -272,6 +280,7 @@ static int s3power_test(fwts_framework *fw)
>  			}
>  			do_suspend = &wrap_logind_do_suspend;
>  			break;
> +#endif
>  		case FWTS_PM_PMUTILS:
>  			fwts_log_info(fw, "Using pm-utils as the default power method.");
>  			do_suspend = &wrap_pmutils_do_suspend;
> diff --git a/src/acpi/s4/s4.c b/src/acpi/s4/s4.c
> index 2ea76bb..684cb68 100644
> --- a/src/acpi/s4/s4.c
> +++ b/src/acpi/s4/s4.c
> @@ -89,14 +89,18 @@ static void s4_check_log(fwts_framework *fw,
>  /* Detect the best power method available */
>  static void detect_pm_method(fwts_pm_method_vars *fwts_settings)
>  {
> +#if FWTS_ENABLE_LOGIND
>  	if (fwts_logind_can_hibernate(fwts_settings))
>  		fwts_settings->fw->pm_method = FWTS_PM_LOGIND;
> -	else if (fwts_sysfs_can_hibernate(fwts_settings))
> +	else
> +#endif
> +	if (fwts_sysfs_can_hibernate(fwts_settings))
>  		fwts_settings->fw->pm_method = FWTS_PM_SYSFS;
>  	else
>  		fwts_settings->fw->pm_method = FWTS_PM_PMUTILS;
>  }
>  
> +#if FWTS_ENABLE_LOGIND
>  static int wrap_logind_do_s4(fwts_pm_method_vars *fwts_settings,
>  	const int percent,
>  	int *duration,
> @@ -113,6 +117,7 @@ static int wrap_logind_do_s4(fwts_pm_method_vars *fwts_settings,
>  
>  	return *duration > 0 ? 0 : 1;
>  }
> +#endif
>  
>  static int wrap_sysfs_do_s4(fwts_pm_method_vars *fwts_settings,
>  	const int percent,
> @@ -193,6 +198,7 @@ static int s4_hibernate(fwts_framework *fw,
>  	}
>  
>  	switch (fw->pm_method) {
> +#if FWTS_ENABLE_LOGIND
>  		case FWTS_PM_LOGIND:
>  			fwts_log_info(fw, "Using logind as the default power method.");
>  			if (fwts_logind_init_proxy(fwts_settings) != 0) {
> @@ -201,6 +207,7 @@ static int s4_hibernate(fwts_framework *fw,
>  			}
>  			do_s4 = &wrap_logind_do_s4;
>  			break;
> +#endif
>  		case FWTS_PM_PMUTILS:
>  			fwts_log_info(fw, "Using pm-utils as the default power method.");
>  			do_s4 = &wrap_pmutils_do_s4;
> @@ -348,10 +355,12 @@ static int s4_test_multiple(fwts_framework *fw)
>  	bool retried = false;
>  	char tmp[32];
>  
> +#if FWTS_ENABLE_LOGIND
>  #if !GLIB_CHECK_VERSION(2,35,0)
>  	/* This is for backward compatibility with old glib versions */
>  	g_type_init();
>  #endif
> +#endif
>  
>          if (s4_multiple == 1)
>                  fwts_log_info(fw, "Defaulted to run 1 test, run --s4-multiple=N to run more S4 cycles\n");
> diff --git a/src/lib/include/fwts_pm_method.h b/src/lib/include/fwts_pm_method.h
> index 75c9c84..5f9bcce 100644
> --- a/src/lib/include/fwts_pm_method.h
> +++ b/src/lib/include/fwts_pm_method.h
> @@ -25,6 +25,9 @@
>  #include <time.h>
>  #include <stdbool.h>
>  
> +#define FWTS_ENABLE_LOGIND 	\
> +	((GLIB_MAJOR_VERSION >= 2) && (GLIB_MINOR_VERSION >= 26))
> +
>  #include "fwts_types.h"
>  
>  typedef struct
> @@ -32,10 +35,12 @@ typedef struct
>  	fwts_framework *fw;
>  	time_t t_start;
>  	time_t t_end;
> +#if FWTS_ENABLE_LOGIND
>  	GDBusProxy *logind_proxy;
>  	GDBusConnection *logind_connection;
>  	GMainLoop *gmainloop;
>  	char *action;
> +#endif
>  	int  min_delay;
>  } fwts_pm_method_vars;
>  
> @@ -58,6 +63,7 @@ static inline void free_pm_method_vars(void *vars)
>  {
>  	fwts_pm_method_vars *var = *(void**)vars;
>  
> +#if FWTS_ENABLE_LOGIND
>  	if (var) {
>  		if (var->logind_proxy) {
>  			g_object_unref(var->logind_proxy);
> @@ -76,6 +82,7 @@ static inline void free_pm_method_vars(void *vars)
>  			var->action = NULL;
>  		}
>  	}
> +#endif
>  	free(var);
>  	var = NULL;
>  }
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 7229af5..f4500f8 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -28,6 +28,7 @@
>  #include <sys/time.h>
>  
>  #include "fwts.h"
> +#include "fwts_pm_method.h"
>  
>  /* Suffix ".log", ".xml", etc gets automatically appended */
>  #define RESULTS_LOG	"results"
> @@ -1005,14 +1006,21 @@ static int fwts_framework_acpica_parse(fwts_framework *fw, const char *arg)
>   */
>  static int fwts_framework_pm_method_parse(fwts_framework *fw, const char *arg)
>  {
> +#if FWTS_ENABLE_LOGIND
>  	if (strcmp(arg, "logind") == 0)
>  		fw->pm_method = FWTS_PM_LOGIND;
> -	else if (strcmp(arg, "pm-utils") == 0)
> +	else
> +#endif
> +	if (strcmp(arg, "pm-utils") == 0)
>  		fw->pm_method = FWTS_PM_PMUTILS;
>  	else if (strcmp(arg, "sysfs") == 0)
>  		fw->pm_method = FWTS_PM_SYSFS;
>  	else {
> -		fprintf(stderr, "--pm-method only supports logind, pm-utils, and sysfs methods\n");
> +#if FWTS_ENABLE_LOGIND
> +		fprintf(stderr, "--pm-method only supports logind, pm-utils and sysfs methods\n");
> +#else
> +		fprintf(stderr, "--pm-method only supports pm-utils and sysfs methods\n");
> +#endif
>  		return FWTS_ERROR;
>  	}
>  
> diff --git a/src/lib/src/fwts_pm_method.c b/src/lib/src/fwts_pm_method.c
> index 846aeff..9aed8b1 100644
> --- a/src/lib/src/fwts_pm_method.c
> +++ b/src/lib/src/fwts_pm_method.c
> @@ -23,6 +23,7 @@
>  #include "fwts.h"
>  #include "fwts_pm_method.h"
>  
> +#if FWTS_ENABLE_LOGIND
>  /*
>   *  logind_do()
>   *  call Logind to perform an action
> @@ -360,6 +361,7 @@ bool fwts_logind_can_hibernate(fwts_pm_method_vars *fwts_settings)
>  {
>  	return logind_can_do_action(fwts_settings, "CanHibernate");
>  }
> +#endif
>  
>  /*
>   *  fwts_sysfs_can_suspend()
> 

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list