unlink.c 1.8 KB

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