Remmina - The GTK+ Remote Desktop Client  v1.4.2
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-2020 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_GTK_LABEL_SET_TEXT:
64  gtk_label_set_text( d->p.gtk_label_set_text.label, d->p.gtk_label_set_text.str );
65  break;
66  case FUNC_FTP_CLIENT_UPDATE_TASK:
68  break;
69  case FUNC_FTP_CLIENT_GET_WAITING_TASK:
71  break;
72  case FUNC_PROTOCOLWIDGET_EMIT_SIGNAL:
74  break;
75  case FUNC_PROTOCOLWIDGET_MPPROGRESS:
77  d->p.protocolwidget_mpprogress.response_callback, d->p.protocolwidget_mpprogress.response_callback_data);
78  break;
79  case FUNC_PROTOCOLWIDGET_MPDESTROY:
81  break;
82  case FUNC_PROTOCOLWIDGET_MPSHOWRETRY:
84  break;
85  case FUNC_PROTOCOLWIDGET_PANELSHOWLISTEN:
87  break;
88  case FUNC_SFTP_CLIENT_CONFIRM_RESUME:
89 #ifdef HAVE_LIBSSH
91  d->p.sftp_client_confirm_resume.path );
92 #endif
93  break;
94  case FUNC_VTE_TERMINAL_SET_ENCODING_AND_PTY:
95 #if defined (HAVE_LIBSSH) && defined (HAVE_LIBVTE)
100 #endif
101  break;
102 
103  }
104  pthread_mutex_lock(&d->pt_mutex);
105  d->complete = TRUE;
106  pthread_cond_signal(&d->pt_cond);
107  pthread_mutex_unlock(&d->pt_mutex);
108  }else {
109  /* thread has been cancelled, so we must free d memory here */
110  g_free(d);
111  }
112  return G_SOURCE_REMOVE;
113 }
114 
116 {
117  RemminaMTExecData *d = data;
118 
119  d->cancelled = TRUE;
120 }
121 
123 {
124  d->cancelled = FALSE;
125  d->complete = FALSE;
126  pthread_cleanup_push(remmina_masterthread_exec_cleanup_handler, (void*)d);
127  pthread_mutex_init(&d->pt_mutex, NULL);
128  pthread_cond_init(&d->pt_cond, NULL);
129  gdk_threads_add_idle((GSourceFunc)remmina_masterthread_exec_callback, (gpointer)d);
130  pthread_mutex_lock(&d->pt_mutex);
131  while (!d->complete)
132  pthread_cond_wait(&d->pt_cond, &d->pt_mutex);
133  pthread_cleanup_pop(0);
134  pthread_mutex_destroy(&d->pt_mutex);
135  pthread_cond_destroy(&d->pt_cond);
136 }
137 
139 {
140  /* To be called from main thread at startup */
141  gMainThreadID = pthread_self();
142 }
143 
145 {
146  return pthread_equal(gMainThreadID, pthread_self()) != 0;
147 }
148 
const gchar * remmina_file_get_string(RemminaFile *remminafile, const gchar *setting)
Definition: remmina_file.c:449
void remmina_protocol_widget_chat_receive(RemminaProtocolWidget *gp, const gchar *text)
struct remmina_masterthread_exec_data::@11::@15 file_get_string
void remmina_protocol_widget_save_cred(RemminaProtocolWidget *gp)
gint remmina_sftp_client_confirm_resume(RemminaSFTPClient *client, const gchar *path)
struct remmina_masterthread_exec_data::@11::@12 gtk_label_set_text
struct remmina_masterthread_exec_data::@11::@18 protocolwidget_emit_signal
struct remmina_masterthread_exec_data::@11::@16 ftp_client_update_task
enum remmina_masterthread_exec_data::@10 func
struct remmina_masterthread_exec_data::@11::@20 protocolwidget_mpdestroy
void remmina_masterthread_exec_save_main_thread_id()
struct remmina_masterthread_exec_data::@11::@14 chat_receive
struct remmina_masterthread_exec_data::@11::@24 vte_terminal_set_encoding_and_pty
void remmina_plugin_ssh_vte_terminal_set_encoding_and_pty(VteTerminal *terminal, const char *codeset, int master, int slave)
static pthread_t gMainThreadID
RemminaFTPTask * remmina_ftp_client_get_waiting_task(RemminaFTPClient *client)
void remmina_ftp_client_update_task(RemminaFTPClient *client, RemminaFTPTask *task)
struct remmina_masterthread_exec_data::@11::@17 ftp_client_get_waiting_task
void remmina_protocol_widget_panel_show_listen(RemminaProtocolWidget *gp, gint port)
gboolean remmina_masterthread_exec_is_main_thread()
union remmina_masterthread_exec_data::@11 p
void remmina_protocol_widget_mpdestroy(RemminaConnectionObject *cnnobj, RemminaMessagePanel *mp)
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::@11::@13 init_save_creds
struct remmina_masterthread_exec_data::@11::@21 protocolwidget_mpshowretry
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::@11::@19 protocolwidget_mpprogress
struct remmina_masterthread_exec_data::@11::@23 sftp_client_confirm_resume
struct remmina_masterthread_exec_data::@11::@22 protocolwidget_panelshowlisten