SAGA C++ API 1.6
context.cpp
Go to the documentation of this file.
00001 //  Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net)
00002 //  Copyright (c) 2005-2009 Hartmut Kaiser
00003 // 
00004 //  Use, modification and distribution is subject to the Boost Software
00005 //  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
00006 //  http://www.boost.org/LICENSE_1_0.txt)
00007 
00008 #include <boost/config.hpp>
00009 #include <boost/lexical_cast.hpp>   // lexical_cast will be in TR2
00010 
00011 #include <saga/saga/exception.hpp>
00012 #include <saga/saga/context.hpp>
00013 
00014 #include <saga/impl/context.hpp>
00015 #include <saga/impl/engine/object.hpp>
00016 #include <saga/impl/engine/proxy.hpp>
00017 #include <saga/impl/engine/metric.hpp>
00018 
00019 #include <saga/saga/detail/attribute_impl.hpp>
00020 
00021 #include <boost/assign/std/vector.hpp>
00022 
00024 namespace saga 
00025 {
00026 //   namespace detail
00027 //   {
00028 //     ///@cond
00029 //       std::string get_userid()
00030 //       {
00031 // #if defined(BOOST_WINDOWS)
00032 //           char chBuffer[MAX_PATH + 1];
00033 //           DWORD cchBuff = sizeof(chBuffer)-1;
00034 //           GetUserName (chBuffer, &cchBuff);     // Get and display the user name.
00035 //           return chBuffer;
00036 // #else
00037 //           return boost::lexical_cast<std::string>(getuid());
00038 // #endif
00039 //       }
00040 //     ///@endcond
00041 //   }
00042   
00044   context::context (std::string const& ctxtype) 
00045     : saga::object (new impl::context())
00046   {
00047       using namespace boost::assign;
00048 
00049       std::vector<std::string> valid_keys;
00050       valid_keys += 
00051           attributes::context_type,
00052           attributes::context_server,
00053           attributes::context_certrepository,
00054           attributes::context_userproxy,
00055           attributes::context_usercert,
00056           attributes::context_userkey,
00057           attributes::context_userid,
00058           attributes::context_userpass,
00059           attributes::context_uservo,
00060           attributes::context_lifetime,
00061           attributes::context_remoteid, 
00062           attributes::context_remotehost,
00063           attributes::context_remoteport;
00064       this->init_keynames(valid_keys);
00065 
00066       // initialize this context if the type is given
00067       strmap_type attributes_scalar_rw;
00068       insert(attributes_scalar_rw)
00069               (attributes::context_type, ctxtype)
00070               (attributes::context_server, "")
00071               (attributes::context_certrepository, "")
00072               (attributes::context_userproxy, "")
00073               (attributes::context_usercert, "")
00074               (attributes::context_userkey, "")
00075               (attributes::context_userid, "")
00076               (attributes::context_userpass, "")
00077               (attributes::context_uservo, "")
00078               (attributes::context_lifetime, "")
00079               (attributes::context_remoteid, "")
00080               (attributes::context_remotehost, "")
00081               (attributes::context_remoteport, "")
00082           ;
00083 
00084       // initialize attribute implementation
00085       this->init(strmap_type(), attributes_scalar_rw);
00086 
00087       // FIXME: attribute_cache only
00088       // making this not cache only may lead to infinite recursions while
00089       // the default session is initialized
00090       this->init(true, true);
00091 
00092 // This has been removed as per latest Spec errata, has been moved to 
00093 // session::add_context
00094 //       if (!ctxtype.empty()) {
00095 //       // initialize the context
00096 //           get_impl()->set_defaults(true);
00097 //       }
00098 
00099       // initialize implementation object
00100       if (!ctxtype.empty()) 
00101           this->saga::object::get_impl()->init();
00102   }
00103 
00104   context::context(saga::impl::context *impl)
00105     : saga::object(impl)
00106   {
00107   }
00108   context::context (TR1::shared_ptr<saga::impl::context> init)
00109     : saga::object(init)
00110   {
00111   }
00112 
00113   context::context(saga::object const& obj)
00114     : saga::object (obj)
00115   {
00116       if (this->get_type() != saga::object::Context)
00117       {
00118           SAGA_THROW("Bad type conversion.", saga::BadParameter);
00119       }
00120   }
00121   context& context::operator=(saga::object const& obj)
00122   {
00123       saga::object::operator=(obj);
00124       if (this->get_type() != saga::object::Context)
00125       {
00126           SAGA_THROW("Bad type conversion.", saga::BadParameter);
00127       }
00128       return *this;
00129   }
00130   
00131   context::~context (void)
00132   {
00133   }
00134 
00135   saga::impl::context* context::get_impl (void) const
00136   { 
00137     typedef saga::object base_type;
00138     return static_cast<saga::impl::context*>(this->base_type::get_impl());
00139   }
00140 
00141   TR1::shared_ptr <saga::impl::context> context::get_impl_sp(void) const
00142   { 
00143     typedef saga::object base_type;
00144     return TR1::static_pointer_cast<saga::impl::context>(
00145         this->base_type::get_impl_sp());
00146   }
00147 
00148 // has been removed as of newest SAGA spec
00149 //   void context::set_defaults()
00150 //   {
00151 //       get_impl()->set_defaults(true);
00152 //   }
00153 
00155 
00156   bool operator== (context const & lhs, context const & rhs)
00157   {
00158       return lhs.get_impl()->is_equal(rhs.get_impl()); 
00159   }
00161 
00162   namespace detail
00163   {
00165     //  implement the attribute functions (we need to explicitly specialize 
00166     //  the template because the functions are not implemented inline)
00167     template struct SAGA_EXPORT_REPEAT attribute<context>;
00168 
00169     template struct SAGA_EXPORT attribute_priv<context, task_base::Sync>;
00170     template struct SAGA_EXPORT attribute_priv<context, task_base::Async>;
00171     template struct SAGA_EXPORT attribute_priv<context, task_base::Task>;
00172 
00173     template struct SAGA_EXPORT attribute_sync<context>;
00174   }
00175 
00177 } // namespace saga 
00178 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines