return_type fsClose(const int nparams, arg_type *a) {
    if (nparams != 1) {
        r.return_val = set_error(EINVAL);
        r.return_size = sizeof(int);
        r.in_error = 1;
        return r;
    } 

    int resource_id = *(int *)a->arg_val;

    int close_result = close(resource_id);

    if (close_result < 0) {
        r.return_val = (void *) set_error(EBUSY);
        r.return_size = sizeof(int);
        r.in_error = 1;
        return r;
    }

    int * resource_removed = malloc(sizeof(int));
    *resource_removed = remove_resource(resource_id);

    if (*resource_removed == 1) {
        r.return_val = (void *) resource_removed;
        r.return_size = sizeof(int);
        r.in_error = 0;
    } else {
        r.return_val = set_error(EBUSY);
        r.return_size = sizeof(int);
        r.in_error = 1;
    }
    return r;
}
bunsan::dcs::hub_interfaces::xmlrpc::xmlrpc(const boost::property_tree::ptree &config, const hub_ptr &hub__):
    hub_(hub__), port(config.get<unsigned int>("server.port")), registry(new xmlrpc_c::registry)
{
    xmlrpc_c::methodPtr
        add_machine(new method_add_machine(hub_)),
        set_capacity(new method_set_capacity(hub_)),
        remove_machine(new method_remove_machine(hub_)),
        clear(new method_clear(hub_)),
        add_resource(new method_add_resource(hub_)),
        set_resource_uri(new method_set_resource_uri(hub_)),
        remove_resource(new method_remove_resource(hub_)),
        select_resource(new method_select_resource(hub_));
    registry->addMethod("add_machine", add_machine);
    registry->addMethod("set_capacity", set_capacity);
    registry->addMethod("remove_machine", remove_machine);
    registry->addMethod("clear", clear);
    registry->addMethod("add_resource", add_resource);
    registry->addMethod("set_resource_uri", set_resource_uri);
    registry->addMethod("remove_resource", remove_resource);
    registry->addMethod("select_resource", select_resource);
}
size_t RottenFoodEvent::normal() {
  const size_t LOST_FOOD = 5;
  remove_resource(RI_FOOD, LOST_FOOD);
  return EO_NORMAL;
}
Exemple #4
0
int resman_poll(struct resman *rman)
{
	int i, num_res;
	unsigned long start_time, timeslice;

	/* first check all the resources to see if anyone is pending deletion */
	num_res = dynarr_size(rman->res);
	for(i=0; i<num_res; i++) {
		struct resource *res = rman->res[i];
		if(!res) {
			continue;
		}

		/* also make sure we're it's off the queues/workers before deleting */
		if(res->delete_pending && !res->pending) {
			if(rman->destroy_func) {
				rman->destroy_func(i, rman->destroy_func_cls);
			}
			remove_resource(rman, i);
		}
	}


	/* then check for modified files */
	resman_check_watch(rman);

#if !defined(WIN32) && !defined(__WIN32__)
	/* empty the thread pool event pipe (fd is nonblocking) */
	while(read(rman->tpool_wait_fd, &i, sizeof i) > 0);
#endif

	if(!rman->done_func) {
		return 0;	/* no done callback; there's no point in checking anything */
	}

	start_time = resman_get_time_msec();

	for(i=0; i<num_res; i++) {
		struct resource *res = rman->res[i];
		if(!res) {
			continue;
		}

		pthread_mutex_lock(&res->lock);
		if(!res->done_pending) {
			int reload = res->reload_timeout && res->reload_timeout <= start_time;
			pthread_mutex_unlock(&res->lock);
			if(reload) {
				printf("file \"%s\" modified, delayed reload\n", res->name);
				res->reload_timeout = 0;
				resman_reload(rman, res);
			}
			continue;
		}

		/* so a done callback *is* pending... */
		res->done_pending = 0;
		if(rman->done_func(i, rman->done_func_cls) == -1) {
			/* done-func returned -1, so let's remove the resource
			 * but only if this was the first load. Otherwise keep it
			 * around in case it gets valid again...
			 */
			if(res->num_loads == 0) {
				pthread_mutex_unlock(&res->lock);
				remove_resource(rman, i);
				continue;
			}
		}
		res->num_loads++;

		resman_start_watch(rman, res);	/* start watching the file for modifications */
		pthread_mutex_unlock(&res->lock);

		/* poll will be called with a high frequency anyway, so let's not spend
		 * too much time on done callbacks each time through it
		 */
		timeslice = rman->opt[RESMAN_OPT_TIMESLICE];
		if(timeslice > 0 && resman_get_time_msec() - start_time > timeslice) {
			break;
		}
	}
	return 0;
}
size_t RottenFoodEvent::success() {
  const size_t LOST_FOOD = 0;
  remove_resource(RI_FOOD, LOST_FOOD);
  return EO_SUCCESS;
}