svc1.c 3.58 KB
Newer Older
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <assert.h>
#include "svc1.h"

static void svc1_do_thing_ult(hg_handle_t handle)
{
    hg_return_t hret;
    svc1_do_thing_out_t out;
    svc1_do_thing_in_t in;
    int ret;
    hg_size_t size;
    void *buffer;
    hg_bulk_t bulk_handle;
    struct hg_info *hgi;
    margo_instance_id mid;

    ret = HG_Get_input(handle, &in);
    assert(ret == HG_SUCCESS);

    printf("Got RPC request with input_val: %d\n", in.input_val);
    out.ret = 0;

    /* set up target buffer for bulk transfer */
    size = 512;
    buffer = calloc(1, 512);
    assert(buffer);

    /* register local target buffer for bulk access */
    hgi = HG_Get_info(handle);
    assert(hgi);
    ret = HG_Bulk_create(hgi->hg_class, 1, &buffer,
        &size, HG_BULK_WRITE_ONLY, &bulk_handle);
    assert(ret == 0);

    mid = margo_hg_class_to_instance(hgi->hg_class);

    /* do bulk transfer from client to server */
    ret = margo_bulk_transfer(mid, HG_BULK_PULL,
        hgi->addr, in.bulk_handle, 0,
        bulk_handle, 0, size);
    assert(ret == 0);

    HG_Free_input(handle, &in);

    hret = HG_Respond(handle, NULL, NULL, &out);
    assert(hret == HG_SUCCESS);

    HG_Bulk_free(bulk_handle);
    HG_Destroy(handle);
    free(buffer);

    return;
}
DEFINE_MARGO_RPC_HANDLER(svc1_do_thing_ult)

static void svc1_do_other_thing_ult(hg_handle_t handle)
{
    hg_return_t hret;
    svc1_do_other_thing_out_t out;
    svc1_do_other_thing_in_t in;
    int ret;
    hg_size_t size;
    void *buffer;
    hg_bulk_t bulk_handle;
    struct hg_info *hgi;
    margo_instance_id mid;

    ret = HG_Get_input(handle, &in);
    assert(ret == HG_SUCCESS);

    printf("Got RPC request with input_val: %d\n", in.input_val);
    out.ret = 0;

    /* set up target buffer for bulk transfer */
    size = 512;
    buffer = calloc(1, 512);
    assert(buffer);

    /* register local target buffer for bulk access */
    hgi = HG_Get_info(handle);
    assert(hgi);
    ret = HG_Bulk_create(hgi->hg_class, 1, &buffer,
        &size, HG_BULK_WRITE_ONLY, &bulk_handle);
    assert(ret == 0);

    mid = margo_hg_class_to_instance(hgi->hg_class);

    /* do bulk transfer from client to server */
    ret = margo_bulk_transfer(mid, HG_BULK_PULL,
        hgi->addr, in.bulk_handle, 0,
        bulk_handle, 0, size);
    assert(ret == 0);

    HG_Free_input(handle, &in);

    hret = HG_Respond(handle, NULL, NULL, &out);
    assert(hret == HG_SUCCESS);

    HG_Bulk_free(bulk_handle);
    HG_Destroy(handle);
    free(buffer);

    return;
}
DEFINE_MARGO_RPC_HANDLER(svc1_do_other_thing_ult)

int svc1_register(margo_instance_id mid, ABT_pool pool, uint32_t mplex_id)
{
    hg_return_t hret;
    hg_id_t id;
    hg_bool_t flag;
Philip Carns's avatar
Philip Carns committed
117 118 119 120
    int ret;

    /* TODO: the following, for each function */
    /* TODO: this should be a macro really */
121 122 123 124 125 126

    hret = HG_Registered_name(margo_get_class(mid), "svc1_do_thing", &id, &flag);
    if(hret != HG_SUCCESS)
    {
        return(-1);
    }
Philip Carns's avatar
Philip Carns committed
127 128 129 130 131 132 133 134 135
    if(!flag)
    {
        id = MERCURY_REGISTER(margo_get_class(mid), "svc1_do_thing", svc1_do_thing_in_t, svc1_do_thing_out_t, svc1_do_thing_ult_handler);
    }
    ret = margo_register_mplex(mid, id, mplex_id, pool);
    if(ret < 0)
    {
        return(ret);
    }
136
    
Philip Carns's avatar
Philip Carns committed
137
    /* TODO: 
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
     * - elsewhere:
     *   - new variant of DEFINE_MARGO_RPC_HANDLER that:
     *     - looks up registered margo thing
     *     - creates thread targeting pool
     */

    return(-1);
}

void svc1_deregister(margo_instance_id mid, ABT_pool pool, uint32_t mplex_id)
{
    /* TODO: undo what was done in svc1_register() */
    return;
}