OpenTP1 Version 7 Programming Reference C Language

[Contents][Index][Back][Next]

7.4.1 XATMI interface samples

Organization of this subsection
(1) Request/response service paradigm sample
(2) Conversational service paradigm sample

(1) Request/response service paradigm sample

(a) Outline of processing

The processing of the sample here is outlined below.

A service for checking hotel room availability and a service for checking airplane seat availability are called from the SUP. The first service receives responses asynchronously, whereas the second service receives responses synchronously.

(b) UAP configuration

The figure below shows the configuration of the sample UAP.

Figure 7-4 Communication of request/response services receiving responses synchronously

[Figure]

(c) Typed buffers used

The following shows the structure of typed buffers used for communication.

struct hotel {                   struct plane {
   long date;                       long date;
    char plane[128];                 char dest;
    char hname[128];                long departure;
   long status;                     long status;
 }                                }
(d) SUP sample
  10  /* Example of XATMI interface definition of SUP */
  15  /* (rrsup.def file)                             */
  20  called_servers = { "rrspp.def" };
  10  /* Example of SUP (rrsup.c file) */
  20  #include <stdio.h>
  30  #include <dcrpc.h>
  40  #include <xatmi.h>
  50  #include <dcadm.h>
  60  /*
  70   * XATMI stub header file
  80   */
  90  #include "rrsup_stbx.h"
 100  main()
 110  {
 120  /*
 130   * Define variables
 140   */
 150    struct hotel *hptr; 
 160    struct plane *pptr;
 170    struct  errmsg *werrmsg ;
 180    int  hlen, plen ;
 190    int  cd ;
 200    int rc;
 210  /*
 220   * RPC-OPEN (start the UAP)
 230   */
 240      rc = dc_rpc_open(DCNOFLAGS);
 250      if(rc != DC_OK){
 260          printf("dc_rpc_open failed.\
 270                  ERROR CODE = %d \n", rc);
 280          goto PROG_END;
 290      }
 300  /*
 310   * ADM-COMPLETE (report completion of user
 315   *               server start processing)
 320   */
 330      rc = dc_adm_complete(DCNOFLAGS);
 340      if(rc != DC_OK){
 350          printf("dc_adm_complete failed.\
 360                  ERROR CODE = %d \n",  rc);
 370          goto PROG_END;
 380      }
 390  /*
 400   * TPALLOC (allocate typed buffer)
 410   */
 420    /* For hotel room availability search service */
 430      hptr = (struct hotel *)tpalloc("X_COMMON",
 435                                     "hotel", 0);
 440      if(hptr == NULL){
 450          printf("tpalloc failed.\
 460                  ERROR CODE = %d \n", tperrno);
 470          goto PROG_END;
 480      }
 490    /* For airplane seat availability */
 500      pptr = (struct plane *)tpalloc("X_COMMON",
 505                                     "plane", 0);
 510      if(pptr == NULL){
 520          printf("tpalloc failed.\
 530                  ERROR CODE = %d \n", tperrno);
 540          goto PROG_END;
 550      }
 560  /*
 570   * Set data
 580   */
 590    hptr->date = 940415 ;
 600    strcpy(hptr->place, "SAPPORO") ;
 610    strcpy(hptr->hname, "PRINCE") ;
 620    hptr->status = 0 ;
 630    pptr->date = 940415 ;
 640    strcpy(pptr->dest, "CHITOSE") ;
 650    pptr->departure = 1540 ;
 660    pptr->status = 0 ;
 670  /*
 680   * TPACALL (send a service request)
 690   */
 700      cd = tpacall("SVHOTEL", (char *) hptr, 0, 0);
 710      if(cd == -1){
 720         printf("The hotel room availability search "
 725                "service call failed.\
 730                 ERROR CODE = %d \n", tperrno);
 740         goto PROG_END;
 750      }
 760      printf("The hotel room availability search "
 765             "service call was successful.\n");
 770  /*
 780   * TPCALL (send a service request and then wait for
 785   *         a response)
 790   */
 800      rc = tpcall("SVPLANE", (char *) pptr, 0,
 805                  (char **) &pptr, &plen, 0);
 810      if(rc != 0){
 820          if(tperrno == TPESVCFAIL){
 830             werrmsg = (struct errmsg *) pptr ;
 840             printf("%s ERROR CODE = %d USER CODE = %d\n",
 850                     werrmsg->errmessage, tperrno, tpurcode);
 860             goto PROG_END ;
 870          }else{
 880             printf("The airplane seat availability "
 885                    "search service call failed. "
 890                    "ERROR CODE = %d", tperrno);
 900             goto PROG_END;
 910          }
 920      }
 930      printf("A response to the airplane seat "
 935             "availability search service call was "
 937             "received successfully.\n");
 940      if(pptr->status == 1){
 950          printf("Airplane seat availability: Full \n");
 960      } else {
 970          printf("Airplane seat availability: "
 975                 "Available \n");
 980      }
 990  /*
1000   * TPGETRPLY (receive a response)
1010   */
1020      rc = tpgetrply(&cd, (char **) &hptr, &hlen, 0);
1030      if(rc != 0){
1040          if(tperrno == TPESVCFAIL){
1050             werrmsg = (struct errmsg *) hptr ;
1060             printf("%s ERROR CODE = %d USER CODE = %d\n",
1070                     werrmsg->errmessage, tperrno, tpurcode);
1080             goto PROG_END ;
1090          }else{
1100             printf("The hotel room availability search "
1105                    "service failed. ERROR CODE = %d",
1110                     tperrno);
1120             goto PROG_END;
1130          }
1140      }
1150      printf("A response to the hotel room availability "
155          "search service was received successfully. \n");
1160      if(hptr->status == 1){
1170          printf("Hotel room availability: Full \n");
1180      } else {
1190          printf("Hotel room availability: Available \n");
1200      }
1210  /*
1220   * Release the typed buffer
1230   */
1240      tpfree((char *) hptr);
1250      tpfree((char *) pptr);
1260  /*
1270   * RPC-CLOSE (terminate the UAP)
1280   */
1290      PROG_END:
1300      dc_rpc_close(DCNOFLAGS);
1310      printf("Thank you for using our service.\n");
1320      exit(0);
1330  }
  10  # Example of the user service definition (rrsup file)
  20  set  module              = "rrsup"
  30  set  receive_from        = none
  40  set  trn_expiration_time = 180
  50  set  trn_expiration_time_suspend = Y
