00001 #ifndef __PROCESSTHREAD_H__
00002 #define __PROCESSTHREAD_H__
00003
00004 #include <stdint.h>
00005
00006 #include <map>
00007 #include <set>
00008 #include <utility>
00009 #include <string>
00010
00011 #include "stm_export.h"
00012 #include "threadutils.h"
00013 #include "scheduler.h"
00014 #include "modules.h"
00015
00016
00017 namespace spectral
00018 {
00019 class Processor;
00020 class Image;
00021 class Parameters;
00022 }
00023
00024
00025 namespace control
00026 {
00027
00028 class STM_EXPORT Message
00029 {
00030 public:
00031 enum Type
00032 {
00033
00034 MSG_START,
00035 MSG_STOP,
00036 MSG_SHUTDOWN,
00037 MSG_EXIT,
00038
00039
00040 MSG_SET_ACTOR,
00041 MSG_SET_INPUT,
00042
00043 MSG_PARAMETERS,
00044 MSG_SET_IMAGE,
00045 MSG_LOAD_IMAGE,
00046 MSG_SAVE_IMAGE,
00047
00048 MSG_IMAGE_LOAD_SUCCEEDED,
00049 MSG_IMAGE_LOAD_FAILED,
00050 MSG_PROGRESS,
00051 MSG_ERROR,
00052 MSG_STARTED,
00053 MSG_STOPPED,
00054 MSG_RESULT,
00055
00056 MSG_ACTOR_INSTALLED,
00057 MSG_ACTOR_REMOVED,
00058 MSG_INPUT_ADDED,
00059 MSG_INPUT_REMOVED,
00060
00061 MSG_REQUEST_PARAMETERS,
00062 MSG_REQUEST_IMAGE,
00063
00064 MSG_MAX
00065 };
00066 Message(Type type)
00067 : m_type(type)
00068 , m_id(0)
00069 , m_floatData(0)
00070 , m_image(NULL)
00071 , m_parameters(NULL)
00072 , m_link(0,0)
00073 {
00074 }
00075 Message(Type type,
00076 int id)
00077 : m_type(type)
00078 , m_id(id)
00079 , m_floatData(0)
00080 , m_image(NULL)
00081 , m_parameters(NULL)
00082 , m_link(0,0)
00083 {
00084 }
00085 Message(Type type,
00086 int id,
00087 float floatData)
00088 : m_type(type)
00089 , m_id(id)
00090 , m_floatData(floatData)
00091 , m_image(NULL)
00092 , m_parameters(NULL)
00093 , m_link(0,0)
00094 {
00095 }
00096 Message(Type type,
00097 int id,
00098 spectral::Image *image)
00099 : m_type(type)
00100 , m_id(id)
00101 , m_floatData(0)
00102 , m_image(image)
00103 , m_parameters(NULL)
00104 , m_link(0,0)
00105 {
00106 }
00107 Message(Type type,
00108 int id,
00109 spectral::Parameters *params)
00110 : m_type(type)
00111 , m_id(id)
00112 , m_floatData(0)
00113 , m_image(NULL)
00114 , m_parameters(params)
00115 , m_link(0,0)
00116 {
00117 }
00118 Message(Type type,
00119 int id,
00120 std::string string)
00121 : m_type(type)
00122 , m_id(id)
00123 , m_floatData(0)
00124 , m_image(NULL)
00125 , m_parameters(NULL)
00126 , m_string(string)
00127 , m_link(0,0)
00128 {
00129 }
00130 Message(Type type,
00131 int id,
00132 std::pair<uint32_t, int32_t> link)
00133 : m_type(type)
00134 , m_id(id)
00135 , m_floatData(0)
00136 , m_image(NULL)
00137 , m_parameters(NULL)
00138 , m_link(link)
00139 {
00140 }
00141
00142 ~Message(){};
00143
00144 Type GetType() {return m_type;}
00145 int GetId() {return m_id;}
00146 float GetFloat() {return m_floatData;}
00147 spectral::Image *GetImage() {return m_image;}
00148 spectral::Parameters *GetParameters() {return m_parameters;}
00149 std::string GetString() {return m_string;}
00150 std::pair<uint32_t, int32_t> GetLink(){return m_link;}
00151 private:
00152 Type m_type;
00153 int m_id;
00154 float m_floatData;
00155 spectral::Image *m_image;
00156 spectral::Parameters *m_parameters;
00157 std::string m_string;
00158 std::pair<uint32_t, int32_t> m_link;
00159 };
00160
00161 class STM_EXPORT MessageQueue : public thread::Fifo<Message>
00162 {
00163 };
00164
00165
00166 class STM_EXPORT ProcessThread : public thread::Thread
00167 {
00168 public:
00169 ProcessThread(int id,
00170 spectral::Processor *processor,
00171 MessageQueue &output);
00172 virtual ~ProcessThread();
00173
00174
00175 void Process(void);
00176 void Shutdown(void);
00177
00178 void SetImage(int, spectral::Image *);
00179 void SetParameters(spectral::Parameters *);
00180
00181
00182 void Progress(float);
00183
00184 protected:
00185 virtual void *MainLoop(void);
00186 private:
00187
00188 MessageQueue &m_outputQueue;
00189 MessageQueue m_inputQueue;
00190 spectral::Processor *m_processor;
00191 bool m_active;
00192 int m_id;
00193 };
00194
00195 }
00196
00197 #endif
00198