TUXEDO 事件订阅服务端

  1. #include <stdio.h>  
  2. #include "atmi.h"         
  3.   
  4.   
  5.   
  6. /*myfunc must be defined as below,other define is error*/  
  7. void _TMDLLENTRY myfunc(char *buffer,long len,long flag)  
  8. {  
  9.     long len2;  
  10.     char buftype[20],subtype[20];  
  11.     if ((len2=tptypes(buffer,buftype,subtype))<0)  
  12.     {  
  13.         printf("invalid buffer receive;\n");  
  14.     }  
  15.     else if(!strcmp(buftype,"STRING"))  
  16.     {  
  17.         printf("unsolicited message from server\n:%s\n",buffer);  
  18.     }  
  19.     else if(!strcmp(buftype,"FML"))  
  20.     {  
  21.         printf("unsolicited message from server:\n");  
  22.         Fprint(buffer);  
  23.     }  
  24.     else  
  25.         printf("cannot print out buffer\n");  
  26.       
  27. }  
  28.   
  29.   
  30.   
  31. #if defined(__STDC__) || defined(__cplusplus)  
  32. main(int argc, char *argv[])  
  33. #else  
  34. main(argc, argv)  
  35. int argc;  
  36. char *argv[];  
  37. #endif  
  38.   
  39. {  
  40.   
  41.     char *sendbuf, *rcvbuf;  
  42.     long sendlen, rcvlen;  
  43.     int ret;  
  44.     TPEVCTL evctl;  
  45.     int sub_serv=0;  
  46.       
  47.       
  48.   
  49.     if(argc != 2) {  
  50.         (void) fprintf(stderr, "Usage: simpcl money\n");  
  51.         exit(1);  
  52.     }  
  53.       
  54.     /* Attach to System/T as a Client Process */  
  55.     if (tpinit((TPINIT *) NULL) == -1) {  
  56.         (void) fprintf(stderr, "Tpinit failed\n");  
  57.         exit(1);  
  58.     }  
  59.     sendlen = strlen(argv[1]);  
  60.     if((sendbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {  
  61.         (void) fprintf(stderr,"Error allocating send buffer\n");  
  62.         tpterm();  
  63.         exit(1);  
  64.     }  
  65.   
  66.     if((rcvbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {  
  67.         (void) fprintf(stderr,"Error allocating receive buffer\n");  
  68.         tpfree(sendbuf);  
  69.         tpterm();  
  70.         exit(1);  
  71.     }  
  72.     if(tpsetunsol(myfunc)== TPUNSOLERR)  
  73.     {  
  74.         printf("tpsetunsol() failure:%s\n",tpstrerror(tperrno));  
  75.         tpfree(sendbuf);  
  76.         tpfree(rcvbuf);  
  77.         tpterm();  
  78.         exit(1);      
  79.     }  
  80.     //sub_serv=tpsubscribe(eventexpr,filter,(TPEVCTL *)NULL,TPSIGRSTRT);  
  81.     evctl.flags = TPEVSERVICE;  
  82.     strcpy(evctl.name1,"CLIENT");  
  83.     sub_serv=tpsubscribe("BANK_TLR_WITHDRAWAL",NULL,(TPEVCTL *)NULL,TPSIGRSTRT);  
  84.     if (sub_serv==-1L)  
  85.     {  
  86.         printf("tpsubscribe() failure:%s\n",tpstrerror(tperrno));  
  87.         tpfree(sendbuf);  
  88.         tpfree(rcvbuf);  
  89.         tpterm () ;  
  90.         exit(1);  
  91.     }  
  92.     else   
  93.         printf("tpsubscribe(BANK_TLR_WITHDRAWAL) success\n");  
  94.       
  95.     (void) strcpy(sendbuf, argv[1]);  
  96.     ret = tpcall("WITHDRAWAL", (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0);  
  97.     if(ret == -1) {  
  98.         (void) fprintf(stderr, "tpcall(WITHDRAWAL) failure:%s\n",tpstrerror(tperrno));  
  99.         tpfree(sendbuf);  
  100.         tpfree(rcvbuf);  
  101.         tpterm();  
  102.         exit(1);  
  103.     }  
  104.     (void) fprintf(stdout, "Returned string is: %s\n", rcvbuf);  
  105.     if (tpunsubscribe(sub_serv,TPSIGRSTRT)==-1)  
  106.         printf("tpunsubscribe():%s\n",tpstrerror(tperrno));  
  107.     /* Free Buffers & Detach from System/T */  
  108.     tpfree(sendbuf);  
  109.     tpfree(rcvbuf);  
  110.     tpterm();  
  111.     return(0);  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值