source: trunk/libtransmission/publish.c @ 4404

Last change on this file since 4404 was 4404, checked in by charles, 14 years ago

set copyright info to 2008

  • Property svn:keywords set to Date Rev Author Id
File size: 1.8 KB
Line 
1/*
2 * This file Copyright (C) 2007-2008 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: publish.c 4404 2008-01-01 17:20:20Z 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
24struct tr_publisher_s
25{
26    tr_list * list;
27};
28
29tr_publisher_t*
30tr_publisherNew( void )
31{
32    return tr_new0( tr_publisher_t, 1 );
33}
34
35void
36tr_publisherFree( tr_publisher_t ** p )
37{
38    assert( p != NULL );
39    assert( *p != NULL );
40
41    tr_list_free( &(*p)->list, NULL );
42    tr_free( *p );
43    *p = NULL;
44}
45
46tr_publisher_tag
47tr_publisherSubscribe ( tr_publisher_t    * p,
48                        tr_delivery_func    func,
49                        void              * user_data )
50{
51    struct tr_publisher_node * node = tr_new( struct tr_publisher_node, 1 );
52    node->func = func;
53    node->user_data = user_data;
54    tr_list_append( &p->list, node );
55    return node;
56}
57
58void
59tr_publisherUnsubscribe( tr_publisher_t   * p,
60                         tr_publisher_tag   tag )
61{
62    tr_list_remove_data( &p->list, tag );
63    tr_free( tag );
64}
65
66void
67tr_publisherPublish( tr_publisher_t  * p,
68                     void            * source,
69                     void            * event )
70{
71    tr_list * walk;
72    for( walk=p->list; walk!=NULL; )
73    {
74        tr_list * next = walk->next;
75        struct tr_publisher_node * node = (struct tr_publisher_node*)walk->data;
76        (node->func)(source, event, node->user_data);
77        walk = next;
78    }
79}
Note: See TracBrowser for help on using the repository browser.