Пример #1
0
    void send_bad_response(
        http::status status,
        std::string const& error)
    {
        string_response_.emplace(
            std::piecewise_construct,
            std::make_tuple(),
            std::make_tuple(alloc_));

        string_response_->result(status);
        string_response_->keep_alive(false);
        string_response_->set(http::field::server, "Beast");
        string_response_->set(http::field::content_type, "text/plain");
        string_response_->body() = error;
        string_response_->prepare_payload();

        string_serializer_.emplace(*string_response_);

        http::async_write(
            socket_,
            *string_serializer_,
            [this](boost::beast::error_code ec, std::size_t)
            {
                socket_.shutdown(tcp::socket::shutdown_send, ec);
                string_serializer_.reset();
                string_response_.reset();
                accept();
            });
    }
Пример #2
0
			data_type operator() (object_type *object, const std::string &title) {
				if (!data_) {
					data_type tmp;
					if (fetch_data(object, tmp, title))
						data_.reset(tmp);
					else
						data_.reset(traits::get_default());
				}
				return *data_;
			}
Пример #3
0
    void send_file(boost::beast::string_view target)
    {
        // Request path must be absolute and not contain "..".
        if (target.empty() || target[0] != '/' || target.find("..") != std::string::npos)
        {
            send_bad_response(
                http::status::not_found,
                "File not found\r\n");
            return;
        }

        std::string full_path = doc_root_;
        full_path.append(
            target.data(),
            target.size());

        http::file_body::value_type file;
        boost::beast::error_code ec;
        file.open(
            full_path.c_str(),
            boost::beast::file_mode::read,
            ec);
        if(ec)
        {
            send_bad_response(
                http::status::not_found,
                "File not found\r\n");
            return;
        }

        file_response_.emplace(
            std::piecewise_construct,
            std::make_tuple(),
            std::make_tuple(alloc_));

        file_response_->result(http::status::ok);
        file_response_->keep_alive(false);
        file_response_->set(http::field::server, "Beast");
        file_response_->set(http::field::content_type, mime_type(target.to_string()));
        file_response_->body() = std::move(file);
        file_response_->prepare_payload();

        file_serializer_.emplace(*file_response_);

        http::async_write(
            socket_,
            *file_serializer_,
            [this](boost::beast::error_code ec, std::size_t)
            {
                socket_.shutdown(tcp::socket::shutdown_send, ec);
                file_serializer_.reset();
                file_response_.reset();
                accept();
            });
    }
Пример #4
0
	void SetLuaBatchThread(bool set) {
		if (set) {
			luaBatchThreadID = Threading::GetCurrentThreadId();
		} else {
			luaBatchThreadID.reset();
		}
	}
Пример #5
0
static bool handle_move_to()
{
    while( input->ready() || ( std::cin.good() && !std::cin.eof() ) )
    {
        if( differential )
        {
            const position* position = input->read();
            if( !position ) { return true; }
            return handle_move_to< quickset::ptcr::commands::move_to_delta >( *position );
        }
        else
        {
            if( !target )
            {
                const position* position = input->read();
                if( !position ) { return true; }
                target = *position;
            }
            if( !handle_move_to< quickset::ptcr::commands::move_to >( *target ) ) { return false; }
            target.reset();
            return true;
        }
    }
    return true;
}
Пример #6
0
	void SetSimThread(bool set) {
		if (set) {
			simThreadID = Threading::GetCurrentThreadId();
			luaBatchThreadID = simThreadID;
		} else {
			simThreadID.reset();
		}
	}
Пример #7
0
  // utility functions; require a lock to already be taken
  // and the container to already be full/empty as applicable.
  // Use these functions everywhere that modifies contents_.
  void preconditions_hold_put_(value_type const& v) {
    if(LASERCAKE_NO_THREADS) {
      caller_error_if(contents_, "'put' into a full m_var in single-threaded mode blocks.");
    }
    contents_.reset(v);
#if !LASERCAKE_NO_THREADS
    readers_wait_on_.notify_one();
#endif
  }
Пример #8
0
    void                get( cstring string_id, boost::optional<T>& res ) const
    {
        const_argument_ptr arg = (*this)[string_id];

        if( arg )
            res = arg_value<T>( *arg );
        else
            res.reset();
    }
Пример #9
0
  value_type preconditions_hold_take_() {
    if(LASERCAKE_NO_THREADS) {
      caller_error_if(!contents_, "'take' from an empty m_var in single-threaded mode blocks.");
    }
    value_type result = contents_.get();
    contents_.reset();
#if !LASERCAKE_NO_THREADS
    writers_wait_on_.notify_one();
#endif
    return result;
  }
Пример #10
0
 static inline void to_ds_type(mapnik::geometry_container const& paths,
                 boost::optional<mapnik::datasource::geometry_t> & result)
 {
     if (paths.size() == 1)
     {
         result.reset(static_cast<mapnik::datasource::geometry_t>(paths.front().type()));
     }
     else if (paths.size() > 1)
     {
         int multi_type = 0;
         for (auto const& geom : paths)
         {
             int type = static_cast<int>(geom.type());
             if (multi_type > 0 && multi_type != type)
             {
                 result.reset(datasource::Collection);
             }
             multi_type = type;
             result.reset(static_cast<mapnik::datasource::geometry_t>(type));
         }
     }
 }
