libmobject-store.c 1.89 KB
Newer Older
1 2 3 4 5 6
/*
 * (C) 2017 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

7
#include "mobject-store-config.h"
8 9

#include <stdio.h>
10
#include <stdlib.h>
11 12
#include <assert.h>

13 14 15
#include <margo.h>
#include <ssg.h>

16
#include "libmobject-store.h"
17

18 19 20
#define MOBJECT_CLUSTER_FILE_ENV "MOBJECT_CLUSTER_FILE"

typedef struct mobject_store_handle
21
{
22 23 24
    ssg_group_id_t gid;
} mobject_store_handle_t;

25

26
int mobject_store_create(mobject_store_t *cluster, const char * const id)
27
{
28 29 30 31
    mobject_store_handle_t *cluster_handle;
    char *cluster_file;
    int ret;

32 33 34 35 36
    (void)id; /* XXX: id unused in mobject */

    /* allocate a new cluster handle and set some fields */
    cluster_handle = malloc(sizeof(*cluster_handle));
    if (!cluster_handle)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
        return -1;
    memset(cluster_handle, 0, sizeof(cluster_handle));

    /* use env variable to determine how to connect to the cluster */
    /* NOTE: this is the _only_ method for specifying a cluster for now... */
    cluster_file = getenv(MOBJECT_CLUSTER_FILE_ENV);
    if (!cluster_file)
    {
        fprintf(stderr, "Error: %s env variable must point to mobject cluster file\n",
            MOBJECT_CLUSTER_FILE_ENV);
        return -1;
    }

    ret = ssg_group_id_load(cluster_file, &cluster_handle->gid);
    if (ret != 0)
    {
        fprintf(stderr, "Error: Unable to load mobject cluster info from file %s\n",
            cluster_file);
        return -1;
    }
57 58 59

    /* set the returned cluster handle */
    *cluster = cluster_handle;
60

61
    return 0;
62 63 64 65
}

int mobject_store_connect(mobject_store_t cluster)
{
66
    /* TODO ssg attach to mobject cluster group id */
67 68

    return 0;
69 70
}

71
void mobject_store_shutdown(mobject_store_t cluster)
72
{
73 74
    mobject_store_handle_t *cluster_handle =
        (mobject_store_handle_t *)cluster;
75 76
    assert(cluster_handle != NULL);

77
    /* TODO ssg detatch from mobject cluster group id. free gid? */
78 79

    free(cluster_handle);
80

81
    return;
82
}