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 /* String equality tests, suggested by Jim Meyering. */
43 #define STREQ(a,b) (strcmp((a),(b)) == 0)
44 #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
45 #define STRNEQ(a,b) (strcmp((a),(b)) != 0)
46 #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
47 #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
48 #define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
49 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
50 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
51 #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
53 extern const char *cainfo;
54 extern gboolean check_cert;
56 /* Communications between the main thread and the WUI thread. For
57 * an explanation of the threading model, please see the comment in
61 extern void start_wui_thread (void);
62 extern void stop_wui_thread (void);
64 extern void assert_is_main_thread (const char *, int);
65 extern void assert_is_wui_thread (const char *, int);
67 #define ASSERT_IS_MAIN_THREAD() assert_is_main_thread(__FILE__,__LINE__)
68 #define ASSERT_IS_WUI_THREAD() assert_is_wui_thread(__FILE__,__LINE__)
70 /* These are messages (instructions) which can be sent from the main
71 * thread to the WUI thread.
74 /* Start connecting to WUI, and set the base URI. */
75 extern void wui_thread_send_connect (const char *uri);
77 /* Disconnect, forget URI, credentials, VMs etc. */
78 extern void wui_thread_send_disconnect (void);
80 /* Set the username and password and tell the WUI to try to log in. */
81 extern void wui_thread_send_login (const char *username, const char *password);
83 /* Tell the WUI thread to refresh the VM list. Note that the WUI
84 * thread does this automatically anyway after a successful login, and
85 * it also periodically updates the list. This call just tells it to
88 extern void wui_thread_send_refresh_vm_list (void);
90 /* Retrieve the list of VMs.
92 * wui_thread_get_vmlist returns TRUE if there was a valid list of
93 * VMs (even if it is empty), or FALSE if we don't have a valid list
96 * NB: Caller must call free_vmlist once it is done with the list.
99 extern gboolean wui_thread_get_vmlist (GSList **ret);
100 extern void free_vmlist (GSList *vmlist);
107 int forward_vnc_port;
108 char *uuid; /* Printable UUID. */
111 /* Only the fields above this point are required. The remainder may
112 * be NULL / -1 to indicate they were missing in the data we got
116 long mem_allocated; /* Kbytes */
117 long mem_used; /* Kbytes */
120 char *mac_addr; /* Printable MAC addr. */
123 /* Returns true if the WUI thread thinks it is connected to a remote
124 * WUI. REST is connectionless so really this means that we
125 * successfully made an HTTP/HTTPS request "recently", and we haven't
126 * seen any errors above a certain threshold.
128 extern gboolean wui_thread_is_connected (void);
130 /* Returns true if we successfully logged in with the username
131 * and password supplied in a recent request, and we haven't
132 * received any authorization failures since.
134 extern gboolean wui_thread_is_logged_in (void);
136 /* Returns true if we have a valid list of VMs. Note that because
137 * of race conditions, this doesn't guarantee that wui_thread_get_vmlist
140 extern gboolean wui_thread_has_valid_vmlist (void);
142 /* Returns true if the WUI thread is busy performing a request
145 extern gboolean wui_thread_is_busy (void);
147 /* Returns true if the main vm list contains a
148 * running vm w/ the same name as specified one
150 extern gboolean main_vmlist_has_running_vm(struct vm*);
152 /* Callbacks from the WUI thread to the main thread. The WUI thread
153 * adds these to the Glib main loop using g_idle_add, which means they
154 * actually get executed in the context of the main thread.
157 /* The WUI thread has changed its state to connected. */
158 extern gboolean main_connected (gpointer);
160 /* The WUI thread has changed its state to disconnected. */
161 extern gboolean main_disconnected (gpointer);
163 /* The WUI thread has changed its state to logged in. */
164 extern gboolean main_logged_in (gpointer);
166 /* The WUI thread has changed its state to logged out. */
167 extern gboolean main_logged_out (gpointer);
169 /* The WUI thread has changed its state to busy. */
170 extern gboolean main_busy (gpointer);
172 /* The WUI thread has changed its state to idle. */
173 extern gboolean main_idle (gpointer);
175 /* The WUI thread had a connection problem. */
176 extern gboolean main_connection_error (gpointer str);
178 /* The WUI thread had a login problem. */
179 extern gboolean main_login_error (gpointer str);
181 /* The WUI thread reports a general status error. */
182 extern gboolean main_status_error (gpointer str);
184 /* The WUI thread has updated the vm list. */
185 extern gboolean main_vmlist_updated (gpointer);
187 #endif /* OVIRT_VIEWER_INTERNAL_H */