clients: cleanup includes for polkit sources

Some cleanup of the includes. For example, immediately after
"nm-default.h" include the header file for the current source.

Also, move the use of the "#if WITH_POLKIT_AGENT" conditionals
closer together. E.g. don't use the #if in "nmcli.h".
This commit is contained in:
Thomas Haller 2018-02-10 00:10:16 +01:00
parent 44d638d69d
commit 0ee8e2f57b
4 changed files with 21 additions and 42 deletions

View file

@ -21,15 +21,8 @@
#define NMC_NMCLI_H
#include "nm-secret-agent-old.h"
#include "nm-meta-setting-desc.h"
#if WITH_POLKIT_AGENT
#include "nm-polkit-listener.h"
#else
/* polkit agent is not available; define fake NMPolkitListener */
typedef gpointer NMPolkitListener;
#endif
typedef char *(*NmcCompEntryFunc) (const char *, int);

View file

@ -19,8 +19,6 @@
#include "nm-default.h"
#if WITH_POLKIT_AGENT
#include "polkit-agent.h"
#include <stdio.h>
@ -29,9 +27,9 @@
#include <unistd.h>
#include "nm-polkit-listener.h"
#include "common.h"
#if WITH_POLKIT_AGENT
static char *
polkit_request (const char *request,
const char *action_id,
@ -39,7 +37,7 @@ polkit_request (const char *request,
const char *icon_name,
const char *user,
gboolean echo_on,
gpointer user_data)
gpointer user_data)
{
char *response, *tmp, *p;
@ -79,10 +77,12 @@ polkit_completed (gboolean gained_authorization)
/* We don't print anything here. The outcome will be evident from
* the operation result anyway. */
}
#endif
gboolean
nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error)
{
#if WITH_POLKIT_AGENT
PolkitAgentListener *listener;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@ -97,18 +97,22 @@ nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error)
nm_polkit_listener_set_completed_callback (NM_POLKIT_LISTENER (listener), polkit_completed);
nmc->pk_listener = NM_POLKIT_LISTENER (listener);
#endif
return TRUE;
}
void
nmc_polkit_agent_fini (NmCli* nmc)
{
#if WITH_POLKIT_AGENT
g_clear_object (&nmc->pk_listener);
#endif
}
gboolean
nmc_start_polkit_agent_start_try (NmCli *nmc)
{
#if WITH_POLKIT_AGENT
GError *error = NULL;
/* We don't register polkit agent at all when running non-interactively */
@ -121,30 +125,6 @@ nmc_start_polkit_agent_start_try (NmCli *nmc)
g_error_free (error);
return FALSE;
}
#endif
return TRUE;
}
#else
/* polkit agent is not avalable; implement stub functions. */
#include "nmcli.h"
#include "polkit-agent.h"
gboolean
nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error)
{
return TRUE;
}
void
nmc_polkit_agent_fini (NmCli* nmc)
{
}
gboolean
nmc_start_polkit_agent_start_try (NmCli *nmc)
{
return TRUE;
}
#endif /* #if WITH_POLKIT_AGENT */

View file

@ -33,12 +33,12 @@
#include "nm-default.h"
#include "nm-polkit-listener.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "nm-polkit-listener.h"
G_DEFINE_TYPE (NMPolkitListener, nm_polkit_listener, POLKIT_AGENT_TYPE_LISTENER)
#define NM_POLKIT_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerPrivate))

View file

@ -19,6 +19,12 @@
#ifndef __NM_POLKIT_LISTENER_H__
#define __NM_POLKIT_LISTENER_H__
struct _NMPolkitListener;
typedef struct _NMPolkitListener NMPolkitListener;
#if WITH_POLKIT_AGENT
#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE
#include <polkitagent/polkitagent.h>
@ -72,14 +78,12 @@ typedef void (*NMPolkitListenerOnShowErrorFunc) (const char *text);
typedef void (*NMPolkitListenerOnCompletedFunc) (gboolean gained_authorization);
typedef struct {
struct _NMPolkitListener {
PolkitAgentListener parent;
} NMPolkitListener;
};
typedef struct {
PolkitAgentListenerClass parent;
} NMPolkitListenerClass;
GType nm_polkit_listener_get_type (void);
@ -95,4 +99,6 @@ void nm_polkit_listener_set_show_error_callback (NMPolkitListener *self,
void nm_polkit_listener_set_completed_callback (NMPolkitListener *self,
NMPolkitListenerOnCompletedFunc completed_callback);
#endif
#endif /* __NM_POLKIT_LISTENER_H__ */