1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "surf_private.h"
11 #include "surf/surf_resource.h"
12 #include "simgrid/sg_config.h"
14 typedef struct workstation_VM2013 {
15 s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */
16 surf_resource_t physical_workstation; // Pointer to the host OS
17 e_msg_vm_state_t current_state; // See include/msg/datatypes.h
18 } s_workstation_VM2013_t, *workstation_VM2013_t;
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf,
21 "Logging specific to the SURF VM workstation module");
23 surf_model_t surf_vm_workstation_model = NULL;
25 static void vm_ws_create (const char *name, void *phys_workstation)
27 workstation_VM2013_t vm_ws = xbt_new0(s_workstation_VM2013_t, 1);
28 // TODO Complete the surf vm workstation model
29 vm_ws->generic_resource.model = surf_vm_workstation_model;
30 vm_ws->generic_resource.name = xbt_strdup(name);
31 vm_ws->physical_workstation = phys_workstation;
32 vm_ws->current_state=msg_vm_state_created,
33 xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, vm_ws);
36 * A physical host does not disapper in the current SimGrid code, but a VM may
37 * disapper during a simulation.
39 static void vm_ws_destroy(const char *name)
41 workstation_VM2013_t workstation = xbt_lib_get_or_null(host_lib, name, SURF_WKS_LEVEL);
42 xbt_assert(workstation);
43 xbt_assert(workstation->generic_resource.model == surf_vm_workstation_model);
45 xbt_free(workstation->generic_resource.name);
47 /* not defined yet, but we should have */
48 // xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL);
50 xbt_free(workstation);
53 static int vm_ws_get_state(void *vm_ws){
54 return ((workstation_VM2013_t)vm_ws)->current_state;
57 static void vm_ws_set_state(void *vm_ws, int state){
58 ((workstation_VM2013_t)vm_ws)->current_state=state;
60 static void surf_vm_workstation_model_init_internal(void)
62 surf_vm_workstation_model = surf_model_init();
64 surf_vm_workstation_model->name = "Virtual Workstation";
66 surf_vm_workstation_model->extension.vm_workstation.create = vm_ws_create;
67 surf_vm_workstation_model->extension.vm_workstation.set_state = vm_ws_set_state;
68 surf_vm_workstation_model->extension.vm_workstation.get_state = vm_ws_get_state;
69 surf_vm_workstation_model->extension.vm_workstation.destroy = vm_ws_destroy;
73 void surf_vm_workstation_model_init()
75 surf_vm_workstation_model_init_internal();
76 xbt_dynar_push(model_list, &surf_vm_workstation_model);