SAGA C++ API 1.6
cpr_checkpoint.cpp
Go to the documentation of this file.
00001 #if defined(__WAVE__)
00002 #pragma wave option(preserve: 2, line: 1, output: "preprocessed/cpr_checkpoint.cpp")
00003 #endif
00004 //  Copyright (c) 2005-2009 Hartmut Kaiser
00005 //  Copyright (c) 2008 Andre Merzky (andre@merzky.net)
00006 // 
00007 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
00008 //  job LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00009 
00010 #if defined(__WAVE__)
00011 #pragma wave option(output: null)
00012 #endif
00013 
00014 //  this is needed in every file including detail/attribute_impl.hpp and not 
00015 //  belonging to the engine
00016 #define SAGA_NO_IMPORT_ATTRIBUTE
00017 #define SAGA_EXPORT_ATTRIBUTE       SAGA_CPR_PACKAGE_EXPORT
00018 
00019 #include <saga/saga/task.hpp>
00020 
00021 // include file API and implementation
00022 #include <saga/saga/cpr.hpp>
00023 #include <saga/impl/cpr.hpp>
00024 #include <saga/saga/detail/call.hpp>
00025 
00026 #include <boost/assign/list_inserter.hpp>
00027 #include <boost/assign/std/vector.hpp>
00028 
00029 #include <saga/saga/detail/attribute_impl.hpp>
00030 
00031 #ifdef SAGA_DEBUG
00032 #include <saga/saga/packages/filesystem/preprocessed/cpr_checkpoint.cpp>
00033 #else
00034 
00035 #if defined(__WAVE__)
00036 #pragma wave option(preserve: 2, line: 1, output: "preprocessed/cpr_checkpoint.cpp")
00037 #endif
00038 
00039 namespace saga 
00040 {
00041     namespace cpr 
00042     {
00043         namespace metrics
00044         {
00046             saga::metrics::init_data const checkpoint_metric_data[] = 
00047             {
00048                 // cpr_checkpoint specific metrics
00049                 {
00050                     checkpoint_modified,
00051                     "Metric fires on checkpoint changes, it carries the key of"
00052                     "the modified checkpoint file.",
00053                     saga::attributes::metric_mode_readonly,
00054                     "1", 
00055                     saga::attributes::metric_type_string,
00056                     ""
00057                 },
00058                 {
00059                     checkpoint_deleted,
00060                     "Metric fires on checkpoint deletes, it carries the key of" 
00061                     "the deleted checkpoint file.",
00062                     saga::attributes::metric_mode_readonly,
00063                     "1", 
00064                     saga::attributes::metric_type_string,
00065                     ""
00066                 },
00067             };
00069             
00070         } // namespace metrics
00071 
00072         checkpoint::checkpoint (session const& s, saga::url url, int mode)
00073         :   entry (new saga::impl::cpr_checkpoint (s, url, mode))
00074         {
00075             // initialize attribute implementation
00076             this->attribute_base::init (true);    // no constraints on attributes
00077 
00078             // initialize implementation object
00079             this->saga::object::get_impl()->init();
00080 
00081             // initialize metrics
00082             std::vector<saga::metric> metrics;
00083             for (unsigned int i = 0; 
00084                  i < sizeof(saga::cpr::metrics::checkpoint_metric_data)/sizeof(saga::metrics::init_data);
00085                  ++i)
00086             {
00087                 saga::metrics::init_data const* p = &saga::cpr::metrics::checkpoint_metric_data[i];
00088                 saga::metric m(*this, p->name, p->description, p->mode, p->unit, 
00089                                p->type, p->value);
00090                 metrics.push_back(m);
00091             }
00092             this->monitorable_base::init (metrics);
00093 
00094             // initialize attributes
00095             using namespace boost::assign;
00096             std::vector<std::string> valid_keys;
00097             valid_keys += 
00098                     attributes::cpr_time,
00099                     attributes::cpr_nfliles,
00100                     attributes::cpr_mode,
00101                     attributes::cpr_parent,
00102                     attributes::cpr_children
00103                 ;
00104 
00105             // initialize list of valid keys
00106             this->init_keynames (valid_keys);
00107 
00108             strmap_type attributes_scalar_rw;
00109             insert(attributes_scalar_rw)
00110                     (attributes::cpr_time, "")
00111                     (attributes::cpr_nfliles, "")
00112                     (attributes::cpr_mode, "")
00113                     (attributes::cpr_parent, "")
00114                     (attributes::cpr_children, "")
00115                 ;
00116 
00117             // initialize attribute implementation
00118             this->attribute_base::init (strmap_type(), attributes_scalar_rw);
00119             this->attribute_base::init (false, true);   // cache only implementation
00120         }
00121 
00122         checkpoint::checkpoint (saga::url url, int mode)
00123         :   entry (new saga::impl::cpr_checkpoint (detail::get_the_session (), url, mode))
00124         {
00125             // initialize attribute implementation
00126             this->attribute_base::init (true);    // no constraints on attributes
00127 
00128             // initialize implementation object
00129             this->saga::object::get_impl()->init();
00130 
00131             // initialize metrics
00132             std::vector<saga::metric> metrics;
00133             for (unsigned int i = 0; 
00134                  i < sizeof(saga::cpr::metrics::checkpoint_metric_data)/sizeof(saga::metrics::init_data);
00135                  ++i)
00136             {
00137                 saga::metrics::init_data const* p = &saga::cpr::metrics::checkpoint_metric_data[i];
00138                 saga::metric m(*this, p->name, p->description, p->mode, p->unit, 
00139                                p->type, p->value);
00140                 metrics.push_back(m);
00141             }
00142 
00143             this->monitorable_base::init (metrics);
00144 
00145             // initialize attributes
00146             using namespace boost::assign;
00147             std::vector<std::string> valid_keys;
00148             valid_keys += 
00149                     attributes::cpr_time,
00150                     attributes::cpr_nfliles,
00151                     attributes::cpr_mode,
00152                     attributes::cpr_parent,
00153                     attributes::cpr_children
00154                 ;
00155 
00156             // initialize list of valid keys
00157             this->init_keynames (valid_keys);
00158 
00159             strmap_type attributes_scalar_rw;
00160             insert(attributes_scalar_rw)
00161                     (attributes::cpr_time, "")
00162                     (attributes::cpr_nfliles, "")
00163                     (attributes::cpr_mode, "")
00164                     (attributes::cpr_parent, "")
00165                     (attributes::cpr_children, "")
00166                 ;
00167 
00168             // initialize attribute implementation
00169             this->attribute_base::init (strmap_type(), attributes_scalar_rw);
00170             this->attribute_base::init (false, true);   // cache only implementation
00171         }
00172 
00173         checkpoint::checkpoint(saga::object const& o)
00174         : entry(o)
00175         {
00176             if (this->get_type() != saga::object::CPRCheckpoint)
00177             {
00178                 SAGA_THROW("Bad type conversion.", saga::BadParameter);
00179             }
00180         }
00181 
00182         checkpoint::checkpoint (void) 
00183         {
00184         }
00185 
00186         checkpoint::checkpoint(saga::impl::cpr_checkpoint *impl)
00187         : entry (impl)
00188         {
00189         }
00190 
00191         checkpoint::~checkpoint (void)
00192         {
00193         }
00194 
00195         checkpoint &checkpoint::operator= (saga::object const& o)
00196         {
00197             return this->saga::name_space::entry::operator=(o), *this;
00198         }
00199 
00200         saga::impl::cpr_checkpoint* checkpoint::get_impl() const
00201         { 
00202             typedef saga::object base_type;
00203             return static_cast<saga::impl::cpr_checkpoint*>(this->base_type::get_impl()); 
00204         }
00205 
00206         TR1::shared_ptr <saga::impl::cpr_checkpoint> checkpoint::get_impl_sp(void) const
00207         { 
00208             // FIXME: this needs documentation
00209             typedef saga::object base_type;
00210             return TR1::static_pointer_cast <saga::impl::cpr_checkpoint> (
00211                 this->base_type::get_impl_sp());
00212         }
00213 
00215         // factory
00216         SAGA_CALL_CREATE_IMP_3(checkpoint, impl::cpr_checkpoint, session const&, saga::url, int)
00217 
00218         SAGA_CALL_IMP_2    (checkpoint, set_parent,                   saga::url, int);
00219         SAGA_CALL_IMP_1    (checkpoint, get_parent,                   int);
00220         SAGA_CALL_IMP_0    (checkpoint, get_file_num);
00221         SAGA_CALL_IMP_0    (checkpoint, list_files);
00222         SAGA_CALL_IMP_1    (checkpoint, add_file,                     saga::url);
00223         SAGA_CALL_IMP_1    (checkpoint, get_file,                     int);
00224         SAGA_CALL_IMP_2    (checkpoint, open_file,                    saga::url, int);
00225         SAGA_CALL_IMP_2_EX (checkpoint, open_file,   open_file_idx,   int,       int);
00226         SAGA_CALL_IMP_1    (checkpoint, remove_file,                  saga::url);
00227         SAGA_CALL_IMP_1_EX (checkpoint, remove_file, remove_file_idx, int);
00228         SAGA_CALL_IMP_2    (checkpoint, update_file,                  saga::url, saga::url);
00229         SAGA_CALL_IMP_2_EX (checkpoint, update_file, update_file_idx, int,       saga::url);
00230         SAGA_CALL_IMP_2    (checkpoint, stage_file,                   saga::url, saga::url);
00231         SAGA_CALL_IMP_2_EX (checkpoint, stage_file,  stage_file_idx,  int,       saga::url);
00232         SAGA_CALL_IMP_1_EX (checkpoint, stage_file,  stage_file_all,  saga::url);
00234         
00235     }   // namespace cpr
00236 
00237     namespace detail
00238     {
00240         //  implement the attribute functions (we need to explicitly specialize 
00241         //  the template because the functions are not implemented inline)
00242         template struct SAGA_CPR_PACKAGE_EXPORT_REPEAT attribute<cpr::checkpoint>;
00243 
00244         template struct SAGA_CPR_PACKAGE_EXPORT attribute_priv<cpr::checkpoint, task_base::Sync>;
00245         template struct SAGA_CPR_PACKAGE_EXPORT attribute_priv<cpr::checkpoint, task_base::Async>;
00246         template struct SAGA_CPR_PACKAGE_EXPORT attribute_priv<cpr::checkpoint, task_base::Task>;
00247 
00248         template struct SAGA_CPR_PACKAGE_EXPORT attribute_sync<cpr::checkpoint>;
00249     }
00250 
00252 } // namespace saga
00253 
00254 #endif
00255 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines