38aef4b671c6d0cc2af5dd8253a17761475f63d8
[strongswan.git] / src / dumm / guest.h
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #ifndef GUEST_H
17 #define GUEST_H
18
19 #include <library.h>
20 #include <utils/iterator.h>
21
22 #include "iface.h"
23
24 typedef enum guest_state_t guest_state_t;
25
26 /**
27 * @brief State of a guest (started, stopped, ...)
28 */
29 enum guest_state_t {
30 /** guest kernel not running at all */
31 GUEST_STOPPED,
32 /** kernel started, but not yet available */
33 GUEST_STARTING,
34 /** guest is up and running */
35 GUEST_RUNNING,
36 /** guest has been paused */
37 GUEST_PAUSED,
38 /** guest is stopping (shutting down) */
39 GUEST_STOPPING,
40 };
41
42 /**
43 * string mappings for guest_state_t
44 */
45 extern enum_name_t *guest_state_names;
46
47 typedef struct guest_t guest_t;
48
49 /**
50 * @brief A guest is a UML instance running on the host.
51 **/
52 struct guest_t {
53
54 /**
55 * @brief Get the name of this guest.
56 *
57 * @return name of the guest
58 */
59 char* (*get_name) (guest_t *this);
60
61 /**
62 * @brief Get the process ID of the guest child process.
63 *
64 * @return name of the guest
65 */
66 pid_t (*get_pid) (guest_t *this);
67 /**
68 * @brief Get the state of the guest (stopped, started, etc.).
69 *
70 * @return guests state
71 */
72 guest_state_t (*get_state)(guest_t *this);
73
74 /**
75 * @brief Start the guest.
76 *
77 * @param kernel kernel to boot for this guest
78 * @return TRUE if guest successfully started
79 */
80 bool (*start) (guest_t *this, char *kernel);
81
82 /**
83 * @brief Kill the guest.
84 *
85 * @return TRUE if guest was running and killed
86 */
87 bool (*stop) (guest_t *this);
88
89 /**
90 * @brief Create a new interface for that host.
91 *
92 * @param name name of the interface in the guest
93 * @return created interface, or NULL if failed
94 */
95 iface_t* (*create_iface)(guest_t *this, char *name);
96
97 /**
98 * @brief Create an iterator over all guest interfaces.
99 *
100 * @return iterator over iface_t's
101 */
102 iterator_t* (*create_iface_iterator)(guest_t *this);
103
104 /**
105 * @brief Close and destroy a guest with all interfaces
106 */
107 void (*destroy) (guest_t *this);
108 };
109
110 /**
111 * @brief Create a new, unstarted guest.
112 *
113 * @param name name of the guest
114 * @param master read-only master filesystem for guest
115 * @param mem amount of memory to give the guest
116 */
117 guest_t *guest_create(char *name, char *master, int mem);
118
119 #endif /* GUEST_H */
120