C:/Development/boost_sandbox/rpc/boost/rpc/registry.hpp

00001 // Copyright Stjepan Rajko 2007. Use, modification and
00002 // distribution is subject to the Boost Software License, Version
00003 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
00004 // http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 #ifndef BOOST_RPC_REGISTRY_HPP
00007 #define BOOST_RPC_REGISTRY_HPP
00008 
00009 #include <boost/ptr_container/ptr_map.hpp>
00010 #include <boost/call_traits.hpp>
00011 #include <boost/rpc/function.hpp>
00012 #include <boost/rpc/marshaled.hpp>
00013 
00014 namespace boost {
00015 namespace rpc {
00016 
00018 
00022 template<typename Id, typename ArchivePair = binary_archive>
00023 class registry
00024 {
00025 public:
00026     typedef Id id_type;
00027     typedef ArchivePair archive_type;
00028 
00030 
00035     template<typename Signature>
00036     void set(Id id, const boost::function<Signature> &f)
00037     {
00038        reg.insert(id, new marshaled<Signature>(f));
00039     }
00040 
00042 
00046     void operator()(const std::string &id_and_params, const call_options &options,
00047         std::string *result = NULL)
00048     {
00049         // prepare input archive to extract id and parameters
00050         std::stringstream p_stream(id_and_params, std::ios::in | std::ios::out | std::ios::binary);
00051         typename archive_type::iarchive_type p_archive(p_stream);
00052        
00053         id_type id;
00054         p_archive & id;
00055      
00056         // make the call
00057         if (options.marshal_option >= call_options::return_only)
00058         {
00059             BOOST_ASSERT(result);
00060             std::stringstream r_stream(std::ios::in | std::ios::out | std::ios::binary);
00061                 typename archive_type::oarchive_type r_archive(r_stream);
00062             reg[id].call(options, p_archive, &r_archive);
00063             *result = r_stream.str();
00064         }
00065         else
00066             reg[id].call(options, p_archive, NULL);
00067     }
00068 private:
00070     boost::ptr_map<Id, detail::function<ArchivePair> > reg;
00071 };
00072 
00073 } // namespace rpc
00074 } // namespace boost
00075 
00076 #endif // BOOST_RPC_REGISTRY_HPP

Generated on Sun May 20 15:47:56 2007 by  doxygen 1.5.2