Migrated guest_t to INIT/METHOD macros.

This commit is contained in:
Tobias Brunner 2011-10-03 16:11:55 +02:00
parent d6c8c0caa8
commit 41100c2429
1 changed files with 53 additions and 83 deletions

View File

@ -82,18 +82,14 @@ ENUM(guest_state_names, GUEST_STOPPED, GUEST_STOPPING,
"STOPPING", "STOPPING",
); );
/** METHOD(guest_t, get_name, char*,
* Implementation of guest_t.get_name. private_guest_t *this)
*/
static char* get_name(private_guest_t *this)
{ {
return this->name; return this->name;
} }
/** METHOD(guest_t, create_iface, iface_t*,
* Implementation of guest_t.create_iface. private_guest_t *this, char *name)
*/
static iface_t* create_iface(private_guest_t *this, char *name)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
iface_t *iface; iface_t *iface;
@ -126,10 +122,8 @@ static iface_t* create_iface(private_guest_t *this, char *name)
return iface; return iface;
} }
/** METHOD(guest_t, destroy_iface, void,
* Implementation of guest_t.destroy_iface. private_guest_t *this, iface_t *iface)
*/
static void destroy_iface(private_guest_t *this, iface_t *iface)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
iface_t *current; iface_t *current;
@ -147,26 +141,20 @@ static void destroy_iface(private_guest_t *this, iface_t *iface)
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
} }
/** METHOD(guest_t, create_iface_enumerator, enumerator_t*,
* Implementation of guest_t.create_iface_enumerator. private_guest_t *this)
*/
static enumerator_t* create_iface_enumerator(private_guest_t *this)
{ {
return this->ifaces->create_enumerator(this->ifaces); return this->ifaces->create_enumerator(this->ifaces);
} }
/** METHOD(guest_t, get_state, guest_state_t,
* Implementation of guest_t.get_state. private_guest_t *this)
*/
static guest_state_t get_state(private_guest_t *this)
{ {
return this->state; return this->state;
} }
/** METHOD(guest_t, get_pid, pid_t,
* Implementation of guest_t.get_pid. private_guest_t *this)
*/
static pid_t get_pid(private_guest_t *this)
{ {
return this->pid; return this->pid;
} }
@ -193,10 +181,8 @@ static char* write_arg(char **pos, size_t *left, char *format, ...)
return res; return res;
} }
/** METHOD(guest_t, stop, void,
* Implementation of guest_t.stop. private_guest_t *this, idle_function_t idle)
*/
static void stop(private_guest_t *this, idle_function_t idle)
{ {
if (this->state != GUEST_STOPPED) if (this->state != GUEST_STOPPED)
{ {
@ -236,11 +222,9 @@ void savepid(private_guest_t *this)
} }
} }
/** METHOD(guest_t, start, bool,
* Implementation of guest_t.start. private_guest_t *this, invoke_function_t invoke, void* data,
*/ idle_function_t idle)
static bool start(private_guest_t *this, invoke_function_t invoke, void* data,
idle_function_t idle)
{ {
char buf[2048]; char buf[2048];
char *notify; char *notify;
@ -296,10 +280,8 @@ static bool start(private_guest_t *this, invoke_function_t invoke, void* data,
return TRUE; return TRUE;
} }
/** METHOD(guest_t, add_overlay, bool,
* Implementation of guest_t.add_overlay. private_guest_t *this, char *path)
*/
static bool add_overlay(private_guest_t *this, char *path)
{ {
if (path == NULL) if (path == NULL)
{ {
@ -319,18 +301,14 @@ static bool add_overlay(private_guest_t *this, char *path)
return this->cowfs->add_overlay(this->cowfs, path); return this->cowfs->add_overlay(this->cowfs, path);
} }
/** METHOD(guest_t, del_overlay, bool,
* Implementation of guest_t.del_overlay. private_guest_t *this, char *path)
*/
static bool del_overlay(private_guest_t *this, char *path)
{ {
return this->cowfs->del_overlay(this->cowfs, path); return this->cowfs->del_overlay(this->cowfs, path);
} }
/** METHOD(guest_t, pop_overlay, bool,
* Implementation of guest_t.pop_overlay. private_guest_t *this)
*/
static bool pop_overlay(private_guest_t *this)
{ {
return this->cowfs->pop_overlay(this->cowfs); return this->cowfs->pop_overlay(this->cowfs);
} }
@ -356,11 +334,9 @@ static int vexec(private_guest_t *this, void(*cb)(void*,char*,size_t), void *dat
return -1; return -1;
} }
/** METHOD(guest_t, exec, int,
* Implementation of guest_t.exec private_guest_t *this, void(*cb)(void*,char*,size_t), void *data,
*/ char *cmd, ...)
static int exec(private_guest_t *this, void(*cb)(void*,char*,size_t), void *data,
char *cmd, ...)
{ {
int res; int res;
va_list args; va_list args;
@ -411,11 +387,9 @@ static void exec_str_cb(exec_str_t *data, char *buf, size_t len)
} }
} }
/** METHOD(guest_t, exec_str, int,
* Implementation of guest_t.exec_str private_guest_t *this, void(*cb)(void*,char*), bool lines, void *data,
*/ char *cmd, ...)
static int exec_str(private_guest_t *this, void(*cb)(void*,char*), bool lines,
void *data, char *cmd, ...)
{ {
int res; int res;
va_list args; va_list args;
@ -448,10 +422,8 @@ static int exec_str(private_guest_t *this, void(*cb)(void*,char*), bool lines,
return res; return res;
} }
/** METHOD(guest_t, sigchild, void,
* Implementation of guest_t.sigchild. private_guest_t *this)
*/
static void sigchild(private_guest_t *this)
{ {
DESTROY_IF(this->mconsole); DESTROY_IF(this->mconsole);
this->mconsole = NULL; this->mconsole = NULL;
@ -537,10 +509,8 @@ bool saveargs(private_guest_t *this, char *args)
return retval; return retval;
} }
/** METHOD(guest_t, destroy, void,
* Implementation of guest_t.destroy. private_guest_t *this)
*/
static void destroy(private_guest_t *this)
{ {
stop(this, NULL); stop(this, NULL);
umount_unionfs(this); umount_unionfs(this);
@ -562,23 +532,27 @@ static private_guest_t *guest_create_generic(char *parent, char *name,
bool create) bool create)
{ {
char cwd[PATH_MAX]; char cwd[PATH_MAX];
private_guest_t *this = malloc_thing(private_guest_t); private_guest_t *this;
this->public.get_name = (void*)get_name; INIT(this,
this->public.get_pid = (pid_t(*)(guest_t*))get_pid; .public = {
this->public.get_state = (guest_state_t(*)(guest_t*))get_state; .get_name = _get_name,
this->public.create_iface = (iface_t*(*)(guest_t*,char*))create_iface; .get_pid = _get_pid,
this->public.destroy_iface = (void(*)(guest_t*,iface_t*))destroy_iface; .get_state = _get_state,
this->public.create_iface_enumerator = (enumerator_t*(*)(guest_t*))create_iface_enumerator; .create_iface = _create_iface,
this->public.start = (void*)start; .destroy_iface = _destroy_iface,
this->public.stop = (void*)stop; .create_iface_enumerator = _create_iface_enumerator,
this->public.add_overlay = (bool(*)(guest_t*,char*))add_overlay; .start = _start,
this->public.del_overlay = (bool(*)(guest_t*,char*))del_overlay; .stop = _stop,
this->public.pop_overlay = (bool(*)(guest_t*))pop_overlay; .add_overlay = _add_overlay,
this->public.exec = (int(*)(guest_t*, void(*cb)(void*,char*,size_t),void*,char*,...))exec; .del_overlay = _del_overlay,
this->public.exec_str = (int(*)(guest_t*, void(*cb)(void*,char*),bool,void*,char*,...))exec_str; .pop_overlay = _pop_overlay,
this->public.sigchild = (void(*)(guest_t*))sigchild; .exec = _exec,
this->public.destroy = (void*)destroy; .exec_str = _exec_str,
.sigchild = _sigchild,
.destroy = _destroy,
}
);
if (*parent == '/' || getcwd(cwd, sizeof(cwd)) == NULL) if (*parent == '/' || getcwd(cwd, sizeof(cwd)) == NULL)
{ {
@ -611,13 +585,9 @@ static private_guest_t *guest_create_generic(char *parent, char *name,
free(this); free(this);
return NULL; return NULL;
} }
this->pid = 0;
this->state = GUEST_STOPPED; this->state = GUEST_STOPPED;
this->mconsole = NULL;
this->ifaces = linked_list_create(); this->ifaces = linked_list_create();
this->args = NULL;
this->name = strdup(name); this->name = strdup(name);
this->cowfs = NULL;
return this; return this;
} }