1 /* ovirt viewer console application
2 * Copyright (C) 2008 Red Hat Inc.
3 * Written by Richard W.M. Jones <rjones@redhat.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef OVIRT_VIEWER_INTERNAL_H
21 #define OVIRT_VIEWER_INTERNAL_H
23 #ifndef G_THREADS_ENABLED
24 #error "This program requires GLib threads, and cannot be compiled without."
27 /* Debugging messages are always compiled in, but have to
28 * be turned on using the --debug command line switch.
30 extern gboolean debug;
32 #define DEBUG(fs,...) \
35 fprintf (stderr, "%s:%d: [thread %p] ", __FILE__, __LINE__, \
37 fprintf (stderr, (fs), ## __VA_ARGS__); \
38 fprintf (stderr, "\n"); \
42 /* Verbose messages are always compiled in, but have to
43 * be turned on using the --verbose command line switch.
45 extern gboolean verbose;
47 #define VERBOSE(fs,...) \
50 fprintf (stderr, "%s:%d: [thread %p] ", __FILE__, __LINE__, \
52 fprintf (stderr, (fs), ## __VA_ARGS__); \
53 fprintf (stderr, "\n"); \
57 /* String equality tests, suggested by Jim Meyering. */
58 #define STREQ(a,b) (strcmp((a),(b)) == 0)
59 #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
60 #define STRNEQ(a,b) (strcmp((a),(b)) != 0)
61 #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
62 #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
63 #define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
64 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
65 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
66 #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
68 extern const char *cainfo;
69 extern gboolean check_cert;
71 /* server we're connecting to */
72 extern const char* hostname;
74 /* vm currently in focus */
75 extern struct vm* vm_in_focus;
77 /* Communications between the main thread and the WUI thread. For
78 * an explanation of the threading model, please see the comment in
82 extern void start_wui_thread (void);
83 extern void stop_wui_thread (void);
85 extern void assert_is_main_thread (const char *, int);
86 extern void assert_is_wui_thread (const char *, int);
88 #define ASSERT_IS_MAIN_THREAD() assert_is_main_thread(__FILE__,__LINE__)
89 #define ASSERT_IS_WUI_THREAD() assert_is_wui_thread(__FILE__,__LINE__)
91 /* These are messages (instructions) which can be sent from the main
92 * thread to the WUI thread.
95 /* Start connecting to WUI, and set the base URI. */
96 extern void wui_thread_send_connect (const char *uri);
98 /* Disconnect, forget URI, credentials, VMs etc. */
99 extern void wui_thread_send_disconnect (void);
101 /* Set the username and password and tell the WUI to try to log in. */
102 extern void wui_thread_send_login (const char *username, const char *password);
104 /* Tell the WUI thread to refresh the VM list. Note that the WUI
105 * thread does this automatically anyway after a successful login, and
106 * it also periodically updates the list. This call just tells it to
109 extern void wui_thread_send_refresh_vm_list (void);
111 /* Retrieve the list of VMs.
113 * wui_thread_get_vmlist returns TRUE if there was a valid list of
114 * VMs (even if it is empty), or FALSE if we don't have a valid list
117 * NB: Caller must call free_vmlist once it is done with the list.
120 extern gboolean wui_thread_get_vmlist (GSList **ret);
121 extern void free_vmlist (GSList *vmlist);
128 int forward_vnc_port;
129 char *uuid; /* Printable UUID. */
132 /* Only the fields above this point are required. The remainder may
133 * be NULL / -1 to indicate they were missing in the data we got
137 long mem_allocated; /* Kbytes */
138 long mem_used; /* Kbytes */
141 char *mac_addr; /* Printable MAC addr. */
144 /* Returns true if the WUI thread thinks it is connected to a remote
145 * WUI. REST is connectionless so really this means that we
146 * successfully made an HTTP/HTTPS request "recently", and we haven't
147 * seen any errors above a certain threshold.
149 extern gboolean wui_thread_is_connected (void);
151 /* Returns true if we successfully logged in with the username
152 * and password supplied in a recent request, and we haven't
153 * received any authorization failures since.
155 extern gboolean wui_thread_is_logged_in (void);
157 /* Returns true if we have a valid list of VMs. Note that because
158 * of race conditions, this doesn't guarantee that wui_thread_get_vmlist
161 extern gboolean wui_thread_has_valid_vmlist (void);
163 /* Returns true if the WUI thread is busy performing a request
166 extern gboolean wui_thread_is_busy (void);
169 /* Communications between the main thread and the tunnel thread.*/
170 extern void start_tunnel (void);
171 extern void stop_tunnel (void);
173 /* port which local tunnel is listening on */
174 extern int tunnel_port;
177 /* Returns true if the main vm list contains a
178 * running vm w/ the same name as specified one
180 extern gboolean main_vmlist_has_running_vm(struct vm*);
182 /* Callbacks from the WUI thread to the main thread. The WUI thread
183 * adds these to the Glib main loop using g_idle_add, which means they
184 * actually get executed in the context of the main thread.
187 /* The WUI thread has changed its state to connected. */
188 extern gboolean main_connected (gpointer);
190 /* The WUI thread has changed its state to disconnected. */
191 extern gboolean main_disconnected (gpointer);
193 /* The WUI thread has changed its state to logged in. */
194 extern gboolean main_logged_in (gpointer);
196 /* The WUI thread has changed its state to logged out. */
197 extern gboolean main_logged_out (gpointer);
199 /* The WUI thread has changed its state to busy. */
200 extern gboolean main_busy (gpointer);
202 /* The WUI thread has changed its state to idle. */
203 extern gboolean main_idle (gpointer);
205 /* The WUI thread had a connection problem. */
206 extern gboolean main_connection_error (gpointer str);
208 /* The WUI thread had a login problem. */
209 extern gboolean main_login_error (gpointer str);
211 /* The WUI thread reports a general status error. */
212 extern gboolean main_status_error (gpointer str);
214 /* The WUI thread has updated the vm list. */
215 extern gboolean main_vmlist_updated (gpointer);
217 #endif /* OVIRT_VIEWER_INTERNAL_H */