[wing/wip/start-type] service: add start-type parameter to handle the kind of start for the service
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [wing/wip/start-type] service: add start-type parameter to handle the kind of start for the service
- Date: Mon, 24 Oct 2016 11:20:33 +0000 (UTC)
commit 59a0e1637d6590ac439dc23af5ac88a0c377d4e8
Author: Ignacio Casal Quinteiro <ignacio casal nice-software com>
Date: Mon Oct 24 13:08:25 2016 +0200
service: add start-type parameter to handle the kind of start for the service
wing/wingservice.c | 10 ++++++++-
wing/wingservicemanager.c | 20 +++++++++++++++---
wing/wingservicemanager.h | 47 +++++++++++++++++++++++++-------------------
3 files changed, 52 insertions(+), 25 deletions(-)
---
diff --git a/wing/wingservice.c b/wing/wingservice.c
index afbed23..348efd5 100644
--- a/wing/wingservice.c
+++ b/wing/wingservice.c
@@ -76,6 +76,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
static gboolean install_service;
static gboolean uninstall_service;
+static gchar *service_start_type;
static gboolean start_service;
static gboolean stop_service;
static gboolean exec_service_as_application;
@@ -85,6 +86,8 @@ static const GOptionEntry entries[] =
"Installs the service in the Windows service manager" },
{ "uninstall", '\0', 0, G_OPTION_ARG_NONE, &uninstall_service,
"Uninstalls the service from the Windows service manager" },
+ { "start-type", '\0', 0, G_OPTION_ARG_STRING, &service_start_type,
+ "Whether to start the service automatically or on demand", "auto|demand" },
{ "start", '\0', 0, G_OPTION_ARG_NONE, &start_service,
"Starts the service using the Windows service manager" },
{ "stop", '\0', 0, G_OPTION_ARG_NONE, &stop_service,
@@ -230,14 +233,18 @@ on_handle_local_options (GApplication *application,
{
WingServicePrivate *priv;
WingServiceManager *manager;
+ WingServiceManagerStartType start_type = WING_SERVICE_MANAGER_START_AUTO;
gint ret = -1;
manager = wing_service_manager_new ();
priv = wing_service_get_instance_private (service);
+ if (g_strcmp0 (service_start_type, "demand") == 0)
+ start_type = WING_SERVICE_MANAGER_START_DEMAND;
+
if (install_service)
- ret = wing_service_manager_install_service (manager, service, NULL) ? 0 : 1;
+ ret = wing_service_manager_install_service (manager, service, start_type, NULL) ? 0 : 1;
else if (uninstall_service)
ret = wing_service_manager_uninstall_service (manager, service, NULL) ? 0 : 1;
else if (stop_service)
@@ -248,6 +255,7 @@ on_handle_local_options (GApplication *application,
else if (start_service || priv->from_console)
ret = wing_service_manager_start_service (manager, service, 0, NULL, NULL) ? 0 : 1;
+ g_clear_pointer (&service_start_type, g_free);
g_object_unref (manager);
if (ret == -1)
diff --git a/wing/wingservicemanager.c b/wing/wingservicemanager.c
index 2fe353d..51e51d8 100644
--- a/wing/wingservicemanager.c
+++ b/wing/wingservicemanager.c
@@ -108,9 +108,10 @@ get_file_path (void)
}
gboolean
-wing_service_manager_install_service (WingServiceManager *manager,
- WingService *service,
- GError **error)
+wing_service_manager_install_service (WingServiceManager *manager,
+ WingService *service,
+ WingServiceManagerStartType start_type,
+ GError **error)
{
SC_HANDLE sc;
SC_HANDLE service_handle;
@@ -118,6 +119,7 @@ wing_service_manager_install_service (WingServiceManager *manager,
gboolean result = FALSE;
WingServiceFlags service_flags;
DWORD service_type;
+ DWORD service_start_type;
g_return_val_if_fail (WING_IS_SERVICE_MANAGER (manager), FALSE);
g_return_val_if_fail (WING_IS_SERVICE (service), FALSE);
@@ -133,12 +135,22 @@ wing_service_manager_install_service (WingServiceManager *manager,
if (service_flags & WING_SERVICE_IS_INTERACTIVE)
service_type |= SERVICE_INTERACTIVE_PROCESS;
+ switch (start_type)
+ {
+ case WING_SERVICE_MANAGER_START_AUTO:
+ service_start_type = SERVICE_AUTO_START;
+ break;
+ case WING_SERVICE_MANAGER_START_DEMAND:
+ service_start_type = SERVICE_DEMAND_START;
+ break;
+ }
+
service_handle = CreateServiceW (sc,
_wing_service_get_namew (service),
_wing_service_get_descriptionw (service),
SERVICE_ALL_ACCESS,
service_type,
- SERVICE_AUTO_START,
+ service_start_type,
SERVICE_ERROR_NORMAL,
path,
NULL, 0, NULL,
diff --git a/wing/wingservicemanager.h b/wing/wingservicemanager.h
index 1387cd4..4dd0fc7 100644
--- a/wing/wingservicemanager.h
+++ b/wing/wingservicemanager.h
@@ -29,6 +29,12 @@ G_BEGIN_DECLS
typedef struct _WingServiceManager WingServiceManager;
+typedef enum
+{
+ WING_SERVICE_MANAGER_START_AUTO,
+ WING_SERVICE_MANAGER_START_DEMAND
+} WingServiceManagerStartType;
+
WING_AVAILABLE_IN_ALL
GType wing_service_manager_get_type (void) G_GNUC_CONST;
@@ -36,36 +42,37 @@ WING_AVAILABLE_IN_ALL
WingServiceManager *wing_service_manager_new (void);
WING_AVAILABLE_IN_ALL
-gboolean wing_service_manager_install_service (WingServiceManager *manager,
- WingService *service,
- GError **error);
+gboolean wing_service_manager_install_service (WingServiceManager *manager,
+ WingService *service,
+ WingServiceManagerStartType
start_type,
+ GError **error);
WING_AVAILABLE_IN_ALL
-gboolean wing_service_manager_uninstall_service (WingServiceManager *manager,
- WingService *service,
- GError **error);
+gboolean wing_service_manager_uninstall_service (WingServiceManager *manager,
+ WingService *service,
+ GError **error);
WING_AVAILABLE_IN_ALL
-gboolean wing_service_manager_get_service_installed (WingServiceManager *manager,
- WingService *service,
- GError **error);
+gboolean wing_service_manager_get_service_installed (WingServiceManager *manager,
+ WingService *service,
+ GError **error);
WING_AVAILABLE_IN_ALL
-gboolean wing_service_manager_get_service_running (WingServiceManager *manager,
- WingService *service,
- GError **error);
+gboolean wing_service_manager_get_service_running (WingServiceManager *manager,
+ WingService *service,
+ GError **error);
WING_AVAILABLE_IN_ALL
-gboolean wing_service_manager_start_service (WingServiceManager *manager,
- WingService *service,
- int argc,
- char **argv,
- GError **error);
+gboolean wing_service_manager_start_service (WingServiceManager *manager,
+ WingService *service,
+ int argc,
+ char **argv,
+ GError **error);
WING_AVAILABLE_IN_ALL
-gboolean wing_service_manager_stop_service (WingServiceManager *manager,
- WingService *service,
- GError **error);
+gboolean wing_service_manager_stop_service (WingServiceManager *manager,
+ WingService *service,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]