00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __J2K__Train__Message_HPP__
00010 #define __J2K__Train__Message_HPP__
00011
00012 #include "sthread.hh"
00013
00014 #define MESSAGE_BUFFER_SIZE 30 // grow as needed
00015
00016 class Message_thread : public Schedule_thread
00017 {
00018 private:
00019 char buffer_[MESSAGE_BUFFER_SIZE];
00020
00021 public:
00022 Message_thread();
00023 virtual void run();
00024
00025
00026 void send(const void* buffer, int length, void* reply, int rlength);
00027
00028
00029 int stop();
00030
00031 typedef int (Message_thread::*method_type)(...);
00032
00033 protected:
00034 struct message_table_entry {
00035 int (*marshal)(Message_thread*,
00036 method_type,
00037 int,
00038 char*,
00039 pid_type);
00040 method_type function;
00041 };
00042
00043 virtual int message_filter(int m, char* data, pid_type pid) { return 0; }
00044 virtual const message_table_entry* find_entry(int msg) { return 0; };
00045
00046 static int dispatch(Message_thread* self,
00047 int msg,
00048 char* buffer,
00049 pid_type pid);
00050 };
00051
00052
00053 #define DECLARE_MESSAGE_TABLE \
00054 static const message_table_entry message_table_[]; \
00055 virtual const message_table_entry* find_entry(int msg) { \
00056 return &message_table_[msg - 1]; \
00057 }
00058
00059 #define BEGIN_MESSAGE_TABLE(Cls) \
00060 const Message_thread::message_table_entry Cls::message_table_[] = {
00061
00062 #define MESSAGE(Marshal, Function) \
00063 { Marshal, (Message_thread::method_type)Function }, //
00064
00065 #define END_MESSAGE_TABLE \
00066 };
00067
00068 #endif