00001 #ifndef __J2K__QNX__Reader_HPP__
00002 #define __J2K__QNX__Reader_HPP__
00003
00004 #include <j2k/Fred/QNX/Project.hpp>
00005
00006 class Reader
00007 : public MsgThread {
00008
00009
00010
00011 public:
00012
00013
00014
00015 Reader( int i = 0 ) : count( 0 ), idx( i ) { }
00016 virtual ~Reader() { }
00017
00018
00019 virtual void* MsgDispatcher( void* m, pid_t replyPid ) {
00020 void ( *Table[3] )( void ) = {
00021 function1,
00022 function2,
00023 function3
00024 };
00025
00026 serial_t id = *((serial_t*)m);
00027 printf("\nEntering MsgDispatcher,");
00028
00029 if ( id & _IS_MSG_DATA ) {
00030 MsgData* msg = (MsgData*)m;
00031 printf("\tMsgDataType [%d],", msg->valid );
00032
00033 if ( msg->valid == 0 ) {
00034 printf("\tExpired MsgData,");
00035 return m;
00036 }
00037
00038 if ( msg->task < MSG_VALID ) {
00039 printf("\tInvalid Task,");
00040 return m;
00041 }
00042
00043 if ( ( msg->task == MSG_KILL_THREAD ) || count > 5 ) {
00044 Stop();
00045 } else if ( msg->task == MSG_FUNCTION_CALL ) {
00046 printf("\tReader(%d){%u}[%d][%d]/5 \n", idx, id, msg->index, count );
00047 ( *Table[1] )();
00048 count++;
00049 }
00050 } else {
00051 printf("I have no clue what I am ! [%u]\n\n", id );
00052 }
00053
00054 return m;
00055 }
00056
00057 static void function1() {
00058 printf("\nFn1");
00059 }
00060
00061 static void function2() {
00062 printf("\nFn2");
00063 }
00064
00065 static void function3() {
00066 printf("\nFn3");
00067 }
00068
00069 private:
00070 int count;
00071 int idx;
00072 };
00073
00074 #endif
00075