Пример #11
0
void load(
    Archive & ar, 
    boost::optional<T> & t, 
    const unsigned int /*version*/
){
    bool tflag;
    ar >> boost::serialization::make_nvp("initialized", tflag);
    if (tflag){
        stack_construct<Archive, T> aux(ar);
        ar >> boost::serialization::make_nvp("value", aux.reference());
        t.reset(aux.reference());
    }
    else {
Пример #12
0
    virtual void onFrame        (const Leap::Controller&)
    {
        const Leap::Frame frame(m_Controller.frame(0));
        const Leap::Hand hand(frame.hands().rightmost());
        if (!hand.isValid())
        {
            m_LastNormalizedPos.reset();
            return;
        }

        const Leap::Vector pos(hand.palmPosition());
        m_LastNormalizedPos = frame.interactionBox().normalizePoint(pos);
    }
Пример #13
0
static block_t* read_block_impl_( ::tbb::flow_control* flow = NULL )
{
    static boost::array< block_t, 3 > blocks;
    static boost::optional< block_t::pair_t > last;
    static comma::uint32 block_id = 0;
    block_t::pairs_t* points = new block_t::pairs_t;
    while( true ) // quick and dirty, only if --discard
    {
        static comma::csv::input_stream< input_t > istream( std::cin, csv );
        points->clear();
        while( true )
        {
            if( last )
            {
                block_id = last->first.block;
                points->push_back( *last );
                last.reset();
            }
            if( is_shutdown || std::cout.bad() || std::cin.bad() || std::cin.eof() )
            {
                if( bursty_reader ) { bursty_reader->stop(); } // quick and dirty, it sucks...
                if( flow ) { flow->stop(); }
                break;
            }
            const input_t* p = istream.read();
            if( !p ) { break; }
            std::string line;
            if( csv.binary() )
            {
                line.resize( csv.format().size() );
                ::memcpy( &line[0], istream.binary().last(), csv.format().size() );
            }
            else
            {
                line = comma::join( istream.ascii().last(), csv.delimiter );
            }
            last = std::make_pair( *p, line );
            if( p->block != block_id ) { break; }
        }
        for( unsigned int i = 0; i < blocks.size(); ++i )
        {
            if( !blocks[i].empty ) { continue; }
            blocks[i].clear();
            blocks[i].id = block_id;
            blocks[i].points.reset( points );
            blocks[i].empty = false;
            return &blocks[i];
        }
    }
}
Пример #14
0
 void to_ds_type(mapnik::geometry_container const& paths,
                 boost::optional<mapnik::datasource::geometry_t> & result)
 {
     if (paths.size() == 1)
     {
         result.reset(static_cast<mapnik::datasource::geometry_t>(paths.front().type()));
     }
     else if (paths.size() > 1)
     {
         int multi_type = 0;
         geometry_container::const_iterator itr = paths.begin();
         geometry_container::const_iterator end = paths.end();
         for ( ; itr!=end; ++itr)
         {
             int type = static_cast<int>(itr->type());
             if (multi_type > 0 && multi_type != type)
             {
                 result.reset(datasource::Collection);
             }
             multi_type = type;
             result.reset(static_cast<mapnik::datasource::geometry_t>(type));
         }
     }
 }
Пример #15
0
void load(
    Archive & ar, 
    boost::optional<T> & t, 
    const unsigned int /*version*/
){
    bool tflag;
    ar >> boost::serialization::make_nvp("initialized", tflag);
    if (tflag){
        unsigned int v = 0;
        if(3 < ar.get_library_version()){
            ar >> boost::serialization::make_nvp("item_version", v);
        }
        detail::stack_construct<Archive, T> aux(ar, v);
        ar >> boost::serialization::make_nvp("value", aux.reference());
        t.reset(aux.reference());
    }
Пример #16
0
void load(
    Archive & ar,
    boost::optional< T > & t,
    const unsigned int version
){
    bool tflag;
    ar >> boost::serialization::make_nvp("initialized", tflag);
    if(! tflag){
        t.reset();
        return;
    }

    if(0 == version){
        boost::serialization::item_version_type item_version(0);
        boost::archive::library_version_type library_version(
            ar.get_library_version()
        );
        if(boost::archive::library_version_type(3) < library_version){
            ar >> BOOST_SERIALIZATION_NVP(item_version);
        }
Пример #17
0
void load(
    Archive & ar, 
    boost::optional< T > & t, 
    const unsigned int /*version*/
){
    bool tflag;
    ar >> boost::serialization::make_nvp("initialized", tflag);
    if (tflag){
        boost::serialization::item_version_type item_version(0);
        boost::archive::library_version_type library_version(
            ar.get_library_version()
        );
        if(boost::archive::library_version_type(3) < library_version){
            // item_version is handled as an attribute so it doesnt need an NVP
           ar >> BOOST_SERIALIZATION_NVP(item_version);
        }
        detail::stack_construct<Archive, T> aux(ar, item_version);
        ar >> boost::serialization::make_nvp("value", aux.reference());
        t.reset(aux.reference());
    }
Пример #18
0
 typename command::response readresponse()
 {
     while( true )
     {
         if( !readpacket() ) { COMMA_THROW( comma::exception, "expected command response, got end of stream" ); }
         switch( m_header->type() )
         {
             case header::scan_type:
             case header::fault_type: // cannot throw yet, since need to get response first
                 break;
             case header::response_type:
             {
                 unsigned int id = reinterpret_cast< const commands::response_header* >( m_payload )->id() & 0x3fff;
                 if( int( id ) != *m_commandId ) { COMMA_THROW( comma::exception, "expected response to command 0x" << std::hex << *m_commandId << ", got 0x" << id << std::dec ); }
                 m_commandId.reset();
                 return *( reinterpret_cast< typename command::response* >( m_payload ) );
             }
             default:
                 COMMA_THROW( comma::exception, "expected command response, got packet of unknown type (0x" << std::hex << m_header->type() << std::dec );
         }
     }
 }
Пример #19
0
				void clearCalendarCache() const { _calendar.reset(); }
Пример #20
0
 ~A() {
     m_active.reset();
     m_io.run(); // to completion
 }