(e) SPP sample
  10  /* Example of XATMI interface definition */
  15  /* (rrspp.def file) */
  20  X_COMMON hotel {
  30      long   date;
  40      char   place[128];
  50      char   hname[128];
  60      long   status;
  70  };
  80  X_COMMON plane {
  90      long   date;
 100      char   dest[128];
 110      long   departure;
 120      long   status;
 130  };
 140  X_COMMON errmsg {
 150      char   errmessage[128];
 160  };
 170  service shotel(X_COMMON hotel) ;
 180  service splane(X_COMMON plane) ;
  10  /* Example of SPP main function (rrspp.c file) */
  20  #include <stdio.h>
  30  #include <dcrpc.h>
  40  #include <xatmi.h>
  50  #include <dcadm.h>
  60  /*
  70   * XATMI stub header file
  80   */
  90  #include "rrspp_stbx.h"
 100  main()
 110  {
 120  /*
 130   * Define variables
 140   */
 150     int rc;
 160  /*
 170   * RPC-OPEN (start the UAP)
 180   */
 190      rc = dc_rpc_open(DCNOFLAGS);
 200      if(rc != DC_OK){
 210          printf("dc_rpc_open failed.\
 220                  ERROR CODE = %d \n", rc);
 230          goto PROG_END;
 240      }
 250  /*
 260   * RPC-MAINLOOP (start the SPP service)
 270   */
 280      rc = dc_rpc_mainloop(DCNOFLAGS);
 290      if(rc != DC_OK){
 300          printf("dc_rpc_mainloop failed.\
 310                  ERROR CODE = %d \n", rc);
 320      }
 330  /*
 340   * RPC-CLOSE (terminate the UAP)
 350   */
 360  PROG_END:
 370      dc_rpc_close(DCNOFLAGS);
 380      exit(0);
 390  }
  10  /* Example of service function of SPP (rrsvc.c file) */
  20  #include <stdio.h>
  30  #include <dcrpc.h>
  40  #include <xatmi.h>
  50  #include <dcadm.h>
  60  /*
  70   * XATMI stub header file
  80   */
  90  #include "rrspp_stbx.h"
 100  void shotel(svcinfo)
 110  TPSVCINFO *svcinfo;
 120  {
 130  /*
 140   * Define variables
 150   */
 160      struct hotel *hptr;
 170    
 180      hptr = (struct hotel *) svcinfo->data;
 190      /* This service searches availability and returns 
 195       * status = 1 if no room is available,
 200       * status = 0 if rooms are available, 
 205       * and a message if an error occurs.
 210       * This example assumes that no room 
 215       * is available. */
 220      hptr->status = 1 ;
 230      tpreturn(TPSUCCESS, 0, hptr, 0, 0);
 240      return ; /* In OpenTP1, return must be issued */
 245               /* after tpreturn. */
 250  }
 260  void splane(svcinfo)
 270  TPSVCINFO *svcinfo;
 280  {
 290      struct plane *pptr;
 300      pptr = (struct plane *) svcinfo->data;
 310      /* This service searches availability and returns
 315       * status = 1 if no seat is available, status = 0
 320       * if seats are available, and a message if an
 325       * error occurs. This example assumes that no seat
 330       * is available.
 335       */
 340      pptr->status = 1 ;
 350      tpreturn(TPSUCCESS, 0, pptr, 0, 0);
 360      return ;
 370  }
  10  # Example of user service definition (rrspp file)
  20  set    service_group       = "rrspp_svg"
  30  set    module              = "rrspp"
  40  set    service             = "SVHOTEL=shotel",
  45                               "SVPLANE=splane"
  50  set    trn_expiration_time = 180
  60  set    trn_expiration_time_suspend = Y
  70  set    server_type = "xatmi"

(2) Conversational service paradigm sample

(a) Outline of processing

The processing of the sample here is outlined below.

The service function is activated through a typed buffer having a build of structure acctreq. The members of acctreq indicate the upper and lower limits of the account numbers. The service function sets account data in this range in the typed buffer having a build of structure acctdat and sends the data to the originator of the conversation.

(b) UAP configuration

The figure below shows the configuration of the sample UAP.

Figure 7-5 Communication of conversational service

[Figure]

(c) Typed buffers used

The structures of typed buffers used are shown below.

(d) SUP sample
  10  /* Example of XATMI interface definition of SUP */
  15  /* (convsup.def file) */
  20  called_servers = { "convspp.def" };
  10  /* Coding example of SUP (convsup.c file) */
  20  #include <stdio.h>
  30  #include <dcrpc.h>
  40  #include <xatmi.h>
  50  #include <tx.h>
  60  #include <dcadm.h>
  70  /*
  80   * XATMI stub header file
  90   */
 100  #include "convsup_stbx.h"
 110  main()
 120  {
 130  /*
 140   * Define variables
 150   */
 160      struct   acctreq  *rptr; 
 170      struct   acctdata *dptr; 
 180      long     wlen;
 190      int      cd;
 200      int      rc;
 210      long     revent; 
 220      long     size = 0 ;
 230  /*
 240   * RPC-OPEN (start the UAP)
 250   */
 260      rc = dc_rpc_open(DCNOFLAGS);
 270      if(rc != DC_OK){
 280          printf("dc_rpc_open failed. ERROR CODE = %d \n",
 285                  rc);
 290          goto PROG_END;
 300      }
 310  /*
 320   * ADM-COMPLETE (report completion of user 
       *               server start processing)
 330   */
 340      rc = dc_adm_complete(DCNOFLAGS);
 350      if(rc != DC_OK){
 360          printf("dc_adm_complete failed. ERROR "
 365                 "CODE = %d \n", rc);
 370          goto PROG_END;
 380      }
 390  /*
 400   * TPALLOC (allocate typed buffer)
 410   */
 420    /* For setting minimum and maximum account numbers */
 425    /* to be searched */
 430      rptr = (struct acctreq *)tpalloc(X_COMMON,
 435                                       "acctreq", 0);
 440  
 450      if(rptr == NULL){
 460          printf("tpalloc failed. ERROR CODE = %d \n",
 465                  tperrno);
 470          goto PROG_END;
 480      }
 490    /* For account data in the search result */  
 500      dptr = (struct acctdata *)tpalloc(X_COMMON, 
 505                                        "acctdata", 0) ;
 510      if(dptr == NULL){
 520          printf("tpalloc failed. ERROR CODE = %d \n",
 525                  tperrno);
 530          goto PROG_END;
 540      }
 550  /*
 560   * Set data
 570   * Specify the search range
 580   */
 590      rptr->lower_no = 10000000L;
 600      rptr->upper_no = 20000000L;
 610   /* Start the transaction  */
 620      tx_begin() ;
 630  /*
 640   * TPCONNECT (call the conversational service)
 650   * Call INQUIRY
 660   */
 670      cd = tpconnect("INQUIRY", (char *) rptr, 0,
 675                      TPRECVONLY);
 680      if(cd == -1){
 690          printf("tpconnect failed. ERROR CODE = %d \n",
 695                  tperrno);
 700          goto PROG_END;
 710      }
 720  /*
 730   * TPRECV (receive messages)
 740   * Until an error occurs (include events),
 750   */
 760      while(rc != -1){
 770          rc = tprecv(cd, (char **) &dptr, &wlen, 0,
 775                      &revent);
 780          /*
 790           * If no error has occurred,
 800           * output the received account information.
 810           */
 820          if(rc != -1) {
 830              printf("The account information was "
 835                     "received from the service.\n");
 840              printf("Account number = %d \n",
 845                      dptr->acct_no);
 850              printf("Name = %s \n", dptr->name);
 860              printf("Amount = %d \n", dptr->amount);
 870          }
 880      }
 890  /*
 900   * Output the result of the service
 910   */
 920      if(tperrno == TPEEVENT){
 930          if(revent == TPEV_SVCSUCC){
 940          /* The service was successful. */
 950              printf("The service was successful.\n");
 960              /* Transaction commit */
 970              tx_commit() ;
 980          }else{
 990              printf("Some event has occurred. "
 995                     "revent = %d\n",
1000              revent);
1010              /* Transaction rollback */
1020              tx_rollback() ;
1030          }
1040    }
1050  /*
1060   * Release the typed buffer
1070   */
1080      tpfree((char *) rptr);
1090      tpfree((char *) dptr);
1100  /*
1110   * RPC-CLOSE (terminate the UAP)
1120   */
1130      PROG_END:
1140      dc_rpc_close(DCNOFLAGS);
1150      exit(0);
1160  }
  10  # Example of user service definition
  15  # (convsup file)
  20  set module        = "convsup"
  25                     # Name of executable file
  30  set watch_time     = 180
  35                     # Maximum time to wait for a response
  40  set receive_from  = none
  45                     # Receiving method
  50  set trn_expiration_time = 180
  60                     # Expiry time in transaction branch
  70  set trn_expiration_time_suspend = Y
  75                                  # Always specify Y
(e) SPP sample
  10  /* Example of XATMI interface definition of SPP */
  15  /* (convspp.def file) */
  20  X_COMMON acctreq {
  30      long   upper_no;
  40      long   lower_no;
  50  };
  60  X_COMMON acctdata {
  70      long   acct_no;
  80      char   name[128];
  90      short  amount;
 100  };
 110  service inquiry(X_COMMON acctreq) ;
  10  /* Example of SPP main function (convspp.c file) */
  20  #include <stdio.h>
  30  #include <dcrpc.h>
  40  #include <xatmi.h>
  50  #include <dcadm.h>
  60  /*
  70   * XATMI stub header file
  80   */
  90  #include "convspp_stbx.h"
 100  main()
 110  {
 120  /*
 130   * Define variables
 140   */
 150      int rc;
 160  /*
 170   * RPC-OPEN (start the UAP)
 180   */
 190      rc = dc_rpc_open(DCNOFLAGS);
 200      if(rc != DC_OK){
 210          printf("dc_rpc_open failed. ERROR "
 215                 "CODE = %d \n", rc);
 220          goto PROG_END;
 230      }
 240    
 250  /*
 260   * RPC-MAINLOOP (start the SPP service)
 270   */
 280      rc = dc_rpc_mainloop(DCNOFLAGS);
 290      if(rc != DC_OK){
 300          printf("dc_rpc_mainloop failed. "
 315                 "ERROR CODE = %d \n",rc);
 310      }
 320  /*
 330   * RPC-CLOSE (terminate the UAP)
 340   */
 350      PROG_END:
 360      dc_rpc_close(DCNOFLAGS);
 370      exit(0);
 380  }
  10  /* Example of service function of SPP */
  15  /* (convsvc.c file) */
  20  #include <stdio.h>
  30  #include <dcrpc.h>
  40  #include <xatmi.h>
  50  #include <dcadm.h>
  60  /*
  70   * XATMI stub header file
  80   */
  90  #include "convspp_stbx.h"
 100  /*
 110   * DEPOSITSVC service function
 120   * Use tpconnect() to receive the minimum and maximum
 125   * account numbers, and send information about
 130   * accounts that are within that range
 140   */
 150  void inquiry(svcinfo)
 160  TPSVCINFO *svcinfo;
 170  {
 180  /*
 190   * Define variables
 200   */
 210      struct   acctreq  *rptr;
 220      struct   acctdata *dptr;
 230      char     type[9];
 240      char     subtype[17];
 250      long     revent, rval;
 260      int      size;
 270  /*
 280   * Service request was accepted
 290   */
 300      rptr = (struct acctreq *) svcinfo->data;
 310  /*
 320   * Allocate the typed buffer for data that is to 
 325   * be returned to the originator
 330   */
 340      dptr = (struct acctdata *)tpalloc("X_COMMON",
 345                                        "acctdata", 0);
 350      if(rptr == NULL){
 360          printf("An error occurred in tpalloc. "
 365                 "tperrno = %d \n",
 370                 tperrno);
 380          abort();
 390      }
 400  /*
 410   * User processing
 420   * Search the data file and return the account
 425   * information for account numbers within the specific
 430   * range. This example assumes that two accounts have 
 435   * been found and then sends the data.
 440   */
 450      
 460      dptr->acct_no = 10000001L;
 470      strcpy(dptr->name, "Hitachi Hanako");
 480      dptr->amount = 20000;
 490  /*
 500   * TPSEND (send a message)
 510   */
 520      tpsend(svcinfo->cd, (char *) dptr, 0, 0, &revent);
 530      if(tperrno != -1){
 540          rval = TPSUCCESS;
 550      }else{
 560          rval = TPFAIL;
 570          goto SVC_END;
 580      }
 590      dptr->acct_no = 10000002L;
 600      dptr->amount = 10000;
 610      strcpy(dptr->name, "Hitachi Tarou");
 620  /*
 630   * TPSEND (send a message)
 640   */
 650      tpsend(svcinfo->cd, (char *) dptr, 0, 0, &revent);
 660      if(tperrno != -1){
 670          rval = TPSUCCESS;
 680      }else{
 690          rval = TPFAIL;
 700          goto SVC_END;
 710      }
 720  SVC_END:
 730      tpreturn(rval, 0, NULL, 0, 0);
 740      return; /* In OpenTP1, return is required after */
 745              /* tpreturn. */
 750  }
  10  # Example of user service definition (convspp file)
  20    set  service_group     = "convspp_svg"
  25                           # Service group name
  30    set  module            = "convspp"
  35                           # Name of executable file
  40    set  service  = "INQUIRY=inquiry"
  50                   # Service name = entry point name
  60    set  watch_time        = 180
  65                   # Maximum time to wait for a response
  70    set  trn_expiration_time = 240
  80                   # Expiry time in transaction branch
  90    set  trn_expiration_time_suspend = Y
  95                                     # Always specify Y
 100    set  server_type = "xatmi"       # Server type
 110    set  receive_from = "socket"     # Receiving method