bake-bedrock-module.c 4.93 KB
Newer Older
1
2
3
4
5
/*
 * (C) 2020 The University of Chicago
 *
 * See COPYRIGHT in top-level directory.
 */
6

7
#include <string.h>
8
9
#include <bedrock/module.h>
#include <abt-io.h>
10

11
#include "bake-server.h"
12
#include "bake-client.h"
13
#include "bake-macros.h"
14

15
16
17
static int bake_register_provider(bedrock_args_t             args,
                                  bedrock_module_provider_t* provider)
{
18
19
20
    int                            ret;
    struct bake_provider_init_info bpargs = {0};
    margo_instance_id              mid = bedrock_args_get_margo_instance(args);
21
22
23
24
    uint16_t    provider_id            = bedrock_args_get_provider_id(args);
    ABT_pool    pool                   = bedrock_args_get_pool(args);
    const char* config                 = bedrock_args_get_config(args);
    const char* name                   = bedrock_args_get_name(args);
25

26
27
28
29
30
31
32
33
34
35
36
    if (bedrock_args_get_num_dependencies(args, "abt_io")) {
        bpargs.aid = bedrock_args_get_dependency(args, "abt_io", 0);
    } else {
        bpargs.aid = ABT_IO_INSTANCE_NULL;
    }

    if (bedrock_args_get_num_dependencies(args, "remi_provider")) {
        bpargs.remi_provider
            = bedrock_args_get_dependency(args, "remi_provider", 0);
    } else {
        bpargs.remi_provider = NULL;
37
38
39
40
41
42
43
    }

    if (bedrock_args_get_num_dependencies(args, "remi_client")) {
        bpargs.remi_client
            = bedrock_args_get_dependency(args, "remi_client", 0);
    } else {
        bpargs.remi_client = NULL;
44
    }
45

Philip Carns's avatar
Philip Carns committed
46
    BAKE_TRACE(mid, "bake_register_provider()");
47
48
49
50
51
52
53
    BAKE_TRACE(mid, " -> mid           = %p", (void*)mid);
    BAKE_TRACE(mid, " -> provider id   = %d", provider_id);
    BAKE_TRACE(mid, " -> pool          = %p", (void*)pool);
    BAKE_TRACE(mid, " -> config        = %s", config);
    BAKE_TRACE(mid, " -> name          = %s", name);
    BAKE_TRACE(mid, " -> abt_io        = %p", bpargs.aid);
    BAKE_TRACE(mid, " -> remi_provider = %p", bpargs.remi_provider);
54
    BAKE_TRACE(mid, " -> remi_client   = %p", bpargs.remi_client);
55
56
57

    bpargs.json_config = config;
    ret                = bake_provider_register(mid, provider_id, &bpargs,
Philip Carns's avatar
Philip Carns committed
58
                                 (bake_provider_t*)provider);
59
60
    if (ret < 0) return (-1);

61
62
63
64
65
    return BEDROCK_SUCCESS;
}

static int bake_deregister_provider(bedrock_module_provider_t provider)
{
66
67
    int ret;

68
    ret = bake_provider_deregister(provider);
69
70
    if (ret < 0) return (-1);

71
72
73
74
75
    return BEDROCK_SUCCESS;
}

static char* bake_get_provider_config(bedrock_module_provider_t provider)
{
76
    return (bake_provider_get_config(provider));
77
78
}

79
static int bake_init_client(bedrock_args_t           args,
80
81
                            bedrock_module_client_t* client)
{
82
83
    int ret;

84
    margo_instance_id mid = bedrock_args_get_margo_instance(args);
Philip Carns's avatar
Philip Carns committed
85
    BAKE_TRACE(mid, "bake_init_client()");
86
87
88
89

    ret = bake_client_init(mid, (bake_client_t*)client);
    if (ret < 0) return (-1);

90
91
92
93
94
    return BEDROCK_SUCCESS;
}

static int bake_finalize_client(bedrock_module_client_t client)
{
95
96
97
98
99
    int ret;

    ret = bake_client_finalize(client);
    if (ret < 0) return (-1);

100
101
102
    return BEDROCK_SUCCESS;
}

103
104
105
106
107
static char* bake_get_client_config(bedrock_module_client_t client)
{
    return strdup("{}");
}

108
109
110
111
112
static int bake_create_provider_handle(bedrock_module_client_t client,
                                       hg_addr_t               address,
                                       uint16_t                provider_id,
                                       bedrock_module_provider_handle_t* ph)
{
113
114
115
116
117
118
    int ret;

    ret = bake_provider_handle_create(client, address, provider_id,
                                      (bake_provider_handle_t*)ph);
    if (ret < 0) return (-1);

119
120
121
122
123
    return BEDROCK_SUCCESS;
}

static int bake_destroy_provider_handle(bedrock_module_provider_handle_t ph)
{
124
125
126
127
128
    int ret;

    ret = bake_provider_handle_release(ph);
    if (ret < 0) return (-1);

129
130
131
    return BEDROCK_SUCCESS;
}

132
133
134
135
136
/* an optional abt-io dependency can be specified
 * - only used by some backends (the file one, specifically)
 * - if needed by not provided as a dependency, then the backend will create
 *   one of it's own implicitly
 */
137
138
139
140
141
142
143
struct bedrock_dependency bake_provider_deps[4]
    = {{"abt_io", "abt_io", 0},
       {"remi_provider", "remi", 0},
       {"remi_client", "remi", 0},
       BEDROCK_NO_MORE_DEPENDENCIES};

struct bedrock_dependency bake_client_deps[1] = {BEDROCK_NO_MORE_DEPENDENCIES};
Philip Carns's avatar
Philip Carns committed
144

145
146
147
148
149
150
static struct bedrock_module bake
    = {.register_provider       = bake_register_provider,
       .deregister_provider     = bake_deregister_provider,
       .get_provider_config     = bake_get_provider_config,
       .init_client             = bake_init_client,
       .finalize_client         = bake_finalize_client,
151
       .get_client_config       = bake_get_client_config,
152
153
       .create_provider_handle  = bake_create_provider_handle,
       .destroy_provider_handle = bake_destroy_provider_handle,
154
155
       .provider_dependencies   = bake_provider_deps,
       .client_dependencies     = bake_client_deps};
156
157

BEDROCK_REGISTER_MODULE(bake, bake)