remi-client.cpp 2.45 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1
#include <thallium.hpp>
Matthieu Dorier's avatar
Matthieu Dorier committed
2
#include "remi/remi-client.h"
Matthieu Dorier's avatar
Matthieu Dorier committed
3
#include "remi-fileset.hpp"
4

Matthieu Dorier's avatar
Matthieu Dorier committed
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
namespace tl = thallium;

struct remi_client {

    margo_instance_id    m_mid = MARGO_INSTANCE_NULL;
    tl::engine*          m_engine = nullptr;
    uint64_t             m_num_providers = 0;
    tl::remote_procedure m_migrate_rpc;

    remi_client(tl::engine* e)
    : m_engine(e)
    , m_migrate_rpc(m_engine->define("remi_migrate")) {}

};

struct remi_provider_handle : public tl::provider_handle {

    remi_client_t m_client    = nullptr;
    uint64_t      m_ref_count = 0;
    
    template<typename ... Args>
    remi_provider_handle(Args&&... args)
    : tl::provider_handle(std::forward<Args>(args)...) {}
};

30 31
extern "C" int remi_client_init(margo_instance_id mid, remi_client_t* client)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
32 33 34 35 36
    auto theEngine           = new tl::engine(mid, THALLIUM_CLIENT_MODE);
    remi_client_t theClient  = new remi_client(theEngine);
    theClient->m_mid         = mid;
    *client = theClient;
    return REMI_SUCCESS;
37 38 39 40
}

extern "C" int remi_client_finalize(remi_client_t client)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
41 42 43 44 45
    if(client == REMI_CLIENT_NULL)
        return REMI_SUCCESS;
    delete client->m_engine;
    delete client;
    return REMI_SUCCESS;
46 47 48 49 50 51 52 53
}

extern "C" int remi_provider_handle_create(
        remi_client_t client,
        hg_addr_t addr,
        uint16_t provider_id,
        remi_provider_handle_t* handle)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
54 55 56 57 58 59 60 61
    if(client == REMI_CLIENT_NULL)
        return REMI_ERR_INVALID_ARG;
    auto theHandle = new remi_provider_handle(
            tl::endpoint(*(client->m_engine), addr, false), provider_id);
    theHandle->m_client = client;
    *handle = theHandle;
    client->m_num_providers += 1;
    return REMI_SUCCESS;
62 63 64 65
}

extern "C" int remi_provider_handle_ref_incr(remi_provider_handle_t handle)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
66 67 68 69
    if(handle == REMI_PROVIDER_HANDLE_NULL)
        return REMI_ERR_INVALID_ARG;
    handle->m_ref_count += 1;
    return REMI_SUCCESS;
70 71 72 73
}

extern "C" int remi_provider_handle_release(remi_provider_handle_t handle)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
74 75 76 77 78 79 80 81
    if(handle == REMI_PROVIDER_HANDLE_NULL)
        return REMI_SUCCESS;
    handle->m_ref_count -= 1;
    if(handle->m_ref_count == 0) {
        handle->m_client->m_num_providers -= 1;
        delete handle;
    }
    return REMI_SUCCESS;
82 83 84 85
}

extern "C" int remi_shutdown_service(remi_client_t client, hg_addr_t addr)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
86
    return margo_shutdown_remote_instance(client->m_mid, addr);
87
}
Matthieu Dorier's avatar
Matthieu Dorier committed
88 89 90 91 92 93

extern "C" int remi_fileset_migrate(
        remi_provider_handle_t handle,
        remi_fileset_t fileset,
        int flag)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
94
    // TODO
Matthieu Dorier's avatar
Matthieu Dorier committed
95
}