Exemple #1
0
int run(void) {
    int operands[] = { 342, 74, 283, 37, 534 };
    int sz = sizeof(operands) / sizeof(int);
    const char *name = get_instance_name();

    printf("%s: what's the answer to ", name);
    for (int i = 0; i < sz; i++) {
        printf("%d ", operands[i]);
        if (i != sz - 1) {
            printf("+ ");
        }
    }
    printf("?\n");

    struct payload *p = (void*)d + 1024;
    p->sz = sz;
    for (int i = 0; i < sz; i++) {
        p->operands[i] = operands[i];
    }
    
    dataport_ptr_t ptr = a_calculate(dataport_wrap_ptr((void*)p));
    p = dataport_unwrap_ptr(ptr);

    printf("%s: result was %d\n", name, p->result);
    return 0;
}
Exemple #2
0
/* this callback handler is meant to be invoked the second time an event 
 * arrives on the echo event interface.
 * Note: the callback handler must be explicitly registered before the 
 * callback will be invoked.  
 * Also the registration is one-shot only, if it wants to be invoked 
 * when a new event arrives then it must re-register itself.  Or it can
 * also register a different handler. */
void callback_handler_echo_2(void *a) {
  /* TODO: read some data from the dataports. specifically:
   * read a dataport pointer from one dataport, then use that pointer to 
   * access data in another dataport. */
  for (int i = 0; i < ptrs->n; i++) {
    char *str = (char *) dataport_unwrap_ptr(ptrs->ptr[i]);
    printf("Echo server received: %s\n", str);
  }

  /* TODO: register the original callback handler for this event */
  data_ready_reg_callback(&callback_handler_echo, NULL);

  /* TODO: notify the client that we are done reading the data */
  reply_ready_emit();
}