/*
 * eventflag.h
 */

#ifndef EVENTFLAG_H_
#define EVENTFLAG_H_

#include <pthread.h>

#include "HA_Object.h"

#ifdef __cplusplus
namespace HARKAndroid {

class EventFlag : public HAObject {

private:

	bool valid;
	const bool autoreset;
	unsigned int flag;
	::pthread_cond_t  cond;
	::pthread_mutex_t mutex;

	int init(const bool autoreset);

public:

    static const unsigned int default_pattern = 1;

	EventFlag(const EventFlag&);
	explicit EventFlag(const bool argautoreset = true);
	virtual ~EventFlag();
	EventFlag &operator = (const EventFlag &);


	bool isValid() const {return(valid);}

	int Wait(const unsigned int pattern = default_pattern);
	int TimedWait(const unsigned int wait_ms, const unsigned int pattern = default_pattern);
	int Set(const unsigned int pattern = default_pattern);
	int Reset(const unsigned int pattern = default_pattern);

};

} // end of namespace

#endif /* __cplusplus */

#endif /* EVENTFLAG_H_ */
