source: trunk/libtransmission/publish.c @ 2843

Last change on this file since 2843 was 2843, checked in by charles, 15 years ago

update version.sh to exclude third-party. add $Id:$ to the new files s.t. version.sh will find them.

File size: 1.7 KB
Line 
1/*
2 * This file Copyright (C) 2007 Charles Kerr <charles@rebelbase.com>
3 *
4 * This file is licensed by the GPL version 2.  Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id:
11 */
12
13#include "list.h"
14#include "publish.h"
15#include "utils.h"
16
17struct tr_publisher_node
18{
19   tr_delivery_func * func; 
20   void * user_data;
21};
22
23struct tr_publisher_s
24{
25    tr_list_t * list;
26};
27
28tr_publisher_t*
29tr_publisherNew( void )
30{
31    return tr_new0( tr_publisher_t, 1 );
32}
33
34void
35tr_publisherFree( tr_publisher_t * p )
36{
37    tr_list_free( &p->list );
38    tr_free( p );
39}
40
41tr_publisher_tag
42tr_publisherSubscribe ( tr_publisher_t    * p,
43                        tr_delivery_func    func,
44                        void              * user_data )
45{
46    struct tr_publisher_node * node = tr_new( struct tr_publisher_node, 1 );
47    node->func = func;
48    node->user_data = user_data;
49    tr_list_append( &p->list, node );
50    return node;
51}
52
53void
54tr_publisherUnsubscribe( tr_publisher_t   * p,
55                         tr_publisher_tag   tag )
56{
57    tr_list_remove_data( &p->list, tag );
58    tr_free( tag );
59}
60
61void
62tr_publisherPublish( tr_publisher_t  * p,
63                     void            * source,
64                     void            * event )
65{
66    tr_list_t * walk;
67    for( walk=p->list; walk!=NULL; )
68    {
69        tr_list_t * next = walk->next;
70        struct tr_publisher_node * node = (struct tr_publisher_node*)walk->data;
71        (node->func)(source, event, node->user_data);
72        walk = next;
73    }
74}
Note: See TracBrowser for help on using the repository browser.