updates to C bindings

This commit is contained in:
Arvid Norberg 2009-05-26 01:03:56 +00:00
parent f05777c2c2
commit 5874d32a34
3 changed files with 56 additions and 7 deletions

View File

@ -282,7 +282,7 @@ TORRENT_EXPORT int session_add_torrent(void* ses, int tag, ...)
return i;
}
void session_remove_torrent(void* ses, int tor, int flags)
TORRENT_EXPORT void session_remove_torrent(void* ses, int tor, int flags)
{
using namespace libtorrent;
torrent_handle h = get_handle(tor);
@ -292,7 +292,23 @@ void session_remove_torrent(void* ses, int tor, int flags)
s->remove_torrent(h, flags);
}
int session_set_settings(void* ses, int tag, ...)
TORRENT_EXPORT int session_pop_alert(void* ses, char* dest, int len, int* category)
{
using namespace libtorrent;
session* s = (session*)ses;
std::auto_ptr<alert> a = s->pop_alert();
if (!a.get()) return -1;
if (category) *category = a->category();
strncpy(dest, a->message().c_str(), len - 1);
dest[len - 1] = 0;
return 0; // for now
}
TORRENT_EXPORT int session_set_settings(void* ses, int tag, ...)
{
using namespace libtorrent;
@ -344,6 +360,10 @@ int session_set_settings(void* ses, int tag, ...)
copy_proxy_setting(&ps, va_arg(lp, struct proxy_setting const*));
s->set_tracker_proxy(ps);
}
case SET_ALERT_MASK:
{
s->set_alert_mask(va_arg(lp, int));
}
#ifndef TORRENT_DISABLE_DHT
case SET_DHT_PROXY:
{
@ -374,7 +394,7 @@ int session_set_settings(void* ses, int tag, ...)
return 0;
}
int session_get_setting(void* ses, int tag, void* value, int* value_size)
TORRENT_EXPORT int session_get_setting(void* ses, int tag, void* value, int* value_size)
{
using namespace libtorrent;
session* s = (session*)ses;
@ -400,7 +420,7 @@ int session_get_setting(void* ses, int tag, void* value, int* value_size)
}
}
int session_get_status(void* sesptr, struct session_status* s, int struct_size)
TORRENT_EXPORT int session_get_status(void* sesptr, struct session_status* s, int struct_size)
{
libtorrent::session* ses = (libtorrent::session*)sesptr;
@ -457,7 +477,7 @@ int session_get_status(void* sesptr, struct session_status* s, int struct_size)
return 0;
}
int torrent_get_status(int tor, torrent_status* s, int struct_size)
TORRENT_EXPORT int torrent_get_status(int tor, torrent_status* s, int struct_size)
{
libtorrent::torrent_handle h = get_handle(tor);
if (!h.is_valid()) return -1;
@ -515,7 +535,7 @@ int torrent_get_status(int tor, torrent_status* s, int struct_size)
return 0;
}
int torrent_set_settings(int tor, int tag, ...)
TORRENT_EXPORT int torrent_set_settings(int tor, int tag, ...)
{
using namespace libtorrent;
torrent_handle h = get_handle(tor);
@ -557,7 +577,7 @@ int torrent_set_settings(int tor, int tag, ...)
return 0;
}
int torrent_get_setting(int tor, int tag, void* value, int* value_size)
TORRENT_EXPORT int torrent_get_setting(int tor, int tag, void* value, int* value_size)
{
using namespace libtorrent;
torrent_handle h = get_handle(tor);

View File

@ -85,6 +85,7 @@ enum tags
SET_TRACKER_PROXY, // proxy_setting const*, session_only
SET_DHT_PROXY, // proxy_setting const*, session_only
SET_PROXY, // proxy_setting const*, session_only
SET_ALERT_MASK, // int, session_only
};
struct proxy_setting
@ -98,6 +99,23 @@ struct proxy_setting
int type;
};
enum category_t
{
cat_error = 0x1,
cat_peer = 0x2,
cat_port_mapping = 0x4,
cat_storage = 0x8,
cat_tracker = 0x10,
cat_debug = 0x20,
cat_status = 0x40,
cat_progress = 0x80,
cat_ip_block = 0x100,
cat_performance_warning = 0x200,
cat_dht = 0x400,
cat_all_categories = 0xffffffff
};
enum proxy_type_t
{
proxy_none,
@ -256,6 +274,10 @@ void session_close(void* ses);
int session_add_torrent(void* ses, int first_tag, ...);
void session_remove_torrent(void* ses, int tor, int flags);
// return < 0 if there are no alerts. Otherwise returns the
// type of alert that was returned
int session_pop_alert(void* ses, char* dest, int len, int* category);
int session_get_status(void* ses, struct session_status* s, int struct_size);
// use SET_* tags in tag list

View File

@ -55,6 +55,7 @@ int main(int argc, char* argv[])
void* ses = session_create(
SES_LISTENPORT, 6881,
SES_LISTENPORT_END, 6889,
SES_ALERT_MASK, ~(cat_progress | cat_port_mapping | cat_debug | cat_performance_warning | cat_peer),
TAG_END);
int t = session_add_torrent(ses,
@ -97,6 +98,12 @@ int main(int argc, char* argv[])
, message);
char msg[400];
while (session_pop_alert(ses, msg, sizeof(msg), 0) >= 0)
{
printf("%s\n", msg);
}
if (strlen(st.error) > 0)
{
fprintf(stderr, "\nERROR: %s\n", st.error);