Remmina - The GTK+ Remote Desktop Client  v1.4.33
Remmina is a remote desktop client written in GTK+, aiming to be useful for system administrators and travellers, who need to work with lots of remote computers in front of either large monitors or tiny netbooks. Remmina supports multiple network protocols in an integrated and consistent user interface. Currently RDP, VNC, NX, XDMCP and SSH are supported.
remmina_masterthread_exec.c
Go to the documentation of this file.
1 /*
2  * Remmina - The GTK+ Remote Desktop Client
3  * Copyright (C) 2009-2011 Vic Lee
4  * Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
5  * Copyright (C) 2016-2023 Antenore Gatta, Giovanni Panozzo
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  * In addition, as a special exception, the copyright holders give
23  * permission to link the code of portions of this program with the
24  * OpenSSL library under certain conditions as described in each
25  * individual source file, and distribute linked combinations
26  * including the two.
27  * You must obey the GNU General Public License in all respects
28  * for all of the code used other than OpenSSL. * If you modify
29  * file(s) with this exception, you may extend this exception to your
30  * version of the file(s), but you are not obligated to do so. * If you
31  * do not wish to do so, delete this exception statement from your
32  * version. * If you delete this exception statement from all source
33  * files in the program, then also delete it here.
34  *
35  */
36 
37 /* Support for execution on main thread of some GTK related
38  * functions (due to threads deprecations in GTK) */
39 
40 #include <gtk/gtk.h>
41 
43 
44 static pthread_t gMainThreadID;
45 
47 {
48 
49  /* This function is called on main GTK Thread via gdk_threads_add_idlde()
50  * from remmina_masterthread_exec_and_wait() */
51 
52  if (!d->cancelled) {
53  switch (d->func) {
54  case FUNC_INIT_SAVE_CRED:
56  break;
57  case FUNC_CHAT_RECEIVE:
59  break;
60  case FUNC_FILE_GET_STRING:
61  d->p.file_get_string.retval = remmina_file_get_string( d->p.file_get_string.remminafile, d->p.file_get_string.setting );
62  break;
63  case FUNC_FILE_SET_STRING:
64  remmina_file_set_string( d->p.file_set_string.remminafile, d->p.file_set_string.setting, d->p.file_set_string.value );
65  break;
66  case FUNC_GTK_LABEL_SET_TEXT:
67  gtk_label_set_text( d->p.gtk_label_set_text.label, d->p.gtk_label_set_text.str );
68  break;
69  case FUNC_FTP_CLIENT_UPDATE_TASK:
71  break;
72  case FUNC_FTP_CLIENT_GET_WAITING_TASK:
74  break;
75  case FUNC_PROTOCOLWIDGET_EMIT_SIGNAL:
77  break;
78  case FUNC_PROTOCOLWIDGET_MPPROGRESS:
80  d->p.protocolwidget_mpprogress.response_callback, d->p.protocolwidget_mpprogress.response_callback_data);
81  break;
82  case FUNC_PROTOCOLWIDGET_MPDESTROY:
84  break;
85  case FUNC_PROTOCOLWIDGET_MPSHOWRETRY:
87  break;
88  case FUNC_PROTOCOLWIDGET_PANELSHOWLISTEN:
90  break;
91  case FUNC_SFTP_CLIENT_CONFIRM_RESUME:
92 #ifdef HAVE_LIBSSH
94  d->p.sftp_client_confirm_resume.path );
95 #endif
96  break;
97  case FUNC_VTE_TERMINAL_SET_ENCODING_AND_PTY:
98 #if defined (HAVE_LIBSSH) && defined (HAVE_LIBVTE)
103 #endif
104  break;
105 
106  }
107  pthread_mutex_lock(&d->pt_mutex);
108  d->complete = TRUE;
109  pthread_cond_signal(&d->pt_cond);
110  pthread_mutex_unlock(&d->pt_mutex);
111  }else {
112  /* thread has been cancelled, so we must free d memory here */
113  g_free(d);
114  }
115  return G_SOURCE_REMOVE;
116 }
117 
119 {
120  RemminaMTExecData *d = data;
121 
122  d->cancelled = TRUE;
123 }
124 
126 {
127  d->cancelled = FALSE;
128  d->complete = FALSE;
129  pthread_cleanup_push(remmina_masterthread_exec_cleanup_handler, (void*)d);
130  pthread_mutex_init(&d->pt_mutex, NULL);
131  pthread_cond_init(&d->pt_cond, NULL);
132  gdk_threads_add_idle((GSourceFunc)remmina_masterthread_exec_callback, (gpointer)d);
133  pthread_mutex_lock(&d->pt_mutex);
134  while (!d->complete)
135  pthread_cond_wait(&d->pt_cond, &d->pt_mutex);
136  pthread_cleanup_pop(0);
137  pthread_mutex_destroy(&d->pt_mutex);
138  pthread_cond_destroy(&d->pt_cond);
139 }
140 
142 {
143  /* To be called from main thread at startup */
144  gMainThreadID = pthread_self();
145 }
146 
148 {
149  return pthread_equal(gMainThreadID, pthread_self()) != 0;
150 }
151 
struct remmina_masterthread_exec_data::@12::@14 init_save_creds
const gchar * remmina_file_get_string(RemminaFile *remminafile, const gchar *setting)
Definition: remmina_file.c:516
void remmina_protocol_widget_chat_receive(RemminaProtocolWidget *gp, const gchar *text)
void remmina_protocol_widget_save_cred(RemminaProtocolWidget *gp)
gint remmina_sftp_client_confirm_resume(RemminaSFTPClient *client, const gchar *path)
struct remmina_masterthread_exec_data::@12::@24 protocolwidget_panelshowlisten
void remmina_masterthread_exec_save_main_thread_id()
struct remmina_masterthread_exec_data::@12::@18 ftp_client_update_task
void remmina_plugin_ssh_vte_terminal_set_encoding_and_pty(VteTerminal *terminal, const char *codeset, int master, int slave)
struct remmina_masterthread_exec_data::@12::@19 ftp_client_get_waiting_task
static pthread_t gMainThreadID
RemminaFTPTask * remmina_ftp_client_get_waiting_task(RemminaFTPClient *client)
void remmina_ftp_client_update_task(RemminaFTPClient *client, RemminaFTPTask *task)
void remmina_protocol_widget_panel_show_listen(RemminaProtocolWidget *gp, gint port)
struct remmina_masterthread_exec_data::@12::@21 protocolwidget_mpprogress
gboolean remmina_masterthread_exec_is_main_thread()
struct remmina_masterthread_exec_data::@12::@22 protocolwidget_mpdestroy
struct remmina_masterthread_exec_data::@12::@23 protocolwidget_mpshowretry
struct remmina_masterthread_exec_data::@12::@26 vte_terminal_set_encoding_and_pty
void remmina_protocol_widget_mpdestroy(RemminaConnectionObject *cnnobj, RemminaMessagePanel *mp)
struct remmina_masterthread_exec_data::@12::@25 sftp_client_confirm_resume
RemminaMessagePanel * remmina_protocol_widget_mpprogress(RemminaConnectionObject *cnnobj, const gchar *msg, RemminaMessagePanelCallback response_callback, gpointer response_callback_data)
void remmina_protocol_widget_panel_show_retry(RemminaProtocolWidget *gp)
struct remmina_masterthread_exec_data::@12::@17 file_set_string
struct remmina_masterthread_exec_data::@12::@16 file_get_string
static void remmina_masterthread_exec_cleanup_handler(gpointer data)
void remmina_masterthread_exec_and_wait(RemminaMTExecData *d)
void remmina_protocol_widget_emit_signal(RemminaProtocolWidget *gp, const gchar *signal_name)
static gboolean remmina_masterthread_exec_callback(RemminaMTExecData *d)
struct remmina_masterthread_exec_data::@12::@13 gtk_label_set_text
struct remmina_masterthread_exec_data::@12::@15 chat_receive
union remmina_masterthread_exec_data::@12 p
struct remmina_masterthread_exec_data::@12::@20 protocolwidget_emit_signal
void remmina_file_set_string(RemminaFile *remminafile, const gchar *setting, const gchar *value)
Definition: remmina_file.c:469
enum remmina_masterthread_exec_data::@11 func