2007-08-14 20:45:23 +00:00
|
|
|
/*
|
2009-01-10 23:09:07 +00:00
|
|
|
* This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.com>
|
2007-08-14 20:45:23 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2007-08-14 20:45:23 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2007-08-18 17:05:51 +00:00
|
|
|
*
|
2007-08-18 17:19:49 +00:00
|
|
|
* $Id$
|
2007-08-14 20:45:23 +00:00
|
|
|
*/
|
|
|
|
|
2007-11-09 20:07:52 +00:00
|
|
|
#include <assert.h>
|
2007-08-14 20:45:23 +00:00
|
|
|
#include "list.h"
|
|
|
|
#include "publish.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
struct tr_publisher_node
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_delivery_func * func;
|
|
|
|
void * user_data;
|
2007-08-14 20:45:23 +00:00
|
|
|
};
|
|
|
|
|
2008-12-29 18:10:07 +00:00
|
|
|
const tr_publisher TR_PUBLISHER_INIT = { NULL };
|
2007-08-14 20:45:23 +00:00
|
|
|
|
|
|
|
void
|
2008-12-29 18:10:07 +00:00
|
|
|
tr_publisherDestruct( tr_publisher * p )
|
2007-08-14 20:45:23 +00:00
|
|
|
{
|
2008-12-29 18:10:07 +00:00
|
|
|
tr_list_free( &p->list, NULL );
|
2007-08-14 20:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tr_publisher_tag
|
2008-12-29 18:10:07 +00:00
|
|
|
tr_publisherSubscribe( tr_publisher * p,
|
|
|
|
tr_delivery_func func,
|
|
|
|
void * user_data )
|
2007-08-14 20:45:23 +00:00
|
|
|
{
|
|
|
|
struct tr_publisher_node * node = tr_new( struct tr_publisher_node, 1 );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2007-08-14 20:45:23 +00:00
|
|
|
node->func = func;
|
|
|
|
node->user_data = user_data;
|
|
|
|
tr_list_append( &p->list, node );
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-12-29 18:10:07 +00:00
|
|
|
tr_publisherUnsubscribe( tr_publisher * p,
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_publisher_tag tag )
|
2007-08-14 20:45:23 +00:00
|
|
|
{
|
|
|
|
tr_list_remove_data( &p->list, tag );
|
|
|
|
tr_free( tag );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-12-29 18:10:07 +00:00
|
|
|
tr_publisherPublish( tr_publisher * p,
|
2008-09-23 19:11:04 +00:00
|
|
|
void * source,
|
|
|
|
void * event )
|
2007-08-14 20:45:23 +00:00
|
|
|
{
|
2007-09-20 16:32:01 +00:00
|
|
|
tr_list * walk;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
for( walk = p->list; walk != NULL; )
|
2007-08-14 20:45:23 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_list * next = walk->next;
|
|
|
|
struct tr_publisher_node * node =
|
|
|
|
(struct tr_publisher_node*)walk->data;
|
|
|
|
( node->func )( source, event, node->user_data );
|
2007-08-14 20:45:23 +00:00
|
|
|
walk = next;
|
|
|
|
}
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|