asio 0.3.8rc3 Home | Reference | Tutorial | Examples | Design
Examples

services/basic_logger.hpp

Go to the documentation of this file.
00001 //
00002 // basic_logger.hpp
00003 // ~~~~~~~~~~~~~~~~
00004 //
00005 // Copyright (c) 2003-2007 Christopher M. Kohlhoff (chris at kohlhoff dot com)
00006 //
00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00009 //
00010 
00011 #ifndef SERVICES_BASIC_LOGGER_HPP
00012 #define SERVICES_BASIC_LOGGER_HPP
00013 
00014 #include <asio.hpp>
00015 #include <boost/noncopyable.hpp>
00016 #include <string>
00017 
00018 namespace services {
00019 
00022 template <typename Service>
00023 class basic_logger
00024   : private boost::noncopyable
00025 {
00026 public:
00028   typedef Service service_type;
00029 
00031   typedef typename service_type::impl_type impl_type;
00032 
00034 
00041   explicit basic_logger(asio::io_service& io_service,
00042       const std::string& identifier)
00043     : service_(asio::use_service<Service>(io_service)),
00044       impl_(service_.null())
00045   {
00046     service_.create(impl_, identifier);
00047   }
00048 
00050   ~basic_logger()
00051   {
00052     service_.destroy(impl_);
00053   }
00054 
00056   asio::io_service& io_service()
00057   {
00058     return service_.io_service();
00059   }
00060 
00062   void use_file(const std::string& file)
00063   {
00064     service_.use_file(impl_, file);
00065   }
00066 
00068   void log(const std::string& message)
00069   {
00070     service_.log(impl_, message);
00071   }
00072 
00073 private:
00075   service_type& service_;
00076 
00078   impl_type impl_;
00079 };
00080 
00081 } // namespace services
00082 
00083 #endif // SERVICES_BASIC_LOGGER_HPP
asio 0.3.8rc3 Home | Reference | Tutorial | Examples | Design