- #include <stdio.h>
- #include "atmi.h"
- /*myfunc must be defined as below,other define is error*/
- void _TMDLLENTRY myfunc(char *buffer,long len,long flag)
- {
- long len2;
- char buftype[20],subtype[20];
- if ((len2=tptypes(buffer,buftype,subtype))<0)
- {
- printf("invalid buffer receive;\n");
- }
- else if(!strcmp(buftype,"STRING"))
- {
- printf("unsolicited message from server\n:%s\n",buffer);
- }
- else if(!strcmp(buftype,"FML"))
- {
- printf("unsolicited message from server:\n");
- Fprint(buffer);
- }
- else
- printf("cannot print out buffer\n");
- }
- #if defined(__STDC__) || defined(__cplusplus)
- main(int argc, char *argv[])
- #else
- main(argc, argv)
- int argc;
- char *argv[];
- #endif
- {
- char *sendbuf, *rcvbuf;
- long sendlen, rcvlen;
- int ret;
- TPEVCTL evctl;
- int sub_serv=0;
- if(argc != 2) {
- (void) fprintf(stderr, "Usage: simpcl money\n");
- exit(1);
- }
- /* Attach to System/T as a Client Process */
- if (tpinit((TPINIT *) NULL) == -1) {
- (void) fprintf(stderr, "Tpinit failed\n");
- exit(1);
- }
- sendlen = strlen(argv[1]);
- if((sendbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {
- (void) fprintf(stderr,"Error allocating send buffer\n");
- tpterm();
- exit(1);
- }
- if((rcvbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {
- (void) fprintf(stderr,"Error allocating receive buffer\n");
- tpfree(sendbuf);
- tpterm();
- exit(1);
- }
- if(tpsetunsol(myfunc)== TPUNSOLERR)
- {
- printf("tpsetunsol() failure:%s\n",tpstrerror(tperrno));
- tpfree(sendbuf);
- tpfree(rcvbuf);
- tpterm();
- exit(1);
- }
- //sub_serv=tpsubscribe(eventexpr,filter,(TPEVCTL *)NULL,TPSIGRSTRT);
- evctl.flags = TPEVSERVICE;
- strcpy(evctl.name1,"CLIENT");
- sub_serv=tpsubscribe("BANK_TLR_WITHDRAWAL",NULL,(TPEVCTL *)NULL,TPSIGRSTRT);
- if (sub_serv==-1L)
- {
- printf("tpsubscribe() failure:%s\n",tpstrerror(tperrno));
- tpfree(sendbuf);
- tpfree(rcvbuf);
- tpterm () ;
- exit(1);
- }
- else
- printf("tpsubscribe(BANK_TLR_WITHDRAWAL) success\n");
- (void) strcpy(sendbuf, argv[1]);
- ret = tpcall("WITHDRAWAL", (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0);
- if(ret == -1) {
- (void) fprintf(stderr, "tpcall(WITHDRAWAL) failure:%s\n",tpstrerror(tperrno));
- tpfree(sendbuf);
- tpfree(rcvbuf);
- tpterm();
- exit(1);
- }
- (void) fprintf(stdout, "Returned string is: %s\n", rcvbuf);
- if (tpunsubscribe(sub_serv,TPSIGRSTRT)==-1)
- printf("tpunsubscribe():%s\n",tpstrerror(tperrno));
- /* Free Buffers & Detach from System/T */
- tpfree(sendbuf);
- tpfree(rcvbuf);
- tpterm();
- return(0);
- }
TUXEDO 事件订阅服务端
最新推荐文章于 2021-04-30 01:41:56 发布