00001
00002 #ifndef DDF_IPCPROCCOMM_HPP
00003 #define DDF_IPCPROCCOMM_HPP
00004
00005 extern "C"
00006 {
00007 #include <sys/types.h>
00008 #include <sys/ipc.h>
00009 #include <sys/msg.h>
00010 }
00011
00012 #include "infocontainer.hpp"
00013 #include "commbase.hpp"
00014 #include "ctime.hpp"
00015 #include "mbx.hpp"
00016 #include "debugging.hpp"
00017
00018 namespace jafar
00019 {
00020 namespace ddf
00021 {
00022
00027 template<typename PARENT>
00028 class CommThreadFunc
00029 {
00030 PARENT *m_par;
00031
00032 public:
00033 CommThreadFunc(PARENT *parent): m_par(parent) {}
00034 ~CommThreadFunc() {}
00035 void operator()()
00036 {
00037 time t_time = time::from_us(5);
00038 m_par->SetInitialized();
00039 JFR_VDEBUG("Listen to message queue: " << m_par->GetCommId() << "\n");
00040
00041 while(m_par->KeepRunning())
00042 {
00043 m_par->Read();
00044 t_time.sleep_period();
00045 }
00046 }
00047 };
00048
00049
00054 class IPCProcComm : public CommBase
00055 {
00056 bool m_run;
00057 unsigned long m_snd_cntr;
00058 unsigned long m_rec_cntr;
00059 boost::thread *pCommThread;
00060 CommThreadFunc<IPCProcComm> m_commFunc;
00061 int m_msgqid_send;
00062 mutable boost::mutex m_mutex;
00063 ChanFltrMsg *m_buf_send;
00064 ChanFltrMsg *m_buf_rec;
00065
00066 private:
00067 void AllocTempBuffers();
00068
00069 public:
00070 IPCProcComm(unsigned short sv_size);
00071 IPCProcComm(unsigned short sv_size, key_t key);
00072 virtual ~IPCProcComm();
00073
00074 void GetMsgQueue();
00075 void DeleteMsgQueue();
00076 CommBase::EC_STATUS Send(InfoContainer const& info);
00077 CommBase::EC_STATUS Read();
00078 bool KeepRunning() { return m_run; }
00079
00080 private:
00081 void Constructor();
00082 };
00083
00084 }
00085 }
00086 #endif