int main() { //status message received in almost all MCAPI-calls mcapi_status_t status; //info-struct received in initialization mcapi_info_t info; //the status code converted to string char status_msg[MCAPI_MAX_STATUS_MSG_LEN]; //an iterator used in loops unsigned int i = 0; //request handle is used to operate wait-calls mcapi_request_t request; //size parameter required in some calls size_t size = 1; //send-handle used in channel-messaging mcapi_pktchan_send_hndl_t handy; //a separate receive buffer used for messages char recv_msg[MAX_MSG_LEN]; //get our stuff here. tip: if signed were used, it bastardized the values unsigned char* recv_buf; //the endpoints used in channel-oriented communication mcapi_endpoint_t green_chan; mcapi_endpoint_t yellow_chan; mcapi_endpoint_t green_msg_point; printf( COLOR "here\n"); //we are the green mcapi_initialize( THE_DOMAIN, GREEN_NODE, 0, 0, &info, &status ); check( MCAPI_SUCCESS, status ); //create our message endpoint green_msg_point = mcapi_endpoint_create( GREEN_MSG, &status ); check( MCAPI_SUCCESS, status ); //wait for the start signal mcapi_msg_recv(green_msg_point, recv_msg, MAX_MSG_LEN, &size, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "signal received, starting to connect & open\n"); //create our channel message endpoint green_chan = mcapi_endpoint_create( GREEN_PKT, &status ); check( MCAPI_SUCCESS, status ); //get their channel message endpoint yellow_chan = mcapi_endpoint_get( THE_DOMAIN, YELLOW_NODE, YELLOW_PKT, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); //form the channel mcapi_pktchan_connect_i( yellow_chan, green_chan, &request, &status ); check( MCAPI_PENDING, status ); //wait for it to happen mcapi_wait( &request, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); //open our end mcapi_pktchan_recv_open_i( &handy, green_chan, &request, &status ); check( MCAPI_PENDING, status ); //wait for it to happen mcapi_wait( &request, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "beginning the receive\n"); //start to receive our stuff mcapi_pktchan_recv( handy, (void*)&recv_buf, &size, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "retrieval done, closing\n"); //close our end mcapi_pktchan_recv_close_i( handy, &request, &status ); check( MCAPI_PENDING, status ); //wait for it to happen mcapi_wait( &request, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "closed, go over the values\n"); //go through that stuff //i+=2 because our values are two bytes while buf is one byte for ( i = 0; i < size; i+=2 ) { //reconstruct the short short sumval = recv_buf[i+1] << 8 | recv_buf[i]; //printf( COLOR "%hX %hhX %hhX\n", sumval, recv_buf[i], recv_buf[i+1] ); } printf(COLOR "buffer release and shut down\n"); //release mcapi_pktchan_release( recv_buf, &status ); check( MCAPI_SUCCESS, status ); //finalize at the end, regardless of which process we are mcapi_finalize( &status ); check( MCAPI_SUCCESS, status ); return EXIT_SUCCESS; }
int main () { size_t size; mcapi_endpoint_t ep1,ep2; mcapi_pktchan_send_hndl_t s1; /* s1 = ep1->ep2 */ mcapi_pktchan_recv_hndl_t r1; /* r1 = ep1->ep2 */ int i = 0; int rc = 1; mca_status_t status; mcapi_request_t request; mcapi_param_t parms; mcapi_info_t version; mcapi_set_debug_level(6); /* create a node */ mcapi_initialize(DOMAIN,NODE,NULL,&parms,&version,&status); if (status != MCAPI_SUCCESS) { WRONG } /* create endpoints */ ep1 = mcapi_endpoint_create(PORT_NUM1,&status); if (status != MCAPI_SUCCESS) { WRONG } ep2 = mcapi_endpoint_create(PORT_NUM2,&status); if (status != MCAPI_SUCCESS) { WRONG } /*************************** connect the channels *********************/ do { mcapi_pktchan_connect_i(ep1,ep2,&request,&status); //retry if all request handles are in-use } while (status == MCAPI_ERR_REQUEST_LIMIT); while (!mcapi_test(&request,&size,&status)) {} if (status != MCAPI_SUCCESS) { WRONG } /*************************** open the channels *********************/ do { mcapi_pktchan_recv_open_i(&r1 /*recv_handle*/,ep2, &request, &status); //retry if all request handles are in-use } while (status == MCAPI_ERR_REQUEST_LIMIT); while (!mcapi_test(&request,&size,&status)) {} if (status != MCAPI_SUCCESS) { WRONG } do { mcapi_pktchan_send_open_i(&s1 /*send_handle*/,ep1, &request, &status); //retry if all request handles are in-use } while (status == MCAPI_ERR_REQUEST_LIMIT); while (!mcapi_test(&request,&size,&status)) {} if (status != MCAPI_SUCCESS) { WRONG } /* tests: recv send send recv obeys FIFO */ do { mcapi_pktchan_recv_i(r1,(void **)((void*)&requests[i].buffer),&requests[i].request,&requests[i].status); //retry if all request handles are in-use } while (status == MCAPI_ERR_REQUEST_LIMIT); i++; do { mcapi_pktchan_send_i(s1,"one",sizeof("one"),&requests[i].request,&requests[i].status); //retry if all request handles are in-use } while (status == MCAPI_ERR_REQUEST_LIMIT); i++; do { mcapi_pktchan_send_i(s1,"two",sizeof("two"),&requests[i].request,&requests[i].status); //retry if all request handles are in-use } while (status == MCAPI_ERR_REQUEST_LIMIT); i++; do { mcapi_pktchan_recv_i(r1,(void **)((void*)&requests[i].buffer),&requests[i].request,&requests[i].status); //retry if all request handles are in-use } while (status == MCAPI_ERR_REQUEST_LIMIT); i++; rc = check_results(); /* close the channels */ do { mcapi_pktchan_recv_close_i(r1,&request,&status); //retry if all request handles are in-use } while (status == MCAPI_ERR_REQUEST_LIMIT); while (!mcapi_test(&request,&size,&status)) {} if (status != MCAPI_SUCCESS) { WRONG } do { mcapi_pktchan_send_close_i(s1,&request,&status); //retry if all request handles are in-use } while (status == MCAPI_ERR_REQUEST_LIMIT); while (!mcapi_test(&request,&size,&status)) {} if (status != MCAPI_SUCCESS) { WRONG } mcapi_finalize(&status); if (rc == 0) { printf(" Test PASSED\n"); } else { printf(" Test FAILED\n"); } return rc; }