completed pkcs7 parsing methods
[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 Get a console pts device.
91 *
92 * Every guest has 5 consoles, numbered from 1 to 5. These are associated
93 * to a unique pts device on the host.
94 *
95 * @param console console number to get (1-5)
96 * @return pts device file name, NULL if failed
97 */
98 char* (*get_console) (guest_t *this, int console);
99
100 /**
101 * @brief Create a new interface in the current scenario.
102 *
103 * @param name name of the interface in the guest
104 * @return created interface, or NULL if failed
105 */
106 iface_t* (*create_iface)(guest_t *this, char *name);
107
108 /**
109 * @brief Create an iterator over all guest interfaces.
110 *
111 * @return iterator over iface_t's
112 */
113 iterator_t* (*create_iface_iterator)(guest_t *this);
114
115 /**
116 * @brief Set the template COWFS overlay to use.
117 *
118 * @param parent parent directory where template diff should point to
119 * @return FALSE if failed
120 */
121 bool (*load_template)(guest_t *this, char *parent);
122
123 /**
124 * @brief Called whenever a SIGCHILD for the guests PID is received.
125 */
126 void (*sigchild)(guest_t *this);
127
128 /**
129 * @brief Close and destroy a guest with all interfaces
130 */
131 void (*destroy) (guest_t *this);
132 };
133
134 /**
135 * @brief Create a new, unstarted guest.
136 *
137 * @param parent parent directory to create the guest in
138 * @param name name of the guest to create
139 * @param kernel kernel this guest uses
140 * @param master read-only master filesystem for guest
141 * @param mem amount of memory to give the guest
142 */
143 guest_t *guest_create(char *parent, char *name, char *kernel,
144 char *master, int mem);
145
146 /**
147 * @brief Load a guest created with guest_create().
148 *
149 * @param parent parent directory to look for a guest
150 * @param name name of the guest directory
151 */
152 guest_t *guest_load(char *parent, char *name);
153
154 #endif /* GUEST_H */
155