eb85ccb3cb6d3ba696127484e57c136e8e91e827
[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 /**
69 * @brief Get the state of the guest (stopped, started, etc.).
70 *
71 * @return guests state
72 */
73 guest_state_t (*get_state)(guest_t *this);
74
75 /**
76 * @brief Start the guest.
77 *
78 * @return TRUE if guest successfully started
79 */
80 bool (*start) (guest_t *this);
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 in the current scenario.
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 Set the scenario COWFS overlay to use.
106 *
107 * @param parent parent directory where scenario diff should point to
108 * @return FALSE if failed
109 */
110 bool (*set_scenario)(guest_t *this, char *parent);
111
112 /**
113 * @brief Called whenever a SIGCHILD for the guests PID is received.
114 */
115 void (*sigchild)(guest_t *this);
116
117 /**
118 * @brief Close and destroy a guest with all interfaces
119 */
120 void (*destroy) (guest_t *this);
121 };
122
123 /**
124 * @brief Create a new, unstarted guest.
125 *
126 * @param parent parent directory to create the guest in
127 * @param name name of the guest to create
128 * @param kernel kernel this guest uses
129 * @param master read-only master filesystem for guest
130 * @param mem amount of memory to give the guest
131 */
132 guest_t *guest_create(char *parent, char *name, char *kernel,
133 char *master, int mem);
134
135 /**
136 * @brief Load a guest created with guest_create().
137 *
138 * @param parent parent directory to look for a guest
139 * @param name name of the guest directory
140 */
141 guest_t *guest_load(char *parent, char *name);
142
143 #endif /* GUEST_H */
144