hook.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <semaphore.h>
  2. #include "../bmc_type.h"
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <fcntl.h>
  6. #include <limits.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. int AddToQueue (void* pBuf, INT8S *Queuepath,INT32U Size);
  12. int AddQueue(INT8S *Queuepath);
  13. int GetQueue(INT8S *Queuepath,int flags);
  14. int GetQueueHandle(INT8S *Queuepath,HQueue_T *IfcQ);
  15. int PostMsg (MsgPkt_T* pMsgPkt, INT8S *Queuepath );
  16. int GetMsg (_FAR_ MsgPkt_T* pMsgPkt, INT8S *Queuepath, INT16S Timeout);
  17. /*-----------------------------------------------------------------
  18. * * Queue specific macros, functions and typedefs
  19. * *-----------------------------------------------------------------*/
  20. /*------ Allocate memory to hold the queue -------------------------*/
  21. #define OS_ALLOC_Q(QueueName, Size)
  22. #define OS_CREATE_Q(Key) \
  23. AddQueue(Key); \
  24. if (-1 == mkfifo (Key, 0777) && (errno != EEXIST)) \
  25. { \
  26. printf("Error creating named pipe %s\n", Key); \
  27. }
  28. #define OS_GET_Q(Key, RDWR) \
  29. if (GetQueue(Key,RDWR) == -1) \
  30. { \
  31. printf ("Attempt to open before creating pipe %s\n", Key); \
  32. }
  33. #define OS_CLOSE_Q(hQueue) \
  34. close (hQueue);
  35. #define POST_TO_Q(pBuf,Size,key,pErr) \
  36. { \
  37. AddToQueue(pBuf,key,Size); \
  38. }
  39. /*------- Add this message to the queue ----------------------------*/
  40. #define OS_ADD_TO_Q(pBuf, Size, hQueue, pErr) \
  41. *pErr = write (hQueue, pBuf, Size) \
  42. /*------ Get the message from the queue -----------------------------*/
  43. #define OS_GET_FROM_Q(pBuf, Size, hQueue, timeout, pErr) \
  44. { \
  45. int ReadLen = 0, Left, Len; \
  46. Left = Size; \
  47. while( Left > 0 ) \
  48. { \
  49. Len = read (hQueue, (INT8U*)pBuf + ReadLen, Left ); \
  50. if( Len < 0 ) \
  51. { \
  52. if( errno == EINTR || errno == EAGAIN ) \
  53. { \
  54. continue; \
  55. } \
  56. else \
  57. { \
  58. *pErr = -1; \
  59. break; \
  60. } \
  61. } \
  62. ReadLen += Len; \
  63. Left -= Len; \
  64. } \
  65. *pErr = ReadLen; \
  66. }
  67. /*-------- Get the number of messages in the Queue --------------------*/
  68. #define OS_GET_Q_DEPTH(hQueue, Depth, Size) \
  69. do \
  70. { \
  71. struct stat Stat; \
  72. if(0 == fstat (hQueue, &Stat)) \
  73. { \
  74. Depth = Stat.st_size/Size; \
  75. } \
  76. else { Depth = 0; } \
  77. } while (0)
  78. /*----------------Locking mechanism for Queue-----------------------*/
  79. #define LOCK_QUEUE(hQueue) \
  80. if (-1 == file_lock_write (hQueue)) \
  81. { \
  82. IPMI_WARNING ("Error locking Queue\n"); \
  83. }
  84. #define UNLOCK_QUEUE(hQueue) \
  85. if (-1 == file_unlock (hQueue)) \
  86. { \
  87. IPMI_WARNING ("Error unlocking Queue\n"); \
  88. }