| 1 | /* |
|---|
| 2 | * Copyright (c) 2006 XenSource, Inc. |
|---|
| 3 | * |
|---|
| 4 | * This library is free software; you can redistribute it and/or |
|---|
| 5 | * modify it under the terms of the GNU Lesser General Public |
|---|
| 6 | * License as published by the Free Software Foundation; either |
|---|
| 7 | * version 2.1 of the License, or (at your option) any later version. |
|---|
| 8 | * |
|---|
| 9 | * This library is distributed in the hope that it will be useful, |
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 12 | * Lesser General Public License for more details. |
|---|
| 13 | * |
|---|
| 14 | * You should have received a copy of the GNU Lesser General Public |
|---|
| 15 | * License along with this library; if not, write to the Free Software |
|---|
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | #ifndef XEN_COMMON_H |
|---|
| 20 | #define XEN_COMMON_H |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #include <stdbool.h> |
|---|
| 24 | #include <stddef.h> |
|---|
| 25 | #include <stdint.h> |
|---|
| 26 | #include <time.h> |
|---|
| 27 | |
|---|
| 28 | #include "xen/api/xen_host_decl.h" |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | typedef bool (*xen_result_func)(const void *data, size_t len, |
|---|
| 32 | void *result_handle); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * len does not include a terminating \0. |
|---|
| 37 | */ |
|---|
| 38 | typedef int (*xen_call_func)(const void *, size_t len, void *user_handle, |
|---|
| 39 | void *result_handle, |
|---|
| 40 | xen_result_func result_func); |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | typedef struct |
|---|
| 44 | { |
|---|
| 45 | xen_call_func call_func; |
|---|
| 46 | void *handle; |
|---|
| 47 | const char *session_id; |
|---|
| 48 | bool ok; |
|---|
| 49 | char **error_description; |
|---|
| 50 | int error_description_count; |
|---|
| 51 | } xen_session; |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | typedef struct xen_session_record |
|---|
| 55 | { |
|---|
| 56 | char *uuid; |
|---|
| 57 | struct xen_host_record_opt *this_host; |
|---|
| 58 | char *this_user; |
|---|
| 59 | time_t last_active; |
|---|
| 60 | } xen_session_record; |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | * Allocate a xen_session_record. |
|---|
| 65 | */ |
|---|
| 66 | extern xen_session_record * |
|---|
| 67 | xen_session_record_alloc(void); |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | * Free the given xen_session_record, and all referenced values. The |
|---|
| 72 | * given record must have been allocated by this library. |
|---|
| 73 | */ |
|---|
| 74 | extern void |
|---|
| 75 | xen_session_record_free(xen_session_record *record); |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | struct xen_task_; |
|---|
| 79 | typedef struct xen_task_ * xen_task_id; |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | typedef struct |
|---|
| 83 | { |
|---|
| 84 | int progress; |
|---|
| 85 | long eta; |
|---|
| 86 | /* !!! RESULT */ |
|---|
| 87 | } xen_task_status; |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | typedef struct |
|---|
| 91 | { |
|---|
| 92 | int major; |
|---|
| 93 | int minor; |
|---|
| 94 | int patch; |
|---|
| 95 | char *extraversion; |
|---|
| 96 | } xen_version; |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | /** |
|---|
| 100 | * Free the given xen_version, and all referenced values. |
|---|
| 101 | */ |
|---|
| 102 | extern void xen_version_free(xen_version *version); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * Return the version of this client-side library. This will be the major, |
|---|
| 107 | * minor, and extraversion of the Xen release with which it was released, |
|---|
| 108 | * plus the library's own version as the patch. |
|---|
| 109 | */ |
|---|
| 110 | extern xen_version *xen_get_client_side_version(); |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | extern bool |
|---|
| 114 | xen_uuid_string_to_bytes(char *uuid, char **bytes); |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | extern bool |
|---|
| 118 | xen_uuid_bytes_to_string(char *bytes, char **uuid); |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | extern void |
|---|
| 122 | xen_uuid_free(char *uuid); |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | extern void |
|---|
| 126 | xen_uuid_bytes_free(char *bytes); |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | /** |
|---|
| 130 | * Initialise this library. Call this before starting to use this library. |
|---|
| 131 | * Note that since this library depends upon libxml2, you should also call |
|---|
| 132 | * xmlInitParser as appropriate for your program. |
|---|
| 133 | */ |
|---|
| 134 | extern |
|---|
| 135 | void xen_init(void); |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | /** |
|---|
| 139 | * Clear up this library. Call when you have finished using this library. |
|---|
| 140 | * Note that since this library depends upon libxml2, you should also call |
|---|
| 141 | * xmlCleanupParser as appropriate for your program. |
|---|
| 142 | */ |
|---|
| 143 | extern |
|---|
| 144 | void xen_fini(void); |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | /** |
|---|
| 148 | * Log in at the server, and allocate a xen_session to represent this session. |
|---|
| 149 | */ |
|---|
| 150 | extern xen_session * |
|---|
| 151 | xen_session_login_with_password(xen_call_func call_func, void *handle, |
|---|
| 152 | const char *uname, const char *pwd); |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | /** |
|---|
| 156 | * Log out at the server, and free the xen_session. |
|---|
| 157 | */ |
|---|
| 158 | extern void |
|---|
| 159 | xen_session_logout(xen_session *session); |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | /** |
|---|
| 163 | * Clear any error condition recorded on this session. |
|---|
| 164 | */ |
|---|
| 165 | void |
|---|
| 166 | xen_session_clear_error(xen_session *session); |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | /** |
|---|
| 170 | * Get the UUID of the second given session. Set *result to point at a |
|---|
| 171 | * string, yours to free. |
|---|
| 172 | */ |
|---|
| 173 | extern bool |
|---|
| 174 | xen_session_get_uuid(xen_session *session, char **result, |
|---|
| 175 | xen_session *self_session); |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | /** |
|---|
| 179 | * Get the this_host field of the second given session. Set *result to be a |
|---|
| 180 | * handle to that host. |
|---|
| 181 | */ |
|---|
| 182 | extern bool |
|---|
| 183 | xen_session_get_this_host(xen_session *session, xen_host *result, |
|---|
| 184 | xen_session *self_session); |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | /** |
|---|
| 188 | * Get the this_user field of the second given session. Set *result to point |
|---|
| 189 | * at a string, yours to free. |
|---|
| 190 | */ |
|---|
| 191 | extern bool |
|---|
| 192 | xen_session_get_this_user(xen_session *session, char **result, |
|---|
| 193 | xen_session *self_session); |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | /** |
|---|
| 197 | * Get the last_active field of the given session, and place it in *result. |
|---|
| 198 | */ |
|---|
| 199 | extern bool |
|---|
| 200 | xen_session_get_last_active(xen_session *session, time_t *result, |
|---|
| 201 | xen_session *self_session); |
|---|
| 202 | |
|---|
| 203 | /** |
|---|
| 204 | * Get a record containing the current state of the second given session. |
|---|
| 205 | */ |
|---|
| 206 | extern bool |
|---|
| 207 | xen_session_get_record(xen_session *session, xen_session_record **result, |
|---|
| 208 | xen_session *self_session); |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | #endif |
|---|