00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <errno.h>
00004 #include <unistd.h>
00005 #include <semaphore.h>
00006 #include <mqueue.h>
00007
00008 #define MQUEUE_NAME "/eurephiaFW"
00009 #define EFW_MSG_SIZE 1024
00010
00011 int main() {
00012 struct mq_attr mqattr;
00013 mqd_t msgq;
00014 int prio;
00015
00016
00017 mqattr.mq_maxmsg = 10;
00018 mqattr.mq_msgsize = EFW_MSG_SIZE;
00019 mqattr.mq_flags = 0;
00020 msgq = mq_open(MQUEUE_NAME, O_RDWR | O_CREAT, 0600, &mqattr);
00021 if( msgq < 0 ) {
00022 printf("Could not open message queue: %s\n", strerror(errno));
00023 return 1;
00024 }
00025
00026 if( mq_getattr(msgq, &mqattr) == 0 ) {
00027 long i;
00028 char buf[1026];
00029
00030 memset(&buf, 0, 1026);
00031 if( mqattr.mq_curmsgs > 0 ) {
00032 for( i = 0; i < mqattr.mq_curmsgs; i++ ) {
00033 if( mq_receive(msgq, &buf[0], 1024, &prio) == -1 ) {
00034 printf("Error while emptying messages from queue: %s\n",
00035 strerror(errno));
00036 } else {
00037 int j;
00038 printf("Removed message on queue:\n");
00039 for( j = 0; j < 1024 ; j++ ) {
00040 printf("%02x [%c] ", buf[j], buf[j]);
00041 if( ((j+1) % 20) == 0 ) {
00042 printf("\n");
00043 }
00044 }
00045 }
00046 }
00047 }
00048 } else {
00049 printf("Could not retrieve message queue attributes (%s)\n",
00050 strerror(errno));
00051 }
00052
00053
00054 if( mq_close(msgq) != 0 ) {
00055 printf("Could not do close the message queue used for eFW: %s\n",
00056 strerror(errno));
00057 }
00058
00059 #if 0
00060 if( mq_unlink(MQUEUE_NAME) != 0 ) {
00061 printf("Could not do close the message queue used for eFW: %s\n",
00062 strerror(errno));
00063 }
00064 #endif
00065 return 0;
00066
00067 }