#ifndef _LVE_CTL_H_

#define _LVE_CTL_H_

struct liblve;

/**
 * return 1 if lve is available
 * 0 otherwise.
 */
int lve_is_available(void);

/**
 * create lve library instance
 * args 
 * libvlve - pointer to allocated memory to store per instance info
 *           or NULL to return how many memory need for per
 *           instance structure.
 * return codes:
 * > 0, size per instance structure, if liblve == NULL.
 * 0 = if instance is correctly init.
 * < 0, if any error is hit
 */
int lve_instance_init(struct liblve *lve);

/**
 * destroy lve library instance
 * args:
 * lve = fully init liblve instance
 */
int lve_instance_destroy(struct liblve *lve);


/**
 * enter into virutal environment
 * args:
 * lve = fully init liblve instance
 * ve_id = id associated with VE
 * uid = user id to switch, -1 if switch not need.
 * gid = group id to switch, -1 if switch not need.
 * cokkie = pointer to cookie, which returned  if task correctly migrated
 * in VE and used to leave from this VE
 * return codes:
 * 0 = none error, all less zero is errors:
 * -EPERM - don't have permission to call, or called from outside root VE
 * -ENOMEM - don't have memory to allocate new VE
 * -EFAULT - cookie is bad pointer
 */
int lve_enter(struct liblve *lve,
              uint32_t ve_id, int32_t uid,
              int32_t gid, uint32_t *cookie);

/**
 * leave from virtual environment
 * args:
 * lve = fully init liblve instance
 * cookie - pointer to cookie returned from lve_enter
 * return codes:
 * 0 = none error, all less zero is errors:
 * -ESRCH = task not in virutal environment
 * -EFAULT = bad cookie pointer
 * -EINVAL = cookie not match to stored in context
 */
int lve_leave(struct liblve *lve, uint32_t *cookie);

#ifdef LVE_ADMIN
/**
 * set default parameters for new created virtual enviroment.
 * args:
 * cpu - default CPU power, -1 if don't set
 * io - default IO priority, -1 if don't set
 * return codes:
 * 
 */
int lve_set_default(int32_t cpu, int32_t io, int32_t maxentryproc);

/**
 * create custom configured virtual enviroment
 * args:
 * ve_id = id associated with VE
 * return
 * 0 - OK
 * any negative value say error is hit.
 */
int lve_create(uint32_t ve_id);

/**
 * destroy configured virtual environment
 * args:
 * ve_id = id associated with VE
 * return
 * 0 - OK
 * any negative value say error is hit.
 */
int lve_destroy(uint32_t ve_id);

/**
 * adjust parameters for virtual environment
 * args:
 * ve_id = id associated with VE
 * cpu - CPU power, -1 if don't set
 * io - IO priority, -1 if don't set 
 * return
 * 0 - OK
 * any negative value say error is hit.
 */
int lve_setup(uint32_t ve_id, int32_t cpu, int32_t io, int32_t maxentryproc);

/**
 * flush context's from kernel
 * args
 * all == true - is need all context flushed, or need flush 
 *               only default configured
 * return
 * 0 - OK
 * any negative value say error is hit.
 */
int lve_flush(int all);

/**
 * get info about context
 * args
 * ve_id = id associated with VE
 * cpu - pointer to return CPU power.
 * io - pointer to IO priority.
 * return
 * 0 - OK
 * any negative value say error is hit.
 */
int lve_info(uint32_t ve_id, int32_t *cpu, int32_t *io);

#endif

#endif
