コード例 #1
0
ファイル: graph_engine.c プロジェクト: jimiszm/peos
vm_exit_code handle_action_change(int pid, char *action, vm_act_state state)
{
    Graph g;
    char msg[256], *this_state;
    vm_exit_code exit_status;

    peos_context_t *context = peos_get_context(pid);

    this_state = act_state_name(state);
    sprintf(msg, "%s %s %s %d ",login_name, this_state, action, pid);
    log_event(msg);

    g = context -> process_graph;
    if (g == NULL) {
        peos_error("handle_resource_event: process graph is null");
        return VM_INTERNAL_ERROR;
    }

    if ((exit_status =  set_act_state_graph(g, action, state)) == VM_DONE) {
        sprintf(msg,"%s DONE %s %d",login_name, context->model, pid);
        log_event(msg);
        delete_entry(context->pid);
  	return exit_status;
    }
    
    if (exit_status == VM_INTERNAL_ERROR) {  
        return exit_status;
    }
                                                                
    return exit_status;
}
コード例 #2
0
ファイル: graph_engine.c プロジェクト: padraigoleary/PEOS
vm_exit_code handle_resource_event(int pid, char *action, vm_resource_event event)
{
    int error;
    Graph g;
    Node n;
    peos_context_t *context = peos_get_context(pid);
    
    g = context -> process_graph;
    if(g == NULL) {
        fprintf(stderr,"Handle Action Error: Unable to find graph");
	return VM_INTERNAL_ERROR;
    }

    n = find_node(g,action);

    if(n != NULL) {
        if(event == REQUIRES_TRUE) {
            if(STATE(n) == ACT_BLOCKED) {
                set_node_state(n, ACT_READY, &error);
                if (error) {
                    return VM_INTERNAL_ERROR;
                }
                return VM_CONTINUE;
            }
            else {
                if((STATE(n) != ACT_READY) && (STATE(n) != ACT_RUN) && (STATE(n) != ACT_PENDING) && (STATE(n) != ACT_SUSPEND) && (STATE(n) != ACT_DONE)) {
                    set_node_state(n, ACT_AVAILABLE, &error); //only raise error when state is set to ready and done
                }
                return VM_CONTINUE;
            }
        }
        else {
            if(event == PROVIDES_TRUE) {
                if((STATE(n) == ACT_PENDING)) {
                    set_node_state(n, ACT_DONE, &error);
                    if (error) {
                        return VM_INTERNAL_ERROR;
                    }
                }
                else {
                    if((STATE(n) != ACT_DONE) && (n -> provides != NULL)) {
                        set_node_state(n, ACT_SATISFIED, &error);
                        if (error) {
                            fprintf(stderr,"Handle Action Error: Unable to find graph");
                            return VM_INTERNAL_ERROR;
                        }
                    }
                }
	        return VM_CONTINUE;
	    }
	    else
	        return VM_INTERNAL_ERROR;
	}
    }
    else
        return VM_INTERNAL_ERROR;
}
コード例 #3
0
ファイル: graph_engine.c プロジェクト: jimiszm/peos
vm_exit_code handle_resource_event(int pid, char *action, vm_resource_event event)
{
    int error;
    Graph g;
    Node n;
    peos_context_t *context = peos_get_context(pid);
    
    g = context -> process_graph;
    if (g == NULL) {
        peos_error("handle_resource_event: process graph is null");
	return VM_INTERNAL_ERROR;
    }

    n = find_node(g,action);

    if (n == NULL) {
	return VM_INTERNAL_ERROR;
    } 

    if (event == REQUIRES_TRUE) {
	if (STATE(n) == ACT_BLOCKED) {
	    set_node_state(n, ACT_READY, &error);
	    if (error) {
		return VM_INTERNAL_ERROR;
	    }
	} else {
	    if ((STATE(n) != ACT_READY) && (STATE(n) != ACT_RUN) && (STATE(n) != ACT_PENDING) && (STATE(n) != ACT_SUSPEND) && (STATE(n) != ACT_DONE)) {
		set_node_state(n, ACT_AVAILABLE, &error); /* only raise error when state is set to ready and done */
	    }
	}
	return VM_CONTINUE;
    } else if (event == PROVIDES_TRUE) {
	if ((STATE(n) == ACT_PENDING)) {
	    set_node_state(n, ACT_DONE, &error);
	    if (error) {
		return VM_INTERNAL_ERROR;
	    }
	} else if ((STATE(n) != ACT_DONE) && (n -> provides != NULL)) {
	    set_node_state(n, ACT_SATISFIED, &error);
	    if (error) {
		return VM_INTERNAL_ERROR;
	    }
	}
	return VM_CONTINUE;
    } else {
	peos_error("handle_resource_event: unknown event %d", event);
	return VM_INTERNAL_ERROR;
    }

}
コード例 #4
0
ファイル: graph_engine.c プロジェクト: jimiszm/peos
vm_act_state get_act_state_graph(int pid, char *act_name) 
{
    Node n;
    Graph g;
    peos_context_t *context = peos_get_context(pid);
    if (context != NULL) {
        g = context->process_graph;
        n = find_node(g, act_name);
	if (n != NULL) {
            return STATE(n);
	}
	else 
	    return -1;
    }
    else
        return -1;
}
コード例 #5
0
ファイル: graph_engine.c プロジェクト: jimiszm/peos
int is_provides_true(Node n) {
    int i;
    int num_resources = 0;
    peos_resource_t* resources;
    peos_resource_t* proc_resources;
    peos_context_t* context = peos_get_context(PID(n));
    resources = get_resource_list_action_provides(PID(n), n->name, &num_resources);
    if (context && context->num_resources > 0) {
        proc_resources = (peos_resource_t *) calloc(context->num_resources, sizeof(peos_resource_t));
       for (i = 0; i < context->num_resources; i++) {
            strcpy(proc_resources[i].name, context->resources[i].name);
         strcpy(proc_resources[i].value, context->resources[i].value);
       }
       eval_resource_list(&proc_resources, context->num_resources);
       fill_resource_list_value(proc_resources, context->num_resources, &resources, num_resources);
    }
    return eval_predicate(resources, num_resources, n->provides);
}
コード例 #6
0
ファイル: graph_engine.c プロジェクト: jimiszm/peos
/* this function was earlier called handle_resource_change */
vm_exit_code update_process_state(int pid) {
    Graph g;
    Node n;
    int result;

    peos_context_t *context = peos_get_context(pid);

    if (context == NULL) {
        peos_error("update_process_state: cannot get context for pid=%d", pid);
        return VM_INTERNAL_ERROR;
    }

    g = context -> process_graph;

    if (g == NULL) {
        peos_error("update_process_state: cannot get graph for pid=%d", pid);
        return VM_INTERNAL_ERROR;
    }

    for (n = g->source->next; n != NULL; n = n->next) {
        if (n->type == ACTION) {
            result = is_requires_true(n);
            if (result == -1)
                return VM_INTERNAL_ERROR;
            if (result) {
                if (handle_resource_event(pid, n->name, REQUIRES_TRUE) == VM_INTERNAL_ERROR) {
                    return VM_INTERNAL_ERROR;
                }
            }
            result = is_provides_true(n);
            if (result == -1)
                return VM_INTERNAL_ERROR;
            if (result) {
                if (handle_resource_event(pid, n->name, PROVIDES_TRUE) == VM_INTERNAL_ERROR) {
                    return VM_INTERNAL_ERROR;
                }
            }
        }
    }
    return VM_CONTINUE;
}
コード例 #7
0
ファイル: graph_engine.c プロジェクト: padraigoleary/PEOS
vm_exit_code update_process_state(int pid) {
    Graph g;
    Node n;
    int result;

    peos_context_t *context = peos_get_context(pid);

    if(context == NULL) {
        fprintf(stderr, "Handle Resource Change: Cannot Get Context\n");
        return VM_INTERNAL_ERROR;
    }

    g = context -> process_graph;

    if(g == NULL) {
        fprintf(stderr, "Handle Resource Change Error: Cannot Get Graph\n");
        return VM_INTERNAL_ERROR;
    }

    for(n = g->source->next; n != NULL; n = n->next) {
        if(n->type == ACTION) {
            result = is_requires_true(n);
            if (result == -1)
                return VM_INTERNAL_ERROR;
            if (result) {
                if(handle_resource_event(pid, n->name, REQUIRES_TRUE) == VM_INTERNAL_ERROR) {
                    return VM_INTERNAL_ERROR;
                }
            }
            result = is_provides_true(n);
            if (result == -1)
                return VM_INTERNAL_ERROR;
            if (result) {
                if(handle_resource_event(pid, n->name, PROVIDES_TRUE) == VM_INTERNAL_ERROR) {
                    return VM_INTERNAL_ERROR;
                }
            }
        }
    }
    return VM_CONTINUE;
}