Changeset 760


Ignore:
Timestamp:
05/16/09 20:58:17 (10 years ago)
Author:
Eoin
Message:

Auto exit after a (currently hardcoded) time working.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/HaliteWindow.cpp

    r759 r760  
    591591} 
    592592 
     593 
     594 
     595LRESULT HaliteWindow::OnUnconditionalShutdown(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam) 
     596{ 
     597        HAL_DEV_MSG(L"In OnUnconditionalShutdown"); 
     598 
     599        DestroyWindow(); 
     600 
     601        return 0; 
     602} 
     603 
     604void HaliteWindow::exitCallback() 
     605{ 
     606        HAL_DEV_MSG(L"In callback"); 
     607 
     608        PostMessage(WM_HALITE_UNCONDITIONAL_SHUTDOWN, 0, 0); 
     609} 
     610 
    593611LRESULT HaliteWindow::OnAutoShutdown(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) 
    594612{        
    595         WTL::CMenuHandle m; 
     613/*      WTL::CMenuHandle m; 
    596614        WTL::CMenu menu;         
    597615 
     
    601619        POINT ptPoint; 
    602620        GetCursorPos(&ptPoint); 
    603         menu.TrackPopupMenu(0, ptPoint.x, ptPoint.y, m_hWnd); 
     621        menu.TrackPopupMenu(0, ptPoint.x, ptPoint.y, m_hWnd);*/ 
     622 
     623        hal::bittorrent::Instance().schedual_callback( 
     624                boost::posix_time::hours(5), bind(&HaliteWindow::exitCallback, this)); 
    604625 
    605626        return 0; 
  • trunk/src/HaliteWindow.hpp

    r758 r760  
    2020#define HAL_SHUTDOWN_EXIT                       ID_WINDOW_BEGIN + 9 
    2121#define HAL_DATETIME_DEFFLD_TEXT                        ID_WINDOW_BEGIN + 12 
     22 
     23 
     24#define WM_HALITE_UNCONDITIONAL_SHUTDOWN        WM_USER + 321 
    2225 
    2326#ifndef RC_INVOKED 
     
    8285                MSG_WM_COPYDATA(OnCopyData); 
    8386                MESSAGE_HANDLER(WM_AreYouMe_, OnAreYouMe) 
     87                MESSAGE_HANDLER_EX(WM_HALITE_UNCONDITIONAL_SHUTDOWN, OnUnconditionalShutdown) 
    8488                MESSAGE_HANDLER_EX(WM_TRAYNOTIFY, OnTrayNotification)    
    8589                 
     
    169173        void OnSize(UINT, WTL::CSize); 
    170174        void OnMove(WTL::CSize); 
    171         void OnShowWindow(BOOL bShow, UINT nStatus); 
     175        void OnShowWindow(BOOL bShow, UINT nStatus);     
    172176        LRESULT OnTrayNotification(UINT, WPARAM wParam, LPARAM lParam); 
     177        LRESULT OnUnconditionalShutdown(UINT, WPARAM wParam, LPARAM lParam); 
    173178        LRESULT OnResumeAll(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); 
    174179        LRESULT OnTrayOpenHalite(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); 
     
    192197        void updateWindow(); 
    193198        void setCorrectDialog(); 
     199        void exitCallback(); 
    194200 
    195201        friend class boost::serialization::access; 
  • trunk/src/WTLx/GenericAddDialog.hpp

    r710 r760  
    140140        enum { IDD = HAL_GENERIC_HOLDER }; 
    141141 
    142     BEGIN_MSG_MAP_EX(thisClass) 
     142        BEGIN_MSG_MAP_EX(thisClass) 
    143143                MSG_WM_INITDIALOG(OnInitDialog) 
    144144                MSG_WM_CLOSE(OnClose)    
     
    148148 
    149149                CHAIN_MSG_MAP(resizeClass) 
    150     END_MSG_MAP() 
     150        END_MSG_MAP() 
    151151 
    152152        BEGIN_DLGRESIZE_MAP(thisClass) 
  • trunk/src/halSession.cpp

    r759 r760  
    3535        bittorrent_ini_(L"BitTorrent.xml"), 
    3636        the_torrents_(bittorrent_ini_), 
     37        action_timer_(io_service_), 
    3738        default_torrent_max_connections_(-1), 
    3839        default_torrent_max_uploads_(-1), 
     
    372373} 
    373374 
     375void bit_impl::execute_action(const boost::system::error_code& e, bit::timeout_actions action) 
     376{ 
     377        if (e != boost::asio::error::operation_aborted) 
     378        { 
     379                HAL_DEV_MSG(hal::wform(L"Doing action %1%") % action); 
     380 
     381                switch(action) 
     382                { 
     383                case bit::action_pause: 
     384                        session_->pause(); 
     385                        break; 
     386                case bit::action_resume: 
     387                        session_->resume(); 
     388                        break; 
     389                default: 
     390                        break; 
     391                }; 
     392        } 
     393        else 
     394        { 
     395                HAL_DEV_MSG(hal::wform(L"Action %1% aborted") % action); 
     396        } 
     397} 
     398 
     399void bit_impl::execute_callback(const boost::system::error_code& e, action_callback_t action) 
     400{ 
     401        if (e != boost::asio::error::operation_aborted) 
     402        { 
     403                HAL_DEV_MSG(L"Doing callback"); 
     404 
     405                action(); 
     406        } 
     407        else 
     408        { 
     409                HAL_DEV_MSG(L"Callback aborted"); 
     410        } 
     411} 
     412 
     413void bit_impl::schedual_action(boost::posix_time::ptime time, bit::timeout_actions action) 
     414{ 
     415        HAL_DEV_MSG(hal::wform(L"Schedual absolute action %1% at %2%") % action % time); 
     416 
     417        action_timer_.cancel(); 
     418 
     419        action_timer_.expires_at(time); 
     420        action_timer_.async_wait(bind(&bit_impl::execute_action, this, _1, action)); 
     421} 
     422void bit_impl::schedual_action(boost::posix_time::time_duration duration, bit::timeout_actions action) 
     423{ 
     424        HAL_DEV_MSG(hal::wform(L"Schedual relative action %1% in %2%") % action % duration); 
     425 
     426        action_timer_.cancel(); 
     427 
     428        action_timer_.expires_from_now(duration); 
     429        action_timer_.async_wait(bind(&bit_impl::execute_action, this, _1, action)); 
     430} 
     431 
     432void bit_impl::schedual_callback(boost::posix_time::ptime time, action_callback_t action) 
     433{ 
     434        HAL_DEV_MSG(hal::wform(L"Schedual absolute callback %1%") % time); 
     435 
     436        action_timer_.cancel(); 
     437 
     438        action_timer_.expires_at(time); 
     439        action_timer_.async_wait(bind(&bit_impl::execute_callback, this, _1, action)); 
     440} 
     441void bit_impl::schedual_callback(boost::posix_time::time_duration duration, action_callback_t action) 
     442{ 
     443        HAL_DEV_MSG(hal::wform(L"Schedual relative callback %1%") % duration); 
     444 
     445        action_timer_.cancel(); 
     446 
     447        action_timer_.expires_from_now(duration); 
     448        action_timer_.async_wait(bind(&bit_impl::execute_callback, this, _1, action)); 
     449}        
     450 
    374451void bit_impl::start_alert_handler() 
    375452{ 
  • trunk/src/halSession.hpp

    r759 r760  
    967967        void alert_handler_wait(const boost::system::error_code& /*e*/); 
    968968 
     969        void execute_action(const boost::system::error_code&, bit::timeout_actions action); 
     970        void execute_callback(const boost::system::error_code&, action_callback_t action); 
     971 
     972        void acquire_work_object() 
     973        { 
     974                HAL_DEV_MSG(hal::wform(L"Acquiring service work object.")); 
     975 
     976                work_.reset(new boost::asio::io_service::work(io_service_)); 
     977        } 
     978 
     979        void discard_work_object() 
     980        { 
     981                work_.reset(); 
     982 
     983                HAL_DEV_MSG(hal::wform(L"Discarded service work object")); 
     984        } 
     985 
     986        void schedual_action(boost::posix_time::ptime time, bit::timeout_actions action); 
     987        void schedual_action(boost::posix_time::time_duration duration, bit::timeout_actions action); 
     988        void schedual_callback(boost::posix_time::ptime time, action_callback_t action); 
     989        void schedual_callback(boost::posix_time::time_duration duration, action_callback_t action);     
     990         
     991        boost::optional<libt::session> session_;         
     992        mutable mutex_t mutex_; 
     993         
     994        ini_file bittorrent_ini_; 
     995        torrent_manager the_torrents_;   
     996 
    969997        boost::asio::io_service io_service_; 
    970998        std::auto_ptr<boost::asio::io_service::work> work_; 
    971999 
    972         void acquire_work_object() 
    973         { 
    974                 HAL_DEV_MSG(hal::wform(L"Acquiring service work object.")); 
    975  
    976                 work_.reset(new boost::asio::io_service::work(io_service_)); 
    977         } 
    978  
    979         void discard_work_object() 
    980         { 
    981                 work_.reset(); 
    982  
    983                 HAL_DEV_MSG(hal::wform(L"Discarded service work object")); 
    984         } 
    985          
    986         boost::optional<libt::session> session_;         
    987         mutable mutex_t mutex_; 
     1000        boost::asio::deadline_timer action_timer_; 
    9881001 
    9891002        typedef boost::shared_ptr<thread_t> shared_thread_ptr; 
     
    9911004        std::vector<shared_thread_ptr> service_threads_; 
    9921005        bool keep_checking_; 
    993          
    994         ini_file bittorrent_ini_; 
    995         torrent_manager the_torrents_;   
    9961006         
    9971007        int default_torrent_max_connections_; 
  • trunk/src/halTorrent.cpp

    r756 r760  
    818818} 
    819819 
     820void bit::schedual_action(boost::posix_time::ptime time, timeout_actions action) 
     821{ 
     822        return pimpl()->schedual_action(time, action); 
     823} 
     824 
     825void bit::schedual_action(boost::posix_time::time_duration duration, timeout_actions action) 
     826{ 
     827        return pimpl()->schedual_action(duration, action); 
     828} 
     829 
     830void bit::schedual_callback(boost::posix_time::ptime time, action_callback_t action) 
     831{ 
     832        return pimpl()->schedual_callback(time, action); 
     833} 
     834 
     835void bit::schedual_callback(boost::posix_time::time_duration duration, action_callback_t action) 
     836{ 
     837        return pimpl()->schedual_callback(duration, action); 
     838} 
     839 
    820840bit::torrent::torrent() 
    821841{} 
  • trunk/src/halTorrent.hpp

    r749 r760  
    4040#include <boost/asio/ip/tcp.hpp> 
    4141#include <boost/asio/ip/udp.hpp> 
     42 
     43#include <boost/asio/deadline_timer.hpp> 
     44#include <boost/date_time/posix_time/posix_time.hpp> 
    4245 
    4346#include "halTypes.hpp" 
     
    223226                peer_details_filled_(false), 
    224227                file_details_filled_(false) 
    225         {};      
     228        {}; 
    226229         
    227230        enum state 
     
    500503typedef boost::function<bool (size_t, size_t, size_t)> filterCallback; 
    501504typedef boost::function<bool (size_t, size_t, std::wstring)> progress_callback; 
     505typedef boost::function<void ()> action_callback_t; 
    502506typedef boost::function<void (int)> report_num_active; 
    503507typedef boost::function<void (wpath path, boost::shared_ptr<file_details_vec> files)> remove_files; 
     
    534538                move_to_top, 
    535539                move_to_bottom 
     540        }; 
     541         
     542        enum timeout_actions 
     543        { 
     544                action_pause = 0, 
     545                action_resume, 
     546                action_callback 
    536547        }; 
    537548 
     
    773784        void start_event_receiver(); 
    774785        void stop_event_receiver(); 
     786 
     787        void schedual_action(boost::posix_time::ptime time, timeout_actions action); 
     788        void schedual_action(boost::posix_time::time_duration duration, timeout_actions action); 
     789 
     790        void schedual_callback(boost::posix_time::ptime time, action_callback_t); 
     791        void schedual_callback(boost::posix_time::time_duration duration, action_callback_t); 
    775792         
    776793//      friend bit& bittorrent(); 
Note: See TracChangeset for help on using the changeset viewer.