added autogen script to run autotools to generate configure and necessary make inputs
[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 extern void assert_is_main_thread (const char *, int);
65 extern void assert_is_wui_thread (const char *, int);
66
67 #define ASSERT_IS_MAIN_THREAD() assert_is_main_thread(__FILE__,__LINE__)
68 #define ASSERT_IS_WUI_THREAD() assert_is_wui_thread(__FILE__,__LINE__)
69
70 /* These are messages (instructions) which can be sent from the main
71  * thread to the WUI thread.
72  */
73
74 /* Start connecting to WUI, and set the base URI. */
75 extern void wui_thread_send_connect (const char *uri);
76
77 /* Disconnect, forget URI, credentials, VMs etc. */
78 extern void wui_thread_send_disconnect (void);
79
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);
82
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
86  * do so right away.
87  */
88 extern void wui_thread_send_refresh_vm_list (void);
89
90 /* Retrieve the list of VMs.
91  *
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
94  * of VMs to return.
95  *
96  * NB: Caller must call free_vmlist once it is done with the list.
97  *
98  */
99 extern gboolean wui_thread_get_vmlist (GSList **ret);
100 extern void free_vmlist (GSList *vmlist);
101
102 struct vm {
103   char *description;
104   int hostid;
105   int id;
106   int vnc_port;
107   int forward_vnc_port;
108   char *uuid;                   /* Printable UUID. */
109
110   /* Only the fields above this point are required.  The remainder may
111    * be NULL / -1 to indicate they were missing in the data we got
112    * back from the WUI.
113    */
114
115   long mem_allocated;           /* Kbytes */
116   long mem_used;                /* Kbytes */
117   int vcpus_allocated;
118   int vcpus_used;
119   char *state;
120   char *mac_addr;               /* Printable MAC addr. */
121 };
122
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.
127  */
128 extern gboolean wui_thread_is_connected (void);
129
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.
133  */
134 extern gboolean wui_thread_is_logged_in (void);
135
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
138  * will work.
139  */
140 extern gboolean wui_thread_has_valid_vmlist (void);
141
142 /* Returns true if the WUI thread is busy performing a request
143  * at the moment.
144  */
145 extern gboolean wui_thread_is_busy (void);
146
147 /* Callbacks from the WUI thread to the main thread.  The WUI thread
148  * adds these to the Glib main loop using g_idle_add, which means they
149  * actually get executed in the context of the main thread.
150  */
151
152 /* The WUI thread has changed its state to connected. */
153 extern gboolean main_connected (gpointer);
154
155 /* The WUI thread has changed its state to disconnected. */
156 extern gboolean main_disconnected (gpointer);
157
158 /* The WUI thread has changed its state to logged in. */
159 extern gboolean main_logged_in (gpointer);
160
161 /* The WUI thread has changed its state to logged out. */
162 extern gboolean main_logged_out (gpointer);
163
164 /* The WUI thread has changed its state to busy. */
165 extern gboolean main_busy (gpointer);
166
167 /* The WUI thread has changed its state to idle. */
168 extern gboolean main_idle (gpointer);
169
170 /* The WUI thread had a connection problem. */
171 extern gboolean main_connection_error (gpointer str);
172
173 /* The WUI thread had a login problem. */
174 extern gboolean main_login_error (gpointer str);
175
176 /* The WUI thread reports a general status error. */
177 extern gboolean main_status_error (gpointer str);
178
179 /* The WUI thread has updated the vm list. */
180 extern gboolean main_vmlist_updated (gpointer);
181
182 #endif /* OVIRT_VIEWER_INTERNAL_H */