Merge pull request #1803 from matt335672/wm_states
Readability fix for WM states (#1803)
This commit is contained in:
commit
8004a05a32
@ -150,7 +150,7 @@ xrdp_wm_get_wait_objs(struct xrdp_wm* self, tbus* robjs, int* rc,
|
||||
int
|
||||
xrdp_wm_check_wait_objs(struct xrdp_wm* self);
|
||||
int
|
||||
xrdp_wm_set_login_mode(struct xrdp_wm* self, int login_mode);
|
||||
xrdp_wm_set_login_state(struct xrdp_wm* self, enum wm_login_state login_state);
|
||||
|
||||
/* xrdp_process.c */
|
||||
struct xrdp_process*
|
||||
|
@ -241,7 +241,7 @@ xrdp_wm_ok_clicked(struct xrdp_bitmap *wnd)
|
||||
/* will copy these cause dialog gets freed */
|
||||
list_append_list_strdup(mod_data->names, wm->mm->login_names, 0);
|
||||
list_append_list_strdup(mod_data->values, wm->mm->login_values, 0);
|
||||
xrdp_wm_set_login_mode(wm, 2);
|
||||
xrdp_wm_set_login_state(wm, WMLS_START_CONNECT);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -132,7 +132,7 @@ xrdp_mm_module_cleanup(struct xrdp_mm *self)
|
||||
{
|
||||
/* make sure autologin is off */
|
||||
self->wm->session->client_info->rdp_autologin = 0;
|
||||
xrdp_wm_set_login_mode(self->wm, 0); /* reset session */
|
||||
xrdp_wm_set_login_state(self->wm, WMLS_RESET); /* reset session */
|
||||
}
|
||||
|
||||
}
|
||||
@ -1514,9 +1514,9 @@ static void cleanup_sesman_connection(struct xrdp_mm *self)
|
||||
self->delete_sesman_trans = 1;
|
||||
self->connected_state = 0;
|
||||
|
||||
if (self->wm->login_mode != 10)
|
||||
if (self->wm->login_state != WMLS_CLEANUP)
|
||||
{
|
||||
xrdp_wm_set_login_mode(self->wm, 11);
|
||||
xrdp_wm_set_login_state(self->wm, WMLS_INACTIVE);
|
||||
xrdp_mm_module_cleanup(self);
|
||||
}
|
||||
}
|
||||
@ -1596,7 +1596,7 @@ xrdp_mm_process_login_response(struct xrdp_mm *self, struct stream *s)
|
||||
if (xrdp_mm_setup_mod2(self, pguid) == 0)
|
||||
{
|
||||
xrdp_mm_get_value(self, "ip", ip, 255);
|
||||
xrdp_wm_set_login_mode(self->wm, 10);
|
||||
xrdp_wm_set_login_state(self->wm, WMLS_CLEANUP);
|
||||
self->wm->dragging = 0;
|
||||
|
||||
/* connect channel redir */
|
||||
@ -2350,7 +2350,7 @@ xrdp_mm_connect(struct xrdp_mm *self)
|
||||
{
|
||||
if (xrdp_mm_setup_mod2(self, 0) == 0)
|
||||
{
|
||||
xrdp_wm_set_login_mode(self->wm, 10);
|
||||
xrdp_wm_set_login_state(self->wm, WMLS_CLEANUP);
|
||||
rv = 0; /*success*/
|
||||
}
|
||||
else
|
||||
@ -2366,15 +2366,15 @@ xrdp_mm_connect(struct xrdp_mm *self)
|
||||
log_message(LOG_LEVEL_ERROR,"Failure setting up module");
|
||||
}
|
||||
|
||||
if (self->wm->login_mode != 10)
|
||||
if (self->wm->login_state != WMLS_CLEANUP)
|
||||
{
|
||||
xrdp_wm_set_login_mode(self->wm, 11);
|
||||
xrdp_wm_set_login_state(self->wm, WMLS_INACTIVE);
|
||||
xrdp_mm_module_cleanup(self);
|
||||
rv = 1; /* failure */
|
||||
}
|
||||
}
|
||||
|
||||
if ((self->wm->login_mode == 10) && (self->sesman_controlled == 0) &&
|
||||
if ((self->wm->login_state == WMLS_CLEANUP) && (self->sesman_controlled == 0) &&
|
||||
(self->usechansrv != 0))
|
||||
{
|
||||
/* if sesman controlled, this will connect later */
|
||||
|
@ -79,9 +79,10 @@ xrdp_process_loop(struct xrdp_process *self, struct stream *s)
|
||||
{
|
||||
DEBUG(("calling xrdp_wm_init and creating wm"));
|
||||
self->wm = xrdp_wm_create(self, self->session->client_info);
|
||||
/* at this point the wm(window manager) is create and wm::login_mode is
|
||||
zero and login_mode_event is set so xrdp_wm_init should be called by
|
||||
xrdp_wm_check_wait_objs */
|
||||
/* at this point the wm(window manager) is created and
|
||||
wm::login_state is WMLS_RESET and wm::login_state_event is set
|
||||
so xrdp_wm_init should be called by xrdp_wm_check_wait_objs
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -323,6 +323,42 @@ struct xrdp_keymap
|
||||
};
|
||||
|
||||
/* the window manager */
|
||||
|
||||
/***
|
||||
* Window manager login mode states
|
||||
*
|
||||
* Use with xrdp_wm_set_login_state()
|
||||
*/
|
||||
enum wm_login_state
|
||||
{
|
||||
/**
|
||||
* Place the window manager in this state to reset it
|
||||
*/
|
||||
WMLS_RESET = 0,
|
||||
/**
|
||||
* In this state, the window manager is waiting for the user to fill
|
||||
* in the login box
|
||||
*/
|
||||
WMLS_USER_PROMPT,
|
||||
/**
|
||||
* Place the window manager in this state to request xrdp connects to
|
||||
* the X server, sesman, chansrv etc
|
||||
*/
|
||||
WMLS_START_CONNECT,
|
||||
/**
|
||||
* In this state, the window manager is making required connections
|
||||
*/
|
||||
WMLS_CONNECT_IN_PROGRESS,
|
||||
/**
|
||||
* Place the window manager in this state to request it finishes.
|
||||
*/
|
||||
WMLS_CLEANUP,
|
||||
/**
|
||||
* In this state, the window manager is inactive
|
||||
*/
|
||||
WMLS_INACTIVE
|
||||
};
|
||||
|
||||
struct xrdp_wm
|
||||
{
|
||||
struct xrdp_process* pro_layer; /* owner */
|
||||
@ -374,8 +410,8 @@ struct xrdp_wm
|
||||
/* session log */
|
||||
struct list* log;
|
||||
struct xrdp_bitmap* log_wnd;
|
||||
int login_mode;
|
||||
tbus login_mode_event;
|
||||
enum wm_login_state login_state;
|
||||
tbus login_state_event;
|
||||
struct xrdp_mm* mm;
|
||||
struct xrdp_font* default_font;
|
||||
struct xrdp_keymap keymap;
|
||||
|
@ -63,10 +63,10 @@ xrdp_wm_create(struct xrdp_process *owner,
|
||||
self->pro_layer = owner;
|
||||
self->session = owner->session;
|
||||
pid = g_getpid();
|
||||
g_snprintf(event_name, 255, "xrdp_%8.8x_wm_login_mode_event_%8.8x",
|
||||
g_snprintf(event_name, 255, "xrdp_%8.8x_wm_login_state_event_%8.8x",
|
||||
pid, owner->session_id);
|
||||
log_message(LOG_LEVEL_DEBUG, "%s", event_name);
|
||||
self->login_mode_event = g_create_wait_obj(event_name);
|
||||
self->login_state_event = g_create_wait_obj(event_name);
|
||||
self->painter = xrdp_painter_create(self, self->session);
|
||||
self->cache = xrdp_cache_create(self, self->session, self->client_info);
|
||||
self->log = list_create();
|
||||
@ -75,7 +75,7 @@ xrdp_wm_create(struct xrdp_process *owner,
|
||||
self->default_font = xrdp_font_create(self);
|
||||
/* this will use built in keymap or load from file */
|
||||
get_keymaps(self->session->client_info->keylayout, &(self->keymap));
|
||||
xrdp_wm_set_login_mode(self, 0);
|
||||
xrdp_wm_set_login_state(self, WMLS_RESET);
|
||||
self->target_surface = self->screen;
|
||||
self->current_surface_index = 0xffff; /* screen */
|
||||
|
||||
@ -102,7 +102,7 @@ xrdp_wm_delete(struct xrdp_wm *self)
|
||||
list_delete(self->log);
|
||||
/* free default font */
|
||||
xrdp_font_delete(self->default_font);
|
||||
g_delete_wait_obj(self->login_mode_event);
|
||||
g_delete_wait_obj(self->login_state_event);
|
||||
|
||||
if (self->xrdp_config)
|
||||
g_free(self->xrdp_config);
|
||||
@ -753,7 +753,10 @@ xrdp_wm_init(struct xrdp_wm *self)
|
||||
list_add_item(self->mm->login_values, (long)g_strdup(r));
|
||||
}
|
||||
|
||||
xrdp_wm_set_login_mode(self, 2);
|
||||
/*
|
||||
* Skip the login box and go straight to the connection phase
|
||||
*/
|
||||
xrdp_wm_set_login_state(self, WMLS_START_CONNECT);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -780,7 +783,7 @@ xrdp_wm_init(struct xrdp_wm *self)
|
||||
/* clear screen */
|
||||
xrdp_bitmap_invalidate(self->screen, 0);
|
||||
xrdp_wm_set_focused(self, self->login_window);
|
||||
xrdp_wm_set_login_mode(self, 1);
|
||||
xrdp_wm_set_login_state(self, WMLS_USER_PROMPT);
|
||||
}
|
||||
|
||||
g_writeln("out xrdp_wm_init: ");
|
||||
@ -1932,29 +1935,27 @@ callback(intptr_t id, int msg, intptr_t param1, intptr_t param2,
|
||||
/* returns error */
|
||||
/* this gets called when there is nothing on any socket */
|
||||
static int
|
||||
xrdp_wm_login_mode_changed(struct xrdp_wm *self)
|
||||
xrdp_wm_login_state_changed(struct xrdp_wm *self)
|
||||
{
|
||||
if (self == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_writeln("xrdp_wm_login_mode_changed: login_mode is %d", self->login_mode);
|
||||
|
||||
if (self->login_mode == 0)
|
||||
if (self->login_state == WMLS_RESET)
|
||||
{
|
||||
/* this is the initial state of the login window */
|
||||
xrdp_wm_set_login_mode(self, 1); /* put the wm in login mode */
|
||||
xrdp_wm_set_login_state(self, WMLS_USER_PROMPT);
|
||||
list_clear(self->log);
|
||||
xrdp_wm_delete_all_children(self);
|
||||
self->dragging = 0;
|
||||
xrdp_wm_init(self);
|
||||
}
|
||||
else if (self->login_mode == 2)
|
||||
else if (self->login_state == WMLS_START_CONNECT)
|
||||
{
|
||||
if (xrdp_mm_connect(self->mm) == 0)
|
||||
{
|
||||
xrdp_wm_set_login_mode(self, 3); /* put the wm in connected mode */
|
||||
xrdp_wm_set_login_state(self, WMLS_CONNECT_IN_PROGRESS);
|
||||
xrdp_wm_delete_all_children(self);
|
||||
self->dragging = 0;
|
||||
}
|
||||
@ -1963,11 +1964,11 @@ xrdp_wm_login_mode_changed(struct xrdp_wm *self)
|
||||
/* we do nothing on connect error so far */
|
||||
}
|
||||
}
|
||||
else if (self->login_mode == 10)
|
||||
else if (self->login_state == WMLS_CLEANUP)
|
||||
{
|
||||
xrdp_wm_delete_all_children(self);
|
||||
self->dragging = 0;
|
||||
xrdp_wm_set_login_mode(self, 11);
|
||||
xrdp_wm_set_login_state(self, WMLS_INACTIVE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -2017,7 +2018,7 @@ xrdp_wm_log_wnd_notify(struct xrdp_bitmap *wnd,
|
||||
{
|
||||
/* make sure autologin is off */
|
||||
wm->session->client_info->rdp_autologin = 0;
|
||||
xrdp_wm_set_login_mode(wm, 0); /* reset session */
|
||||
xrdp_wm_set_login_state(wm, WMLS_RESET); /* reset session */
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2075,7 +2076,7 @@ xrdp_wm_show_log(struct xrdp_wm *self)
|
||||
{
|
||||
/* make sure autologin is off */
|
||||
self->session->client_info->rdp_autologin = 0;
|
||||
xrdp_wm_set_login_mode(self, 0); /* reset session */
|
||||
xrdp_wm_set_login_state(self, WMLS_RESET); /* reset session */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2176,7 +2177,7 @@ xrdp_wm_get_wait_objs(struct xrdp_wm *self, tbus *robjs, int *rc,
|
||||
}
|
||||
|
||||
i = *rc;
|
||||
robjs[i++] = self->login_mode_event;
|
||||
robjs[i++] = self->login_state_event;
|
||||
*rc = i;
|
||||
return xrdp_mm_get_wait_objs(self->mm, robjs, rc, wobjs, wc, timeout);
|
||||
}
|
||||
@ -2194,10 +2195,10 @@ xrdp_wm_check_wait_objs(struct xrdp_wm *self)
|
||||
|
||||
rv = 0;
|
||||
|
||||
if (g_is_wait_obj_set(self->login_mode_event))
|
||||
if (g_is_wait_obj_set(self->login_state_event))
|
||||
{
|
||||
g_reset_wait_obj(self->login_mode_event);
|
||||
xrdp_wm_login_mode_changed(self);
|
||||
g_reset_wait_obj(self->login_state_event);
|
||||
xrdp_wm_login_state_changed(self);
|
||||
}
|
||||
|
||||
if (rv == 0)
|
||||
@ -2209,10 +2210,46 @@ xrdp_wm_check_wait_objs(struct xrdp_wm *self)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
xrdp_wm_set_login_mode(struct xrdp_wm *self, int login_mode)
|
||||
|
||||
static const char *
|
||||
wm_login_state_to_str(enum wm_login_state login_state)
|
||||
{
|
||||
self->login_mode = login_mode;
|
||||
g_set_wait_obj(self->login_mode_event);
|
||||
const char *result = "unknown";
|
||||
/* Use a switch for this, as some compilers will warn about missing states
|
||||
*/
|
||||
switch (login_state)
|
||||
{
|
||||
case WMLS_RESET:
|
||||
result = "WMLS_RESET";
|
||||
break;
|
||||
case WMLS_USER_PROMPT:
|
||||
result = "WMLS_USER_PROMPT";
|
||||
break;
|
||||
case WMLS_START_CONNECT:
|
||||
result = "WMLS_START_CONNECT";
|
||||
break;
|
||||
case WMLS_CONNECT_IN_PROGRESS:
|
||||
result = "WMLS_CONNECT_IN_PROGRESS";
|
||||
break;
|
||||
case WMLS_CLEANUP:
|
||||
result = "WMLS_CLEANUP";
|
||||
break;
|
||||
case WMLS_INACTIVE:
|
||||
result = "WMLS_INACTIVE";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
xrdp_wm_set_login_state(struct xrdp_wm* self, enum wm_login_state login_state)
|
||||
{
|
||||
LOG(LOG_LEVEL_DEBUG, "Login state change request %s -> %s",
|
||||
wm_login_state_to_str(self->login_state),
|
||||
wm_login_state_to_str(login_state));
|
||||
|
||||
self->login_state = login_state;
|
||||
g_set_wait_obj(self->login_state_event);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user