1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /*
3  *  (C) 2008 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 
7 #ifndef COMMON_H_INCLUDED
8 #define COMMON_H_INCLUDED
9 
10 #include "hydra.h"
11 
12 /* Generic definitions */
13 #define PMI_MAXKEYLEN    (64)   /* max length of key in keyval space */
14 #define PMI_MAXVALLEN    (1024) /* max length of value in keyval space */
15 #define PMI_MAXKVSLEN    (256)  /* max length of various names */
16 
17 struct HYD_pmcd_pmi_kvs_pair {
18     char key[PMI_MAXKEYLEN];
19     char val[PMI_MAXVALLEN];
20     struct HYD_pmcd_pmi_kvs_pair *next;
21 };
22 
23 struct HYD_pmcd_pmi_kvs {
24     char kvs_name[PMI_MAXKVSLEN];       /* Name of this kvs */
25     struct HYD_pmcd_pmi_kvs_pair *key_pair;
26 };
27 
28 struct HYD_pmcd_hdr {
29     /* The set of commands supported */
30     enum HYD_pmcd_cmd {
31         INVALID_CMD = 0,        /* for sanity testing */
32 
33         /* UI to proxy commands */
34         PROC_INFO,
35         CKPOINT,
36         PMI_RESPONSE,
37         SIGNAL,
38         STDIN,
39 
40         /* Proxy to UI commands */
41         PID_LIST,
42         EXIT_STATUS,
43         PMI_CMD,
44         STDOUT,
45         STDERR,
46         PROCESS_TERMINATED
47     } cmd;
48 
49     /* Generic */
50     int buflen;
51 
52     /* PMI_CMD */
53     int pid;                    /* ID of the requesting process */
54     int pmi_version;            /* PMI version */
55 
56     /* STDOUT/STDERR */
57     int pgid;
58     int proxy_id;
59     int rank;
60 
61     /* SIGNAL */
62     int signum;
63 };
64 
65 struct HYD_pmcd_token {
66     char *key;
67     char *val;
68 };
69 
70 void HYD_pmcd_init_header(struct HYD_pmcd_hdr *hdr);
71 HYD_status HYD_pmcd_pmi_parse_pmi_cmd(char *buf, int pmi_version, char **pmi_cmd,
72                                       char *args[]);
73 HYD_status HYD_pmcd_pmi_args_to_tokens(char *args[], struct HYD_pmcd_token **tokens,
74                                        int *count);
75 void HYD_pmcd_pmi_free_tokens(struct HYD_pmcd_token *tokens, int token_count);
76 char *HYD_pmcd_pmi_find_token_keyval(struct HYD_pmcd_token *tokens, int count,
77                                      const char *key);
78 HYD_status HYD_pmcd_pmi_allocate_kvs(struct HYD_pmcd_pmi_kvs **kvs, int pgid);
79 void HYD_pmcd_free_pmi_kvs_list(struct HYD_pmcd_pmi_kvs *kvs_list);
80 HYD_status HYD_pmcd_pmi_add_kvs(const char *key, char *val, struct HYD_pmcd_pmi_kvs *kvs,
81                                 int *ret);
82 
83 #endif /* COMMON_H_INCLUDED */
84