source: trunk/src/halTorrentIntStates.cpp @ 683

Revision 683, 2.6 KB checked in by Eoin, 11 years ago (diff)
Line 
1
2//         Copyright Eóin O'Callaghan 2008 - 2009.
3// Distributed under the Boost Software License, Version 1.0.
4//    (See accompanying file LICENSE_1_0.txt or copy at
5//          http://www.boost.org/LICENSE_1_0.txt)
6
7#include "stdAfx.hpp"
8
9#include "halTorrentInternal.hpp"
10
11namespace hal
12{
13
14in_the_session::in_the_session(base_type::my_context ctx) :
15        base_type::my_base(ctx)
16{
17        TORRENT_STATE_LOG(L"Entering in_the_session()");
18
19        assert(context<torrent_internal>().in_session());
20}
21
22sc::result in_the_session::react(const ev_remove_from_session& evt)
23{
24        torrent_internal& t_i = context<torrent_internal>();
25
26        HAL_DEV_MSG(L"removing handle from session");
27        t_i.the_session_->remove_torrent(t_i.handle_);
28        t_i.in_session_ = false;
29
30        assert(!t_i.in_session());     
31        HAL_DEV_MSG(L"Removed from session!");
32
33        return transit< out_of_session >();
34}
35
36in_the_session::~in_the_session()
37{
38        TORRENT_STATE_LOG(L"Exiting ~in_the_session()");
39}
40
41out_of_session::out_of_session(base_type::my_context ctx) :
42        base_type::my_base(ctx)
43{
44        TORRENT_STATE_LOG(L"Entering out_of_session()");
45}
46
47out_of_session::~out_of_session()
48{
49        TORRENT_STATE_LOG(L"Exiting ~out_of_session()");
50}
51
52sc::result out_of_session::react(const ev_add_to_session& evt)
53{
54        TORRENT_STATE_LOG(L"Entering in_the_session()");
55        torrent_internal& t_i = context<torrent_internal>();
56
57        assert(!t_i.in_session());
58
59        libt::add_torrent_params p;
60
61        string torrent_file = to_utf8((hal::app().get_working_directory()/L"torrents"/t_i.filename_).string());
62        t_i.info_memory_.reset(new libt::torrent_info(torrent_file.c_str()));
63
64        std::string resume_file = to_utf8((hal::app().get_working_directory()/L"resume" / (t_i.name_ + L".fastresume")).string());
65
66        std::vector<char> buf;
67        if (libt::load_file(resume_file.c_str(), buf) == 0)
68        {
69                HAL_DEV_MSG(L"Using resume data");
70                p.resume_data = &buf;
71        }
72
73        p.ti = t_i.info_memory_;
74        p.save_path = path_to_utf8(t_i.save_directory_);
75        p.storage_mode = hal_allocation_to_libt(t_i.allocation_);
76        p.paused = evt.pause();
77        p.duplicate_is_error = false;
78        p.auto_managed = t_i.managed_;
79
80        t_i.handle_ = t_i.the_session_->add_torrent(p);         
81        assert(t_i.handle_.is_valid());
82        t_i.in_session_ = true;
83       
84//      clear_resume_data();
85//      handle_.force_reannounce();
86
87        return transit< in_the_session >();
88}
89
90paused::paused()
91{
92        TORRENT_STATE_LOG(L"Entering paused()");
93}
94
95paused::~paused()
96{
97        TORRENT_STATE_LOG(L"Exiting ~paused()");
98}
99
100active::active()
101{
102        TORRENT_STATE_LOG(L"Entering active()");
103}
104
105active::~active()
106{
107        TORRENT_STATE_LOG(L"Exiting ~active()");
108}
109
110} // namespace hal
Note: See TracBrowser for help on using the repository browser.