////////////////////////////////////////////////////////////
//
//     	Declaration of classes
//	AProcessAttributes, AScheduleRules
// 	see rtsched (2)
//
//      Copyright 2001 
//
////////////////////////////////////////////////////////////

#ifndef __PROCESS_H__
#define __PROCESS_H__


typedef void (*EXEC_FAIL_CALLBACK)(void * arg);
	

	// AProcessAttributes
	
class AProcessAttributes
{
public:
	int status;
	
	// process_id is zero - calling process
	AProcessAttributes(pid_t process_id=0):
	policy(0),priority(0),child_policy(0),child_priority(0)
	{ status=set(process_id);}
	
	int set(pid_t process_id);
	
	int get_pid_t(pid_t& z)const
	{ if(status) return 1; z=id; return 0;}
		
	int get_schedule_policy(int& z)const
	{ if(status) return 1; z=policy; return 0;}
	 
	int get_priority(int& z)const
	{ if(status) return 1; z=priority; return 0;}
	
	int get_child_schedule_policy(int& z)const
	{ if(status) return 1; z=child_policy; return 0;}
	 
	int get_child_priority(int& z)const
	{ if(status) return 1; z=child_priority; return 0;}
	
	
	// in a multithreaded process
	// affects a child, does not affect threads of calling process
	// a calling process has to have appropriate privileges to call this
	int set_child_priority(int priority);
	int set_child(int policy,int priority);
		
private:
	pid_t id;
	int policy, priority,
	    child_policy, child_priority;	
};



	// AScheduleRules

class AScheduleRules
{
public:
	int status;
	
	AScheduleRules(); // calling thread schedule
	
	AScheduleRules(int policy_code)
	{ status=set_policy(policy_code);}
	
	int set_policy(int policy);
	
	// direction > 0 - larger value corresponds to higher priority
	int priority_range(int& min_priority, int& max_priority, int& direction);
	int priority_above(int& new_priority, int base_priority);
	int priority_below(int& new_priority, int base_priority);
	
private:
	int policy;
};

	// functions

// call from the main thread
int AMainThreadPriority(int& priority);

// fork
// if original_process, then attributes are of a child
// otherwise - calling process attributes with pid zero
int clone_process(bool& original_process, AProcessAttributes& attributes);


#endif