2007-08-14 20:45:23 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2007 Charles Kerr <charles@rebelbase.com>
|
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* 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
|
|
|
|
{
|
|
|
|
tr_delivery_func * func;
|
|
|
|
void * user_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tr_publisher_s
|
|
|
|
{
|
2007-09-20 16:32:01 +00:00
|
|
|
tr_list * list;
|
2007-08-14 20:45:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
tr_publisher_t*
|
|
|
|
tr_publisherNew( void )
|
|
|
|
{
|
|
|
|
return tr_new0( tr_publisher_t, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-09-20 16:32:01 +00:00
|
|
|
tr_publisherFree( tr_publisher_t ** p )
|
2007-08-14 20:45:23 +00:00
|
|
|
{
|
2007-09-20 16:32:01 +00:00
|
|
|
assert( p != NULL );
|
|
|
|
assert( *p != NULL );
|
|
|
|
|
2007-09-28 14:27:56 +00:00
|
|
|
tr_list_free( &(*p)->list, NULL );
|
2007-09-20 16:32:01 +00:00
|
|
|
tr_free( *p );
|
|
|
|
*p = NULL;
|
2007-08-14 20:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tr_publisher_tag
|
|
|
|
tr_publisherSubscribe ( tr_publisher_t * p,
|
|
|
|
tr_delivery_func func,
|
|
|
|
void * user_data )
|
|
|
|
{
|
|
|
|
struct tr_publisher_node * node = tr_new( struct tr_publisher_node, 1 );
|
|
|
|
node->func = func;
|
|
|
|
node->user_data = user_data;
|
|
|
|
tr_list_append( &p->list, node );
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tr_publisherUnsubscribe( tr_publisher_t * p,
|
|
|
|
tr_publisher_tag tag )
|
|
|
|
{
|
|
|
|
tr_list_remove_data( &p->list, tag );
|
|
|
|
tr_free( tag );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tr_publisherPublish( tr_publisher_t * p,
|
|
|
|
void * source,
|
|
|
|
void * event )
|
|
|
|
{
|
2007-09-20 16:32:01 +00:00
|
|
|
tr_list * walk;
|
2007-08-14 20:45:23 +00:00
|
|
|
for( walk=p->list; walk!=NULL; )
|
|
|
|
{
|
2007-09-20 16:32:01 +00:00
|
|
|
tr_list * next = walk->next;
|
2007-08-14 20:45:23 +00:00
|
|
|
struct tr_publisher_node * node = (struct tr_publisher_node*)walk->data;
|
|
|
|
(node->func)(source, event, node->user_data);
|
|
|
|
walk = next;
|
|
|
|
}
|
|
|
|
}
|