d838fdec7590c7b487a6fe0dc45c28c2b5adea9c
[ovirt-viewer.git] / internal.h
1 /* ovirt viewer console application
2  * Copyright (C) 2008 Red Hat Inc.
3  * Written by Richard W.M. Jones <rjones@redhat.com>
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #ifndef OVIRT_VIEWER_INTERNAL_H
21 #define OVIRT_VIEWER_INTERNAL_H
22
23 #ifndef G_THREADS_ENABLED
24 #error "This program requires GLib threads, and cannot be compiled without."
25 #endif
26
27 /* Debugging messages are always compiled in, but have to
28  * be turned on using the --debug command line switch.
29  */
30 extern gboolean debug;
31
32 #define DEBUG(fs,...)                                                   \
33   do {                                                                  \
34     if (debug) {                                                        \
35       fprintf (stderr, "%s:%d: [thread %p] ", __FILE__, __LINE__,       \
36                g_thread_self ());                                       \
37       fprintf (stderr, (fs), ## __VA_ARGS__);                           \
38       fprintf (stderr, "\n");                                           \
39     }                                                                   \
40   } while (0)
41
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)
52
53 extern const char *cainfo;
54 extern gboolean check_cert;
55
56 /* Communications between the main thread and the WUI thread.  For
57  * an explanation of the threading model, please see the comment in
58  * main().
59  */
60
61 extern void start_wui_thread (void);
62 extern void stop_wui_thread (void);
63
64 /* These are messages (instructions) which can be sent from the main
65  * thread to the WUI thread.
66  */
67
68 /* Start connecting to WUI, and set the base URI. */
69 extern void wui_thread_send_connect (const char *uri);
70
71 /* Disconnect, forget URI, credentials, VMs etc. */
72 extern void wui_thread_send_disconnect (void);
73
74 /* Set the username and password and tell the WUI to try to log in. */
75 extern void wui_thread_send_login (const char *username, const char *password);
76
77 /* Tell the WUI thread to refresh the VM list.  Note that the WUI
78  * thread does this automatically anyway after a successful login, and
79  * it also periodically updates the list.  This call just tells it to
80  * do so right away.
81  */
82 extern void wui_thread_send_refresh_vm_list (void);
83
84 /* Retrieve the list of VMs.
85  *
86  * NB: Caller must call free_vmlist once it is done with the list.
87  *
88  * This can return NULL if the WUI thread doesn't have a valid
89  * list of VMs to return to the caller.  In the case of a valid,
90  * empty list, you will get a non-NULL GSList pointer to an empty
91  * list.
92  */
93 extern GSList *wui_thread_get_vmlist (void);
94 extern void free_vmlist (GSList *vmlist);
95
96 /* Returns true if the WUI thread thinks it is connected to a remote
97  * WUI.  REST is connectionless so really this means that we
98  * successfully made an HTTP/HTTPS request "recently", and we haven't
99  * seen any errors above a certain threshold.
100  */
101 extern gboolean wui_thread_is_connected (void);
102
103 /* Returns true if we successfully logged in with the username
104  * and password supplied in a recent request, and we haven't
105  * received any authorization failures since.
106  */
107 extern gboolean wui_thread_is_logged_in (void);
108
109 /* Returns true if we have a valid list of VMs.  Note that because
110  * of race conditions, this doesn't guarantee that wui_thread_get_vmlist
111  * will work.
112  */
113 extern gboolean wui_thread_has_valid_vmlist (void);
114
115 /* Returns true if the WUI thread is busy performing a request
116  * at the moment.
117  */
118 extern gboolean wui_thread_is_busy (void);
119
120 #endif /* OVIRT_VIEWER_INTERNAL_H */