#ifndef _WORKER_HPP_
#define _WORKER_HPP_
#include <ev++.h>

struct task
{
	uint32_t m_cmd_code;
	uint32_t m_hash_id;
	char     m_d[1];

	void destroy()
	{
		free(this);
	}

	template<typename T> const T&body()const
	{
		const void*x=&m_d[0];
		return *(T*)x;
	}

	template<typename T> T&body()
	{
		void*x=&m_d[0];
		return *(T*)x;
	}

	static size_t align(size_t n)
	{
		return (n+31)&~0x1F;
	}

	template<typename T> static task*alloc()
	{
		return (task*)malloc(align(sizeof(T)+sizeof(task)));
	}
};

struct worker
{
	virtual void stop()=0;
	virtual void request(task*tk)=0;

	static worker*instance();
};

#endif

