unlink.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Test program for event service
  3. */
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <sys/poll.h>
  7. #include <unistd.h>
  8. #include <fcntl.h>
  9. #ifndef OPENAIS_SOLARIS
  10. #include <stdint.h>
  11. #include <getopt.h>
  12. #else
  13. #include <sys/types.h>
  14. #endif
  15. #include <stdlib.h>
  16. #include <sys/time.h>
  17. #include "saAis.h"
  18. #include "saEvt.h"
  19. #define TRY_WAIT 2
  20. extern int get_sa_error(SaAisErrorT, char *, int);
  21. char result_buf[256];
  22. int result_buf_len = sizeof(result_buf);
  23. SaVersionT version = { 'B', 0x01, 0x01 };
  24. SaEvtCallbacksT callbacks = {
  25. 0,
  26. 0
  27. };
  28. char channel[256] = "EVENT_TEST_CHANNEL";
  29. int
  30. do_unlink()
  31. {
  32. SaEvtHandleT handle;
  33. SaNameT channel_name;
  34. SaAisErrorT result;
  35. do {
  36. result = saEvtInitialize (&handle, &callbacks, &version);
  37. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  38. if (result != SA_AIS_OK) {
  39. get_sa_error(result, result_buf, result_buf_len);
  40. printf("Event Initialize result: %s\n", result_buf);
  41. return(result);
  42. }
  43. strcpy((char *)channel_name.value, channel);
  44. channel_name.length = strlen(channel);
  45. do {
  46. result = saEvtChannelUnlink(handle, &channel_name);
  47. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  48. if (result != SA_AIS_OK) {
  49. get_sa_error(result, result_buf, result_buf_len);
  50. printf("ERROR: channel unlink result: %s\n", result_buf);
  51. }
  52. do {
  53. result = saEvtFinalize(handle);
  54. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  55. if (result != SA_AIS_OK) {
  56. get_sa_error(result, result_buf, result_buf_len);
  57. printf("ERROR: Event Finalize result: %s\n", result_buf);
  58. }
  59. return 0;
  60. }
  61. int main (int argc, char **argv)
  62. {
  63. static const char opts[] = "c:";
  64. int option;
  65. while (1) {
  66. option = getopt(argc, argv, opts);
  67. if (option == -1)
  68. break;
  69. switch (option) {
  70. case 'c':
  71. strcpy(channel, optarg);
  72. break;
  73. default:
  74. printf("invalid arg: \"%s\"\n", optarg);
  75. return 1;
  76. }
  77. }
  78. do_unlink();
  79. return 0;
  80. }