Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <boost/assign/list_of.hpp>
00010 #include <boost/assign/list_inserter.hpp>
00011 #include <boost/assign/std/vector.hpp>
00012
00013 #include <saga/saga/metric.hpp>
00014 #include <saga/impl/engine/metric.hpp>
00015 #include <saga/impl/engine/context_base.hpp>
00016
00017 #include <saga/saga/detail/attribute_impl.hpp>
00018
00020 namespace saga
00021 {
00022
00023 metric::metric (void)
00024 : saga::object (new saga::impl::metric ())
00025 {
00026 }
00027
00028 metric::metric (saga::impl::metric *impl)
00029 : saga::object (impl)
00030 {
00031 }
00032
00033 metric::metric (saga::object target,
00034 std::string name, std::string desc, std::string mode,
00035 std::string unit, std::string type, std::string val)
00036 : saga::object (new saga::impl::metric(target))
00037 {
00038 if (mode != attributes::metric_mode_readonly &&
00039 mode != attributes::metric_mode_readwrite &&
00040 mode != attributes::metric_mode_final)
00041 {
00042 SAGA_THROW("metric::metric: bad 'mode' parameter", BadParameter);
00043 }
00044
00045
00046 std::map <std::string, std::string> attributes_scalar_ro;
00047 std::map <std::string, std::string> attributes_scalar_rw;
00048 std::vector<std::string> valid_keys;
00049
00050
00051 using namespace boost::assign;
00052
00053 valid_keys +=
00054 attributes::metric_name,
00055 attributes::metric_description,
00056 attributes::metric_mode,
00057 attributes::metric_unit,
00058 attributes::metric_type,
00059 attributes::metric_value
00060 ;
00061 this->init_keynames(valid_keys);
00062
00063 insert(attributes_scalar_ro)
00064 (attributes::metric_name, name)
00065 (attributes::metric_description, desc)
00066 (attributes::metric_mode, mode)
00067 (attributes::metric_unit, unit)
00068 (attributes::metric_type, type);
00069
00070 if (mode != attributes::metric_mode_readwrite)
00071 {
00072 insert(attributes_scalar_ro) (attributes::metric_value, val);
00073 }
00074 else
00075 {
00076 insert(attributes_scalar_rw) (attributes::metric_value, val);
00077 }
00078
00079
00080 this->init (attributes_scalar_ro, attributes_scalar_rw);
00081 this->init (false, true);
00082 }
00083
00084 metric::~metric (void)
00085 {
00086 }
00087
00089 metric::metric (saga::object const& o)
00090 : saga::object (o)
00091 {
00092 if (this->get_type() != saga::object::Metric)
00093 {
00094 SAGA_THROW("Bad type conversion.", saga::BadParameter);
00095 }
00096 }
00097
00098 metric &metric::operator= (saga::object const& o)
00099 {
00100 saga::object::operator=(o);
00101 if (this->get_type() != saga::object::Metric)
00102 {
00103 SAGA_THROW("Bad type conversion.", saga::BadParameter);
00104 }
00105 return *this;
00106 }
00107
00109 saga::impl::metric* metric::get_impl (void) const
00110 {
00111 typedef saga::object base_type;
00112 return static_cast<saga::impl::metric*>(this->base_type::get_impl());
00113 }
00114
00115 TR1::shared_ptr <saga::impl::metric> metric::get_impl_sp (void) const
00116 {
00117 typedef saga::object base_type;
00118 return TR1::static_pointer_cast<saga::impl::metric>(
00119 this->base_type::get_impl_sp());
00120 }
00121
00123
00124 bool operator== (metric const & lhs,
00125 metric const & rhs)
00126 {
00127 return (lhs.get_impl() == rhs.get_impl());
00128 }
00130
00131 metric::metric_cookie
00132 metric::add_callback(saga::callback f)
00133 {
00134 return get_impl()->add_callback(f);
00135 }
00136
00137 void metric::remove_callback(metric_cookie cookie)
00138 {
00139 get_impl()->remove_callback(cookie);
00140 }
00141
00142 void metric::fire (saga::context ctx)
00143 {
00144 std::string mode (get_attribute(saga::attributes::metric_mode));
00145 if (mode == saga::attributes::metric_mode_readonly)
00146 {
00147 std::string name(get_attribute(saga::attributes::metric_name));
00148 SAGA_THROW("Metric: '" + name + "' is readonly.", saga::PermissionDenied);
00149 }
00150 get_impl()->fire (ctx);
00151 }
00152
00153 namespace detail
00154 {
00156
00157
00158 template struct SAGA_EXPORT_REPEAT attribute<metric>;
00159
00160 template struct SAGA_EXPORT attribute_priv<metric, task_base::Sync>;
00161 template struct SAGA_EXPORT attribute_priv<metric, task_base::Async>;
00162 template struct SAGA_EXPORT attribute_priv<metric, task_base::Task>;
00163
00164 template struct SAGA_EXPORT attribute_sync<metric>;
00165 }
00166
00168 }
00169