00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _CJNETWORKPROCESS_H_
00021 #define _CJNETWORKPROCESS_H_ 1
00022
00023 #include <string>
00024 #include <stdexcept>
00025 #include "CjNLTopology.hh"
00026 #include "CjMatrix.hh"
00027 #include "CjNetworkProcessException.hh"
00028 #include <boost/random.hpp>
00029 #include "CjVisitorFactory.hh"
00030
00031 namespace jmitie {
00032
00033 class CjNodeSelector;
00034 class CjLinkSelector;
00035 class CjNetworkDimensioner;
00036
00038
00040 struct CjNetworkProcess_ctor_va_t {
00041 typedef CjVisitorFactory< CjVisitorFactoryEntry< CjNetworkDimensioner > > CjDimFactory_t;
00042 typedef CjVisitorFactory< CjVisitorFactoryEntry< CjNodeSelector > > CjNodeSelectorFactory_t;
00043 typedef CjVisitorFactory< CjVisitorFactoryEntry< CjLinkSelector > > CjLinkSelectorFactory_t;
00044
00046 CjDimFactory_t & m_dim_fac;
00048 CjNodeSelectorFactory_t & m_nodsel_fac;
00050 CjLinkSelectorFactory_t & m_lnksel_fac;
00051
00053 boost::mt19937 * m_rng;
00055 CjNLTopology * m_top;
00056
00057 CjNetworkProcess_ctor_va_t(CjDimFactory_t & dim_fac, CjNodeSelectorFactory_t & nodsel_fac, CjLinkSelectorFactory_t & lnksel_fac, \
00058 boost::mt19937 * rng, CjNLTopology * top ): \
00059 m_dim_fac(dim_fac), \
00060 m_nodsel_fac(nodsel_fac), \
00061 m_lnksel_fac(lnksel_fac), \
00062 m_rng(rng), \
00063 m_top(top) {}
00064 };
00065
00067
00069 struct CjNetworkProcess_act_va_t {
00071 boost::mt19937 * m_rng;
00073 int m_epoch;
00074
00075 CjNetworkProcess_act_va_t(boost::mt19937 * rng, int epoch ):m_rng(rng),m_epoch(epoch) {}
00076 };
00077
00078
00089 class CjNetworkProcess {
00090
00091
00092
00093 public:
00094 typedef CjNetworkProcess_ctor_va_t ctor_va_t;
00095 typedef CjNetworkProcess_act_va_t action_va_t;
00096
00098 CjNetworkProcess(std::string args, ctor_va_t va):m_orig_args(args),m_cmd(args),m_start(0),m_lifetime(0),m_step(1),m_priority(0),m_atEnd( parseEpochs(m_cmd, m_name, m_start, m_lifetime, m_step, m_priority ) ),m_top(va.m_top) {
00099 JLOG(4, std::cout << "CjNetworkProcess(std::string args): Timing parsed as: args = \"" << args << "\" start = " << m_start << " lifetime = " << m_lifetime << " step = " << m_step << " prio = " << m_priority << " atEnd = " << m_atEnd << std::endl; )
00100 }
00101
00102
00104 virtual bool activeEpoch (const unsigned int t) const { return ( (t>=m_start) && ( (m_lifetime==0) || (t<(m_start+m_lifetime)) ) && ((t-m_start)%m_step==0) ); }
00106 virtual bool expiredPolicy (const unsigned int t) const { return ((m_lifetime==0)?false:( t>(m_start+m_lifetime))); }
00107
00108 virtual unsigned int getStartEpoch() const { return m_start; }
00109 virtual unsigned int getLifetime() const { return m_lifetime; }
00110 virtual unsigned int getEpochStep() const { return m_step; }
00111 virtual unsigned int getProcessPriority() const { return m_priority; }
00112 virtual bool atEnd() const { return m_atEnd; }
00113
00114
00116 static std::string getName_static() { throw std::logic_error("CjNetworkProcess::getName_static() called."); }
00118 static std::string getProperty_static(const std::string &) { throw std::logic_error("CjNetworkProcess::getProperty_static(..) called."); }
00120
00121 virtual std::string getName() const = 0;
00123 virtual std::string getProperty (const std::string &) const = 0;
00124
00126 virtual std::string toString() const { return m_orig_args; }
00128 virtual std::string getCmd() const { return m_cmd; }
00129
00131 virtual void performAction( const action_va_t & opts ) = 0;
00132 virtual ~CjNetworkProcess() = 0;
00133
00134 static std::string getProcName( const std::string & instr );
00136
00140 static bool parseEpochs( std::string & instr, std::string & proc_name, unsigned int & start, unsigned int & lifetime, unsigned int & step, unsigned int & prio );
00141
00142 protected:
00144 std::string m_orig_args;
00146 std::string m_cmd;
00148 std::string m_name;
00149
00151 unsigned int m_start;
00153 unsigned int m_lifetime;
00155 unsigned int m_step;
00157 unsigned int m_priority;
00159 bool m_atEnd;
00160
00162 CjNLTopology * m_top;
00163
00164 private:
00165
00166 };
00167
00168 }
00169
00170 #endif // _CJNETWORKPROCESS_H_