This source file includes following definitions.
- notification_fn
- evhandler_reg_callbk
- opcbfunc
- main
   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 #include "pmix_config.h"
  27 #include "pmix_common.h"
  28 
  29 #include <stdio.h>
  30 #include <stdlib.h>
  31 #include <unistd.h>
  32 #include <time.h>
  33 #include <pthread.h>
  34 
  35 #include <pmix_tool.h>
  36 #include "src/mca/base/base.h"
  37 #include "src/mca/pinstalldirs/base/base.h"
  38 #include "src/threads/threads.h"
  39 #include "src/util/cmd_line.h"
  40 #include "src/util/keyval_parse.h"
  41 #include "src/util/show_help.h"
  42 #include "src/runtime/pmix_rte.h"
  43 
  44 typedef struct {
  45     pmix_lock_t lock;
  46     pmix_status_t status;
  47 } mylock_t;
  48 
  49 static pmix_proc_t myproc;
  50 
  51 
  52 
  53 
  54 
  55 
  56 static void notification_fn(size_t evhdlr_registration_id,
  57                             pmix_status_t status,
  58                             const pmix_proc_t *source,
  59                             pmix_info_t info[], size_t ninfo,
  60                             pmix_info_t results[], size_t nresults,
  61                             pmix_event_notification_cbfunc_fn_t cbfunc,
  62                             void *cbdata)
  63 {
  64     
  65     if (NULL != cbfunc) {
  66         cbfunc(PMIX_EVENT_ACTION_COMPLETE, NULL, 0, NULL, NULL, cbdata);
  67     }
  68 }
  69 
  70 
  71 
  72 
  73 
  74 
  75 
  76 
  77 static void evhandler_reg_callbk(pmix_status_t status,
  78                                  size_t evhandler_ref,
  79                                  void *cbdata)
  80 {
  81     mylock_t *lock = (mylock_t*)cbdata;
  82 
  83     if (PMIX_SUCCESS != status) {
  84         fprintf(stderr, "Client %s:%d EVENT HANDLER REGISTRATION FAILED WITH STATUS %d, ref=%lu\n",
  85                    myproc.nspace, myproc.rank, status, (unsigned long)evhandler_ref);
  86     }
  87     lock->status = status;
  88     PMIX_WAKEUP_THREAD(&lock->lock);
  89 }
  90 
  91 
  92 
  93 
  94 typedef struct {
  95     bool help;
  96     bool verbose;
  97     pid_t pid;
  98     int code;
  99     int range;
 100 } pmix_pevent_globals_t;
 101 
 102 pmix_pevent_globals_t pmix_pevent_globals = {0};
 103 
 104 pmix_cmd_line_init_t cmd_line_opts[] = {
 105     { NULL,
 106       'h', NULL, "help",
 107       0,
 108       &pmix_pevent_globals.help, PMIX_CMD_LINE_TYPE_BOOL,
 109       "This help message" },
 110 
 111     { NULL,
 112       'v', NULL, "verbose",
 113       0,
 114       &pmix_pevent_globals.verbose, PMIX_CMD_LINE_TYPE_BOOL,
 115       "Be Verbose" },
 116 
 117     { NULL,
 118       'p', NULL, "pid",
 119       1,
 120       &pmix_pevent_globals.pid, PMIX_CMD_LINE_TYPE_INT,
 121       "Specify starter pid" },
 122 
 123     { NULL,
 124       'e', NULL, "event",
 125       0,
 126       &pmix_pevent_globals.code, PMIX_CMD_LINE_TYPE_INT,
 127       "Status code of event to be sent" },
 128 
 129     { NULL,
 130       'r', NULL, "range",
 131       0,
 132       &pmix_pevent_globals.range, PMIX_CMD_LINE_TYPE_INT,
 133       "Range of event to be sent" },
 134 
 135     
 136     { NULL,
 137       '\0', NULL, NULL,
 138       0,
 139       NULL, PMIX_CMD_LINE_TYPE_NULL,
 140       NULL }
 141 };
 142 
 143 static void opcbfunc(pmix_status_t status, void *cbdata)
 144 {
 145     mylock_t *lock = (mylock_t*)cbdata;
 146 
 147     lock->status = status;
 148     PMIX_WAKEUP_THREAD(&lock->lock);
 149 }
 150 
 151 int main(int argc, char **argv)
 152 {
 153     pmix_status_t rc;
 154     pmix_info_t *info;
 155     mylock_t mylock;
 156     pmix_status_t status;
 157     pmix_data_range_t range;
 158     pmix_cmd_line_t cmd_line;
 159 
 160     
 161 
 162     signal(SIGPIPE, SIG_IGN);
 163 
 164     
 165     if (!pmix_output_init()) {
 166         return PMIX_ERROR;
 167     }
 168 
 169     
 170     if (PMIX_SUCCESS != (rc = pmix_mca_base_framework_open(&pmix_pinstalldirs_base_framework, 0))) {
 171         fprintf(stderr, "pmix_pinstalldirs_base_open() failed -- process will likely abort (%s:%d, returned %d instead of PMIX_SUCCESS)\n",
 172                 __FILE__, __LINE__, rc);
 173         return rc;
 174     }
 175 
 176     
 177     pmix_show_help_init();
 178 
 179     
 180     if (PMIX_SUCCESS != (rc = pmix_util_keyval_parse_init())) {
 181         fprintf(stderr, "pmix_util_keyval_parse_init failed with %d\n", rc);
 182         return PMIX_ERROR;
 183     }
 184 
 185     
 186     if (PMIX_SUCCESS != (rc = pmix_mca_base_var_init())) {
 187         fprintf(stderr, "pmix_mca_base_var_init failed with %d\n", rc);
 188         return PMIX_ERROR;
 189     }
 190 
 191     
 192     if (PMIX_SUCCESS != (rc = pmix_register_params())) {
 193         fprintf(stderr, "pmix_register_params failed with %d\n", rc);
 194         return PMIX_ERROR;
 195     }
 196 
 197     
 198     pmix_cmd_line_create(&cmd_line, cmd_line_opts);
 199 
 200     pmix_mca_base_open();
 201     pmix_mca_base_cmd_line_setup(&cmd_line);
 202     rc = pmix_cmd_line_parse(&cmd_line, false, false, argc, argv);
 203 
 204     if (PMIX_SUCCESS != rc) {
 205         if (PMIX_ERR_SILENT != rc) {
 206             fprintf(stderr, "%s: command line error (%s)\n", argv[0],
 207                     PMIx_Error_string(rc));
 208         }
 209         return rc;
 210     }
 211 
 212     if (pmix_pevent_globals.help) {
 213         char *str, *args = NULL;
 214         args = pmix_cmd_line_get_usage_msg(&cmd_line);
 215         str = pmix_show_help_string("help-pevent.txt", "usage", true,
 216                                     args);
 217         if (NULL != str) {
 218             printf("%s", str);
 219             free(str);
 220         }
 221         free(args);
 222         
 223         exit(0);
 224     }
 225 
 226     status = (pmix_status_t)pmix_pevent_globals.code;
 227     range = (pmix_data_range_t)pmix_pevent_globals.range;
 228 
 229     
 230 
 231 
 232     
 233     PMIX_INFO_CREATE(info, 1);
 234     PMIX_INFO_LOAD(&info[0], PMIX_CONNECT_SYSTEM_FIRST, NULL, PMIX_BOOL);
 235     
 236     if (PMIX_SUCCESS != (rc = PMIx_tool_init(&myproc, info, 1))) {
 237         fprintf(stderr, "PMIx_tool_init failed: %d\n", rc);
 238         exit(rc);
 239     }
 240     PMIX_INFO_FREE(info, 1);
 241 
 242     
 243     PMIX_CONSTRUCT_LOCK(&mylock.lock);
 244     PMIx_Register_event_handler(NULL, 0, NULL, 0,
 245                                 notification_fn, evhandler_reg_callbk, (void*)&mylock);
 246     PMIX_WAIT_THREAD(&mylock.lock);
 247     if (PMIX_SUCCESS != mylock.status) {
 248         fprintf(stderr, "PMIx_Register_event_handler returned bad status: %d\n", rc);
 249         PMIX_DESTRUCT_LOCK(&mylock.lock);
 250         goto done;
 251     }
 252     PMIX_DESTRUCT_LOCK(&mylock.lock);
 253 
 254     
 255     PMIX_CONSTRUCT_LOCK(&mylock.lock);
 256     rc = PMIx_Notify_event(status, &myproc, range, NULL, 0, opcbfunc, (void*)&mylock);
 257     if (PMIX_SUCCESS != rc) {
 258         fprintf(stderr, "PMIx_Notify_event failed: %d\n", rc);
 259         goto done;
 260     }
 261     PMIX_WAIT_THREAD(&mylock.lock);
 262     if (PMIX_SUCCESS != mylock.status) {
 263         fprintf(stderr, "PMIx_Notify_event returned bad status: %d\n", rc);
 264     }
 265     PMIX_DESTRUCT_LOCK(&mylock.lock);
 266 
 267 
 268   done:
 269     PMIx_tool_finalize();
 270 
 271     return(rc);
 272 }