msgqueue.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #ifndef _MSGQUEUE_H
  2. #define _MSGQUEUE_H
  3. #include <unistd.h>
  4. #include <stdbool.h>
  5. #include <sys/types.h>
  6. #include <sys/ipc.h>
  7. #include <sys/msg.h>
  8. #include <sys/shm.h>
  9. #include <stdio.h>
  10. #include <errno.h>
  11. //03/08/2012 added by cdlin to build for new tool chain.
  12. #include <string.h>
  13. //~cdlin
  14. #define SHM_EPG_CH_LIST (0xf001)
  15. #define SHM_EPG_CUR_EVENT (0xf002)
  16. #define SHM_UMF_CH_LIST (0xf003)
  17. #define SHM_EPG_CH_SERVICE (0xf004)
  18. #define SHM_EPG_RRT (0xf005)
  19. #define SHM_CECDEVICE_LIST (0xf006)
  20. #define SHM_OSD_String (0xf007)
  21. #define SHM_REC_DATAINFO (0xf008)
  22. #define TASK_QUEUE_EPG (0xf001)
  23. #define TASK_QUEUE_FC (0xf002)
  24. #define TASK_QUEUE_UMF2JPEG (0xf003)
  25. #define TASK_QUEUE_JPEG2UMF (0xf004)
  26. #define TASK_QUEUE_UMFtoTT (0xf005)
  27. #define TASK_QUEUE_TTtoUMF (0xf006)
  28. #define TASK_QUEUE_UMFtoCECD (0xf007)
  29. #define TASK_QUEUE_CECDtoUMF (0xf008)
  30. #define TASK_QUEUE_UMF2MUSIC (0xf009)
  31. #define TASK_QUEUE_MUSIC2UMF (0xf00a)
  32. #define TASK_QUEUE_UMF2TS (0xf00b)
  33. #define TASK_QUEUE_TS2UMF (0xf00c)
  34. #define TASK_QUEUE_UMF2KOK (0xf00d)
  35. #define TASK_QUEUE_KOK2UMF (0xf00e)
  36. #define TASK_QUEUE_UMF2MEDIA (0xf00f)
  37. #define TASK_QUEUE_MEDIA2UMF (0xf010)
  38. #define TASK_QUEUE_UMF2ANYPLEX (0xf011)
  39. #define TASK_QUEUE_ANYPLEX2UMF (0xf012)
  40. // nina for media message Q
  41. #define TASK_QUEUE_MEDIA2MediaQueue (0xf013)
  42. #define TASK_QUEUE_MEDIA2MediaReturnQueue (0xf014)
  43. #define TASK_QUEUE_WhoIsCurrentScreenQueue (0xf015)
  44. #define TASK_QUEUE_MEDIA2PVRQueue (0xf016)
  45. // ~nina for media message Q
  46. // for GJ PVR Msg Q
  47. #define TASK_QUEUE_UMF2PVR (0xf017)
  48. #define TASK_QUEUE_PVR2UMF (0xf018)
  49. #define TASK_QUEUE_PVR2MediaReturnQueue (0xf019)
  50. #define TASK_QUEUE_PVR2PVRQueue (0xf01A)
  51. // ~for GJ PVR Msg Q
  52. // for KOK Msg Q
  53. #define TASK_QUEUE_MINI2KOK (0xf01B)
  54. #define TASK_QUEUE_KOKTOMINI (0xf01C)
  55. #ifdef CONFIG_SUPPORT_MIRACAST
  56. #define TASK_QUEUE_UMF2MIRACAST (0xf01d)
  57. #define TASK_QUEUE_MIRACAST2UMF (0xf01e)
  58. #endif
  59. // ~for KOK PVR Msg Q
  60. #define MSGTYPE_FC (0x1) //Flow Control
  61. #define MSGTYPE_EPG (0x2)
  62. #define MSGTYPE_PSIP (0x3)
  63. #define MSGTYPE_SI (0x4)
  64. #define MSGTYPE_CI (0x5)
  65. #define MSGTYPE_SELF (0x6)
  66. #define MSGTYPE_EAM (0x7)
  67. #define MSGTYPE_UMF2JPEG (0x8)
  68. #define MSGTYPE_JPEG2UMF (0x9)
  69. #define MSGTYPE_TT (0xa)
  70. #define MSGTYPE_UMF2MUSIC (0xb)
  71. #define MSGTYPE_MUSIC2UMF (0xc)
  72. #define MSGTYPE_UMF2TS (0xd)
  73. #define MSGTYPE_TS2UMF (0xe)
  74. #define MSGTYPE_UMF2KOK (0xf)
  75. #define MSGTYPE_KOK2UMF (0x10)
  76. #define MSGTYPE_UMF2MEDIA (0x11)
  77. #define MSGTYPE_MEDIA2UMF (0x12)
  78. #define MSGTYPE_UMF2ANYPLEX (0x13)
  79. #define MSGTYPE_ANYPLEX2UMF (0x14)
  80. //media for pre message Q
  81. #define MSGTYPE_MEDIA2MediaQueue (0x15)
  82. #define MSGTYPE_MEDIA2MediaReturnQueueFail (0x16)
  83. #define MSGTYPE_WhoIsCurrentScreenQueue (0x17)
  84. #define MSGTYPE_UMF2PVR (0x18)
  85. #define MSGTYPE_MEDIA2MediaReturnQueueSuccess (0x19)
  86. #define MSGTYPE_NoticesTimeOut (0x1a)
  87. #define MSGTYPE_PVR2UMF (0x1b)
  88. //-media for pre message Q
  89. #define TASK_QUEUE_UMF2MEDIA_MENU (0x1c)
  90. #ifdef CONFIG_SUPPORT_MIRACAST
  91. #define MSGTYPE_UMF2MIRACAST (0x1d)
  92. #define MSGTYPE_MIRACAST2UMF (0x1e)
  93. #endif
  94. inline static bool CreateMessageQueue(int* pMsqid, uint nQueue)
  95. {
  96. int iMsqid;
  97. iMsqid= msgget(nQueue, 0);
  98. if( iMsqid!=-1 )
  99. msgctl(iMsqid, IPC_RMID, 0);
  100. iMsqid= msgget(nQueue, 0666|IPC_CREAT);
  101. if( iMsqid==-1 )
  102. {
  103. perror("CreateMessageQueue fail: ");
  104. return false;
  105. }
  106. *pMsqid= iMsqid;
  107. return true;
  108. }
  109. inline static bool ConnectMessageQueue(int* pMsqid, uint nQueue)
  110. {
  111. int iMsqid,iLoop=100;
  112. do{
  113. usleep(50000);
  114. iMsqid= msgget(nQueue, 0);
  115. } while(iMsqid==-1 && iLoop-->0);
  116. *pMsqid= iMsqid;
  117. return (iMsqid>=0)?true:false;
  118. }
  119. inline static bool DeleteMessageQueue(int iMsqid)
  120. {
  121. if( -1==msgctl(iMsqid, IPC_RMID, 0) )
  122. return false;
  123. else
  124. return true;
  125. }
  126. inline static uint GetMessageNodeCount(int iMsqid)
  127. {
  128. struct msqid_ds buf;
  129. if( -1==msgctl(iMsqid, IPC_STAT, &buf) )
  130. return 0;
  131. return buf.msg_qnum;
  132. }
  133. inline static int CreateSharedMemory(key_t key, size_t size)
  134. {
  135. return shmget(key, size, 0666|IPC_CREAT);
  136. }
  137. inline static void DeleteSharedMemory(int iShmId)
  138. {
  139. if( iShmId!=-1 )
  140. shmctl( iShmId, IPC_RMID, 0);
  141. }
  142. inline static bool CopyToSharedMemory(int iShmId, void* p, size_t size)
  143. {
  144. bool bResult= false;
  145. void* shared_memory= shmat(iShmId, (void*) 0, 0);
  146. if( shared_memory!=(void*)(-1) )
  147. {
  148. memcpy(shared_memory, p, size);
  149. shmdt(shared_memory);
  150. bResult= true;
  151. }
  152. return bResult;
  153. }
  154. inline static bool CopyFromSharedMemory(int iShmId, void* p, size_t size)
  155. {
  156. bool bResult= false;
  157. void* shared_memory= shmat(iShmId, (void*) 0, 0);
  158. if( shared_memory!=(void*)(-1) )
  159. {
  160. memcpy(p, shared_memory, size);
  161. shmdt(shared_memory);
  162. bResult= true;
  163. }
  164. return bResult;
  165. }
  166. #endif //_MSGQUEUE_H