[Libpdtp-svn] r47 - /
Status: Alpha
Brought to you by:
bascule
From: <tar...@pd...> - 2004-11-23 23:33:15
|
Author: tarcieri Date: 2004-11-23 16:33:02 -0700 (Tue, 23 Nov 2004) New Revision: 47 Modified: download.c pdtp.c pdtp.h Log: Library interface changes Modified: download.c =================================================================== --- download.c 2004-11-23 22:57:56 UTC (rev 46) +++ download.c 2004-11-23 23:33:02 UTC (rev 47) @@ -73,9 +73,6 @@ /* File being downloaded */ pdtp_file_t file; - - /* Callback table associated with download */ - pdtp_callback_table_t *callback; }; /* This structure stores piece transfer initialization parameters */ @@ -181,7 +178,6 @@ dl->conn = conn; dl->file = 0; - dl->callback = 0; return dl; err: @@ -202,7 +198,7 @@ { } -void pdtp_download_run(pdtp_download_t dl, pdtp_file_t file, pdtp_callback_table_t *table, void *ptr) +void pdtp_download_run(pdtp_download_t dl, pdtp_file_t file) { unsigned i; uint32_t value; Modified: pdtp.c =================================================================== --- pdtp.c 2004-11-23 22:57:56 UTC (rev 46) +++ pdtp.c 2004-11-23 23:33:02 UTC (rev 47) @@ -271,7 +271,7 @@ return; } - pdtp_download_run(dl, file, 0, 0); + pdtp_download_run(dl, file); pdtp_download_destroy(dl); pdtp_fclose(file); Modified: pdtp.h =================================================================== --- pdtp.h 2004-11-23 22:57:56 UTC (rev 46) +++ pdtp.h 2004-11-23 23:33:02 UTC (rev 47) @@ -228,72 +228,7 @@ * @{ */ - -/** Function table for event notification. This table is passed to the - pdtp_download_run() function. The last argument of pdtp_download_run() - is a void pointer which will be passed as the last argument to any - function in this table. */ -typedef struct { - /** This is invoked when we actually begin the download */ - void (*download_begin)(int pieces_remaining, int pieces_total, void *ptr); - - /** This is invoked when the download has been successfully completed */ - void (*download_complete)(void *ptr); - - /** This is invoked if a download fails. If this occurs, - pdtp_download_run() will also exit */ - void (*download_fail)(const char *message, void *ptr); - - /** This is invoked when we attempt to connect to a peer */ - void (*peer_connect)(const char *address, int port, void *ptr); - - /** This is invoked when we successfully connect to a peer */ - void (*peer_connect_complete)(const char *address, int port, void *ptr); - - /** This is invoked if a connection to a peer fails */ - void (*peer_connect_fail)(const char *address, int port, const char *errmsg, void *ptr); - - /** This is invoked when we disconnect from a peer */ - void (*peer_disconnect)(char *address, int port, void *ptr); - - /** This is invoked when a peer connects to us */ - void (*incoming_connect)(char *address, int port, void *ptr); - - /** This is invoked when a peer disconnects from us */ - void (*incoming_disconnect)(char *address, int port, void *ptr); - - /** This is invoked when we begin to download a piece */ - void (*piece_download)(char *address, int port, int piece, int length, void *ptr); - - /** This is invoked when we begin to upload a piece */ - void (*piece_upload)(char *address, int port, int piece, int length, void *ptr); - - /** This is invoked when a piece download completes */ - void (*piece_download_complete)(char *address, int port, int piece, void *ptr); - - /** This is invoked when a piece upload completes */ - void (*piece_upload_complete)(char *address, int port, int piece, void *ptr); - - /** This is invoked whenever we download a portion of a piece */ - void (*piece_chunk_download)(char *address, int port, int piece, int length, void *ptr); - - /** This is invoked whenever we upload a portion of a piece */ - void (*piece_chunk_upload)(char *address, int port, int piece, int length, void *ptr); - - /** This is invoked when we begin checksumming a piece */ - void (*piece_checksum)(int piece, int length, void *ptr); - - /** This is invoked if a piece checksum matches */ - void (*piece_checksum_complete)(int piece, void *ptr); - - /** This is invoked if a piece checksum mismatches */ - void (*piece_checksum_fail)(int piece, void *ptr); - - /** This is invoked whenever we MD5 checksum a piece */ - void (*piece_chunk_scan)(int piece, int length, void *ptr); -} pdtp_callback_table_t; - -/** This initiates a new download */ +/** This initiates a new download for the given file on the PDTP server */ pdtp_download_t pdtp_download_create(pdtp_connection_t, const char *path); /** This will free the information associated with a download */ @@ -337,12 +272,107 @@ the given file while this function is active. This function does not handle closing the given file pointer, that is left up to the programmer using the library. */ -void pdtp_download_run(pdtp_download_t, pdtp_file_t, pdtp_callback_table_t *, void *ptr); +void pdtp_download_run(pdtp_download_t, pdtp_file_t); /** This function may be invoked from another thread to gracefully terminate an active transfer */ void pdtp_download_stop(pdtp_download_t); +/** The following functions let you define callbacks which are invoked when + various events occur during the download. */ + +/** This is invoked when the download actually begins. It specifies how many + total pieces remain in the download and how many have been completed */ +typedef void (*pdtp_download_begin_handler_t)(int pieces_remaining, int pieces_total, void *ptr); + +void pdtp_download_set_begin_handler(pdtp_download_t, pdtp_download_begin_handler_t, void *ptr); + +/** This is invoked when the download has been successfully completed */ +typedef void (*pdtp_download_complete_handler_t)(void *ptr); + +void pdtp_download_set_complete_handler(pdtp_download_t, pdtp_download_complete_handler_t, void *ptr); + +/** This is invoked if a download fails. If this occurs, pdtp_download_run() + will also exit */ +typedef void (*pdtp_download_fail_handler_t)(const char *message, void *ptr); + +void pdtp_download_set_fail_handler(pdtp_download_t, pdtp_download_fail_handler_t, void *ptr); + +/** This is invoked when we begin checksumming a piece */ +typedef void (*pdtp_piece_checksum_handler_t)(int piece, int length, void *ptr); + +void pdtp_download_set_piece_checksum_handler(pdtp_download_t, pdtp_piece_checksum_handler_t, void *ptr); + +/** This is invoked if a piece checksum matches */ +typedef void (*pdtp_piece_checksum_pass_handler_t)(int piece, void *ptr); + +void pdtp_download_set_piece_checksum_pass_handler(pdtp_download_t, pdtp_piece_checksum_pass_handler_t, void *ptr); + +/** This is invoked if a piece checksum mismatches */ +typedef void (*pdtp_piece_checksum_fail_handler_t)(int piece, void *ptr); + +void pdtp_download_set_piece_checksum_fail_handler(pdtp_download_t, pdtp_piece_checksum_fail_handler_t, void *ptr); + +/** This is invoked when we attempt to connect to a peer */ +typedef void (*pdtp_peer_connect_handler_t)(const char *address, int port, void *ptr); + +void pdtp_download_set_peer_connect_handler(pdtp_download_t, pdtp_peer_connect_handler_t, void *ptr); + +/** This is invoked when we successfully connect to a peer */ +typedef void (*pdtp_peer_connect_complete_handler_t)(const char *address, int port, void *ptr); + +void pdtp_download_set_peer_connect_complete_handler(pdtp_download_t, pdtp_peer_connect_complete_handler_t, void *ptr); + +/** This is invoked if a connection to a peer fails */ +typedef void (*pdtp_peer_connect_fail_handler_t)(const char *address, int port, const char *errmsg, void *ptr); + +void pdtp_download_set_peer_connect_fail_handler(pdtp_download_t, pdtp_peer_connect_fail_handler_t, void *ptr); + +/** This is invoked when we disconnect from a peer */ +typedef void (*pdtp_peer_disconnect_handler_t)(char *address, int port, void *ptr); + +void pdtp_download_set_peer_disconnect_handler(pdtp_download_t, pdtp_peer_disconnect_handler_t, void *ptr); + +/** This is invoked when a peer connects to us */ +typedef void (*pdtp_incoming_connect_handler_t)(char *address, int port, void *ptr); + +void pdtp_download_set_incoming_connect_handler(pdtp_download_t, pdtp_incoming_connect_handler_t, void *ptr); + +/** This is invoked when a peer disconnects from us */ +typedef void (*pdtp_incoming_disconnect_handler_t)(char *address, int port, void *ptr); + +void pdtp_download_set_incoming_disconnect_handler(pdtp_download_t, pdtp_incoming_disconnect_handler_t, void *ptr); + +/** This is invoked when we begin to download a piece */ +typedef void (*pdtp_piece_download_handler_t)(char *address, int port, int piece, int length, void *ptr); + +void pdtp_download_set_piece_download_handler(pdtp_download_t, pdtp_piece_download_handler_t, void *ptr); + +/** This is invoked when we begin to upload a piece */ +typedef void (*pdtp_piece_upload_handler_t)(char *address, int port, int piece, int length, void *ptr); + +void pdtp_download_set_piece_upload_handler(pdtp_download_t, pdtp_piece_upload_handler_t, void *ptr); + +/** This is invoked when a piece download completes */ +typedef void (*pdtp_piece_download_complete_handler_t)(char *address, int port, int piece, void *ptr); + +void pdtp_download_set_piece_download_complete_handler(pdtp_download_t, pdtp_piece_download_complete_handler_t, void *ptr); + +/** This is invoked when a piece upload completes */ +typedef void (*pdtp_piece_upload_complete_handler_t)(char *address, int port, int piece, void *ptr); + +void pdtp_download_set_piece_upload_complete_handler(pdtp_download_t, pdtp_piece_upload_complete_handler_t, void *ptr); + +/** This is invoked whenever we download a portion of a piece */ +typedef void (*pdtp_piece_chunk_download_handler_t)(char *address, int port, int piece, int length, void *ptr); + +void pdtp_download_set_piece_chunk_download_handler(pdtp_download_t, pdtp_piece_chunk_download_handler_t, void *ptr); + +/** This is invoked whenever we upload a portion of a piece */ +typedef void (*pdtp_piece_chunk_upload_handler_t)(char *address, int port, int piece, int length, void *ptr); + +void pdtp_download_set_piece_chunk_upload_handler(pdtp_download_t, pdtp_piece_chunk_upload_handler_t, void *ptr); + /* @} */ /****************** * File Interface * |