Commit 947951cb authored by Philip Carns's avatar Philip Carns

added another example service

parent 4c22bfb6
......@@ -2,4 +2,5 @@ noinst_PROGRAMS += examples/multiplex/margo-example-mp-server
examples_multiplex_margo_example_mp_server_SOURCES = \
examples/multiplex/margo-example-mp-server.c \
examples/multiplex/svc1.c
examples/multiplex/svc1.c \
examples/multiplex/svc2.c
......@@ -12,6 +12,7 @@
#include <margo.h>
#include "svc1.h"
#include "svc2.h"
/* example server program that starts a skeleton for sub-services within
* this process to register with
......@@ -131,6 +132,9 @@ int main(int argc, char **argv)
mid = margo_init(0, 0, hg_context);
assert(mid);
/* register RPCs and services */
/***************************************/
/* register a shutdown RPC as just a generic handler; not part of a
* multiplexed service
*/
......@@ -153,7 +157,15 @@ int main(int argc, char **argv)
ret = svc1_register(mid, svc1_pool2, 2);
assert(ret == 0);
/* TODO: register svc2 */
/* register svc2, with mplex_id 3, to execute on the default handler pool
* used by Margo
*/
ret = svc2_register(mid, margo_get_handler_pool(mid), 3);
assert(ret == 0);
/* shut things down */
/****************************************/
/* NOTE: there isn't anything else for the server to do at this point
* except wait for itself to be shut down. The
......@@ -164,6 +176,7 @@ int main(int argc, char **argv)
svc1_deregister(mid, margo_get_handler_pool(mid), 1);
svc1_deregister(mid, margo_get_handler_pool(mid), 2);
svc2_deregister(mid, margo_get_handler_pool(mid), 3);
ABT_xstream_join(svc1_xstream2);
ABT_xstream_free(&svc1_xstream2);
......
/*
* (C) 2015 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <assert.h>
#include "svc2.h"
static void svc2_do_thing_ult(hg_handle_t handle)
{
hg_return_t hret;
svc2_do_thing_out_t out;
svc2_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);
/* TODO: print handler name, mplex_id, and pool */
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(svc2_do_thing_ult)
static void svc2_do_other_thing_ult(hg_handle_t handle)
{
hg_return_t hret;
svc2_do_other_thing_out_t out;
svc2_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);
/* TODO: print handler name, mplex_id, and pool */
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(svc2_do_other_thing_ult)
int svc2_register(margo_instance_id mid, ABT_pool pool, uint32_t mplex_id)
{
MARGO_REGISTER(mid, "svc2_do_thing", svc2_do_thing_in_t, svc2_do_thing_out_t, svc2_do_thing_ult_handler, mplex_id, pool);
MARGO_REGISTER(mid, "svc2_do_other_thing", svc2_do_other_thing_in_t, svc2_do_other_thing_out_t, svc2_do_other_thing_ult_handler, mplex_id, pool);
return(0);
}
void svc2_deregister(margo_instance_id mid, ABT_pool pool, uint32_t mplex_id)
{
/* TODO: undo what was done in svc2_register() */
return;
}
/*
* (C) 2015 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __SVC2
#define __SVC2
#include <margo.h>
/* this is an example service that will be registered as a unit on a
* centralized progress engine */
int svc2_register(margo_instance_id mid, ABT_pool pool, uint32_t mplex_id);
void svc2_deregister(margo_instance_id mid, ABT_pool pool, uint32_t mplex_id);
MERCURY_GEN_PROC(svc2_do_thing_out_t, ((int32_t)(ret)))
MERCURY_GEN_PROC(svc2_do_thing_in_t,
((int32_t)(input_val))\
((hg_bulk_t)(bulk_handle)))
DECLARE_MARGO_RPC_HANDLER(svc2_do_thing_ult)
DECLARE_MARGO_RPC_HANDLER(svc2_do_thing_shutdown_ult)
MERCURY_GEN_PROC(svc2_do_other_thing_out_t, ((int32_t)(ret)))
MERCURY_GEN_PROC(svc2_do_other_thing_in_t,
((int32_t)(input_val))\
((hg_bulk_t)(bulk_handle)))
DECLARE_MARGO_RPC_HANDLER(svc2_do_other_thing_ult)
DECLARE_MARGO_RPC_HANDLER(svc2_do_other_thing_shutdown_ult)
#endif /* __SVC2 */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment