| 1 | #include "fep.h" |
|---|
| 2 | #include <stdio.h> |
|---|
| 3 | #include <stdlib.h> |
|---|
| 4 | |
|---|
| 5 | /* Author: John A. Torres |
|---|
| 6 | The fep_program_32 function creates a new RPC Client which |
|---|
| 7 | sends an fep_reply structure to the ATMS Server. After the |
|---|
| 8 | reply is sent, the ATMS Sends a response and the RPC Client |
|---|
| 9 | is destroyed. |
|---|
| 10 | */ |
|---|
| 11 | void fep_program_32(char *host) |
|---|
| 12 | { |
|---|
| 13 | CLIENT *clnt; |
|---|
| 14 | |
|---|
| 15 | /* Declerations to construct an fep_reply */ |
|---|
| 16 | fep_answer_info fai; |
|---|
| 17 | fep_pollerror fpe; |
|---|
| 18 | fep_answer_short_msg fasm; |
|---|
| 19 | fep_shortanswer fsa; |
|---|
| 20 | fep_reply fep_reply_xfer_32_arg; // the reply to be sent to ATMS |
|---|
| 21 | |
|---|
| 22 | /* Var to recieve message back from ATMS */ |
|---|
| 23 | void *rv; |
|---|
| 24 | |
|---|
| 25 | /* Create RPC Client to communicate with ATMS */ |
|---|
| 26 | printf("Preparing to create RPC client\n"); |
|---|
| 27 | clnt = clnt_create(host, FEP_PROGRAM, FEP_VERSION, "tcp"); |
|---|
| 28 | |
|---|
| 29 | /* Check if client creation failed */ |
|---|
| 30 | if (clnt == (CLIENT *) NULL) |
|---|
| 31 | { |
|---|
| 32 | fprintf(stderr, "can't create client to %s\n", host); |
|---|
| 33 | /* Show why rpc handle couldn't be created */ |
|---|
| 34 | clnt_pcreateerror(""); |
|---|
| 35 | exit(1); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | /* Populate fep_shortmessage data */ |
|---|
| 39 | printf("setting reply values\n"); |
|---|
| 40 | |
|---|
| 41 | fasm.message_len = 5; |
|---|
| 42 | fasm.message[0] = 0x0a; |
|---|
| 43 | fasm.message[1] = 0x0d; |
|---|
| 44 | fasm.message[2] = 0x11; |
|---|
| 45 | fasm.message[3] = 0x12; |
|---|
| 46 | fasm.message[4] = 0x13; |
|---|
| 47 | |
|---|
| 48 | fpe.msgerror = (enum answererror) 0; |
|---|
| 49 | fpe.state = (enum Polling_FSM_States) 0x00; |
|---|
| 50 | fpe.perrno = 0; |
|---|
| 51 | fpe.termination = 0; |
|---|
| 52 | fpe.count = 0; |
|---|
| 53 | |
|---|
| 54 | fai.poll_time = 1111443466; |
|---|
| 55 | fai.status = (enum replystatus) 1; |
|---|
| 56 | fai.poll_user_info1 = 1; |
|---|
| 57 | fai.poll_user_info2 = 2; |
|---|
| 58 | fai.retries = 0; |
|---|
| 59 | fai.poll_error_count = 1; |
|---|
| 60 | fai.pollerror[0] = fpe; |
|---|
| 61 | |
|---|
| 62 | fsa.info = fai; |
|---|
| 63 | fsa.msg = fasm; |
|---|
| 64 | |
|---|
| 65 | fep_reply_xfer_32_arg.reply = 0; |
|---|
| 66 | fep_reply_xfer_32_arg.schedule = 0; |
|---|
| 67 | fep_reply_xfer_32_arg.lineinfo = 0; |
|---|
| 68 | fep_reply_xfer_32_arg.kind = (enum polltype)0; |
|---|
| 69 | fep_reply_xfer_32_arg.flag = (enum replykind) 0; |
|---|
| 70 | fep_reply_xfer_32_arg.schedule_sequence = 0; |
|---|
| 71 | fep_reply_xfer_32_arg.global_sequence = 0; |
|---|
| 72 | fep_reply_xfer_32_arg.schedule_time = 1111443466; |
|---|
| 73 | fep_reply_xfer_32_arg.user_info1 = 0; |
|---|
| 74 | fep_reply_xfer_32_arg.user_info2 = 0; |
|---|
| 75 | fep_reply_xfer_32_arg.system_key = 0; |
|---|
| 76 | fep_reply_xfer_32_arg.answers.size = 0; |
|---|
| 77 | fep_reply_xfer_32_arg.answers.fep_answer_list_u.shortp.count = 1; |
|---|
| 78 | fep_reply_xfer_32_arg.answers.fep_answer_list_u.shortp.answers[0] = fsa; |
|---|
| 79 | |
|---|
| 80 | /* Make RPC Call to transfer reply to ATMS */ |
|---|
| 81 | printf("transferring data\n"); |
|---|
| 82 | rv = fep_reply_xfer_32(&fep_reply_xfer_32_arg, clnt); |
|---|
| 83 | printf("checking reply`\n"); |
|---|
| 84 | |
|---|
| 85 | /* If ATMS reply call fails */ |
|---|
| 86 | if (rv == (void *) NULL) |
|---|
| 87 | { |
|---|
| 88 | clnt_perror(clnt, "call failed"); |
|---|
| 89 | } |
|---|
| 90 | /* If recieved reply is successful, but empty */ |
|---|
| 91 | else if ((char *) rv == "") |
|---|
| 92 | { |
|---|
| 93 | printf("rv is empty\n"); |
|---|
| 94 | } |
|---|
| 95 | /* If recieved reply is successful */ |
|---|
| 96 | else |
|---|
| 97 | { |
|---|
| 98 | printf("Result = %s\n", (char *)rv); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | /* Destroy client */ |
|---|
| 102 | printf("destroying client\n"); |
|---|
| 103 | clnt_destroy(clnt); |
|---|
| 104 | printf("returning to main\n"); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | /* Creates a single client and sends an fep_reply to the ATMS */ |
|---|
| 108 | int main(int argc, char *argv[]) { |
|---|
| 109 | char *host; |
|---|
| 110 | |
|---|
| 111 | if (argc < 2) |
|---|
| 112 | { |
|---|
| 113 | printf("usage: %s server_host\n", argv[0]); |
|---|
| 114 | exit(1); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | /* Create RPC Client to send an fep_reply to ATMS */ |
|---|
| 118 | host = argv[1]; |
|---|
| 119 | fep_program_32(host); |
|---|
| 120 | |
|---|
| 121 | return 0; |
|---|
| 122 | } |
|---|