TUXEDO 事件订阅服务端
1.#include <stdio.h>
2.#include "atmi.h"
3.
4.
5.
6.
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.
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.
108. tpfree(sendbuf);
109. tpfree(rcvbuf);
110. tpterm();
111. return(0);
112.}