/* ovirt viewer console application * Copyright (C) 2008 Red Hat Inc. * Written by Richard W.M. Jones * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OVIRT_VIEWER_INTERNAL_H #define OVIRT_VIEWER_INTERNAL_H #ifndef G_THREADS_ENABLED #error "This program requires GLib threads, and cannot be compiled without." #endif /* Debugging messages are always compiled in, but have to * be turned on using the --debug command line switch. */ extern gboolean debug; #define DEBUG(fs,...) \ do { \ if (debug) { \ fprintf (stderr, "%s:%d: [thread %p] ", __FILE__, __LINE__, \ g_thread_self ()); \ fprintf (stderr, (fs), ## __VA_ARGS__); \ fprintf (stderr, "\n"); \ } \ } while (0) /* Verbose messages are always compiled in, but have to * be turned on using the --verbose command line switch. */ extern gboolean verbose; #define VERBOSE(fs,...) \ do { \ if (verbose) { \ fprintf (stderr, "%s:%d: [thread %p] ", __FILE__, __LINE__, \ g_thread_self ()); \ fprintf (stderr, (fs), ## __VA_ARGS__); \ fprintf (stderr, "\n"); \ } \ } while (0) /* String equality tests, suggested by Jim Meyering. */ #define STREQ(a,b) (strcmp((a),(b)) == 0) #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) #define STRNEQ(a,b) (strcmp((a),(b)) != 0) #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0) #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0) #define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0) #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0) #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0) #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) extern const char *cainfo; extern gboolean check_cert; /* server we're connecting to */ extern const char* hostname; /* port which to connect to the server via vnc */ extern int ovirt_server_vnc_port; /* vm currently in focus */ extern struct vm* vm_in_focus; /* Communications between the main thread and the WUI thread. For * an explanation of the threading model, please see the comment in * main(). */ extern void start_wui_thread (void); extern void stop_wui_thread (void); extern void assert_is_main_thread (const char *, int); extern void assert_is_wui_thread (const char *, int); #define ASSERT_IS_MAIN_THREAD() assert_is_main_thread(__FILE__,__LINE__) #define ASSERT_IS_WUI_THREAD() assert_is_wui_thread(__FILE__,__LINE__) /* These are messages (instructions) which can be sent from the main * thread to the WUI thread. */ /* Start connecting to WUI, and set the base URI. */ extern void wui_thread_send_connect (const char *uri); /* Disconnect, forget URI, credentials, VMs etc. */ extern void wui_thread_send_disconnect (void); /* Set the username and password and tell the WUI to try to log in. */ extern void wui_thread_send_login (const char *username, const char *password); /* Tell the WUI thread to refresh the VM list. Note that the WUI * thread does this automatically anyway after a successful login, and * it also periodically updates the list. This call just tells it to * do so right away. */ extern void wui_thread_send_refresh_vm_list (void); /* Retrieve the list of VMs. * * wui_thread_get_vmlist returns TRUE if there was a valid list of * VMs (even if it is empty), or FALSE if we don't have a valid list * of VMs to return. * * NB: Caller must call free_vmlist once it is done with the list. * */ extern gboolean wui_thread_get_vmlist (GSList **ret); extern void free_vmlist (GSList *vmlist); struct vm { char *description; int hostid; int id; int vnc_port; int forward_vnc_port; char *uuid; /* Printable UUID. */ char *state; /* Only the fields above this point are required. The remainder may * be NULL / -1 to indicate they were missing in the data we got * back from the WUI. */ long mem_allocated; /* Kbytes */ long mem_used; /* Kbytes */ int vcpus_allocated; int vcpus_used; char *mac_addr; /* Printable MAC addr. */ }; /* Returns true if the WUI thread thinks it is connected to a remote * WUI. REST is connectionless so really this means that we * successfully made an HTTP/HTTPS request "recently", and we haven't * seen any errors above a certain threshold. */ extern gboolean wui_thread_is_connected (void); /* Returns true if we successfully logged in with the username * and password supplied in a recent request, and we haven't * received any authorization failures since. */ extern gboolean wui_thread_is_logged_in (void); /* Returns true if we have a valid list of VMs. Note that because * of race conditions, this doesn't guarantee that wui_thread_get_vmlist * will work. */ extern gboolean wui_thread_has_valid_vmlist (void); /* Returns true if the WUI thread is busy performing a request * at the moment. */ extern gboolean wui_thread_is_busy (void); /* Communications between the main thread and the tunnel thread.*/ extern void start_tunnel (void); extern void stop_tunnel (void); /* port which local tunnel is listening on */ extern int tunnel_port; /* Returns true if the main vm list contains a * running vm w/ the same name as specified one */ extern gboolean main_vmlist_has_running_vm(struct vm*); /* Callbacks from the WUI thread to the main thread. The WUI thread * adds these to the Glib main loop using g_idle_add, which means they * actually get executed in the context of the main thread. */ /* The WUI thread has changed its state to connected. */ extern gboolean main_connected (gpointer); /* The WUI thread has changed its state to disconnected. */ extern gboolean main_disconnected (gpointer); /* The WUI thread has changed its state to logged in. */ extern gboolean main_logged_in (gpointer); /* The WUI thread has changed its state to logged out. */ extern gboolean main_logged_out (gpointer); /* The WUI thread has changed its state to busy. */ extern gboolean main_busy (gpointer); /* The WUI thread has changed its state to idle. */ extern gboolean main_idle (gpointer); /* The WUI thread had a connection problem. */ extern gboolean main_connection_error (gpointer str); /* The WUI thread had a login problem. */ extern gboolean main_login_error (gpointer str); /* The WUI thread reports a general status error. */ extern gboolean main_status_error (gpointer str); /* The WUI thread has updated the vm list. */ extern gboolean main_vmlist_updated (gpointer); #endif /* OVIRT_VIEWER_INTERNAL_H */