/* 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) /* 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; /* 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); /* 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. * * NB: Caller must call free_vmlist once it is done with the list. * * This can return NULL if the WUI thread doesn't have a valid * list of VMs to return to the caller. In the case of a valid, * empty list, you will get a non-NULL GSList pointer to an empty * list. */ extern GSList *wui_thread_get_vmlist (void); extern void free_vmlist (GSList *vmlist); /* 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); #endif /* OVIRT_VIEWER_INTERNAL_H */