Beispiel #1
0
inline void DEBUG_GEOMETRY_STOP()
{
    if (dg_output_debug_geometry)
    {
        debug_geometry_file << std::endl << "]}" << std::endl;
        debug_geometry_file.close();
    }
}
Beispiel #2
0
inline void DEBUG_TURNS_STOP()
{
    if (dg_output_turn_debug)
    {
        dg_debug_turns_file << std::endl << "]}" << std::endl;
        dg_debug_turns_file.close();
    }
}
void downloader_instance_simple::handle_read(const boost::system::error_code& ec, std::size_t length)
{
    if (!ec)
    {
        ofstream_.write(buffer_, length);
        readed_bytes_ += length;
        
        if (owner()->progress_notify_)
            owner()->progress_notify_(readed_bytes_);


        {
            boost::mutex::scoped_lock lock(owner()->stateGuard_);

            while (owner()->command_ != http_downloader_simple::commandNull)
            {
                switch (owner()->command_)
                {
                case http_downloader_simple::commandPause:
                    {
                        owner()->state_ = http_downloader_simple::statePaused;
                        owner()->command_ = http_downloader_simple::commandNull;

                        if (owner()->state_notify_)
                            owner()->state_notify_(http_downloader::statePause);

                        while (
                            owner()->command_ != http_downloader_simple::commandCancel &&
                            owner()->command_ != http_downloader_simple::commandResume
                            )   
                        {
                            lock.unlock();
                            boost::this_thread::sleep( boost::posix_time::milliseconds(100) ); 
                            lock.lock();                                                                                                
                        }

                        if (owner()->command_ == http_downloader_simple::commandResume)
                        {
                            owner()->state_ = http_downloader_simple::stateDownload;
                            owner()->command_ = http_downloader_simple::commandNull;
                            if (owner()->state_notify_)
                                owner()->state_notify_(http_downloader::stateResume);
                        }

                    }
                    break;

                case http_downloader_simple::commandCancel:
                    {
                        owner()->command_ = http_downloader_simple::commandNull;
                        ofstream_.close();
                        if (owner()->state_notify_)
                            owner()->state_notify_(http_downloader::stateCancel);
                        return;
                    }
                    break;

                case http_downloader_simple::commandResume:
                    break;

                }
            }
            
        }

        read_stream_.async_read_some(
            boost::asio::buffer(buffer_),
            boost::bind(&downloader_instance_simple::handle_read,
            shared_from_this(), _1, _2));
    } 
    else
    {
        ofstream_.close();
        if ( boost::asio::error::misc_category == ec.category() )
        {
            if (boost::asio::error::eof == ec.value())
            {
                if (owner()->state_notify_)
                    owner()->state_notify_(http_downloader::stateFinish);    
            }
        }
        else
        {
                if (owner()->state_notify_)
                    owner()->state_notify_(http_downloader::stateError);    
        }
    }
}