request.hpp 1.02 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#ifndef __THALLIUM_REQUEST_HPP
#define __THALLIUM_REQUEST_HPP

#include <margo.h>

namespace thallium {

class margo_engine;

class request {

	friend class margo_engine;

private:

	hg_handle_t m_handle;

	request(hg_handle_t h)
	: m_handle(h) {}

public:

	request(const request& other)
	: m_handle(other.m_handle) {
		margo_ref_incr(m_handle);
	}

	request(request&& other) 
	: m_handle(other.m_handle) {
		other.m_handle = HG_HANDLE_NULL;
	}

	request& operator=(const request& other) {
		if(m_handle == other.m_handle) return *this;
		margo_destroy(m_handle);
		m_handle = other.m_handle;
		margo_ref_incr(m_handle);
		return *this;
	}

	request& operator=(request&& other) {
		if(m_handle == other.m_handle) return *this;
		margo_destroy(m_handle);
		m_handle = other.m_handle;
		other.m_handle = HG_HANDLE_NULL;
		return *this;
	}

	~request() {
		margo_destroy(m_handle);
	}

	template<typename T>
	void respond(T&& t) {
		// TODO serialize
		if(m_handle != HG_HANDLE_NULL) {
			margo_respond(m_handle, nullptr);
		}
	}
};

}

#endif