source: trunk/libtransmission/publish.c @ 8050

Last change on this file since 8050 was 7658, checked in by charles, 13 years ago

(trunk) update the GPL code's copyright dates

  • Property svn:keywords set to Date Rev Author Id
File size: 1.6 KB
Line 
1/*
2 * This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.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: publish.c 7658 2009-01-10 23:09:07Z charles $
11 */
12
13#include <assert.h>
14#include "list.h"
15#include "publish.h"
16#include "utils.h"
17
18struct tr_publisher_node
19{
20    tr_delivery_func *  func;
21    void *              user_data;
22};
23
24const tr_publisher TR_PUBLISHER_INIT = { NULL };
25
26void
27tr_publisherDestruct( tr_publisher * p )
28{
29    tr_list_free( &p->list, NULL );
30}
31
32tr_publisher_tag
33tr_publisherSubscribe( tr_publisher     * p,
34                       tr_delivery_func   func,
35                       void *             user_data )
36{
37    struct tr_publisher_node * node = tr_new( struct tr_publisher_node, 1 );
38
39    node->func = func;
40    node->user_data = user_data;
41    tr_list_append( &p->list, node );
42    return node;
43}
44
45void
46tr_publisherUnsubscribe( tr_publisher * p,
47                         tr_publisher_tag tag )
48{
49    tr_list_remove_data( &p->list, tag );
50    tr_free( tag );
51}
52
53void
54tr_publisherPublish( tr_publisher * p,
55                     void *           source,
56                     void *           event )
57{
58    tr_list * walk;
59
60    for( walk = p->list; walk != NULL; )
61    {
62        tr_list *                  next = walk->next;
63        struct tr_publisher_node * node =
64            (struct tr_publisher_node*)walk->data;
65        ( node->func )( source, event, node->user_data );
66        walk = next;
67    }
68}
69
Note: See TracBrowser for help on using the repository browser.