/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: include/sgx/core/threading/callback.hpp

*/

#ifndef SGX_CORE_THREADING_CALLBACK_HPP
#define SGX_CORE_THREADING_CALLBACK_HPP	1

class CSGXCallback;
typedef tMEM_SIZE (*cbFunctionPtr)(CSGXCallback *, tMEM_SIZE result);

class CSGXCallback {
public:
	cbFunctionPtr		m_pFunction;
	tMEM_SIZE			m_Data;
	tMEM_SIZE			m_UserData;
	sgxCPU				*m_pCPU;

	CSGXCallback(cbFunctionPtr ptr, tMEM_SIZE data=0, tMEM_SIZE userdata=0, sgxCPU *cpu= NULL) {
		m_pFunction = ptr;
		m_Data = data;
		m_UserData = userdata;
		m_pCPU = cpu;
	}

	tMEM_SIZE call(tMEM_SIZE resultData=0) {
		if (m_pFunction) {
			// TODO: handle m_pCPU correctly.
			return (*m_pFunction)(this, resultData);
		}
		return 0;
	}
};


#endif /* SGX_CORE_THREADING_CALLBACK_HPP */
