source: trunk/libtransmission/publish.c @ 7404

Last change on this file since 7404 was 7404, checked in by charles, 12 years ago

updated email address

  • 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@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 7404 2008-12-16 00:20:44Z 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 );
39    assert( *p );
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
53    node->func = func;
54    node->user_data = user_data;
55    tr_list_append( &p->list, node );
56    return node;
57}
58
59void
60tr_publisherUnsubscribe( tr_publisher_t * p,
61                         tr_publisher_tag tag )
62{
63    tr_list_remove_data( &p->list, tag );
64    tr_free( tag );
65}
66
67void
68tr_publisherPublish( tr_publisher_t * p,
69                     void *           source,
70                     void *           event )
71{
72    tr_list * walk;
73
74    for( walk = p->list; walk != NULL; )
75    {
76        tr_list *                  next = walk->next;
77        struct tr_publisher_node * node =
78            (struct tr_publisher_node*)walk->data;
79        ( node->func )( source, event, node->user_data );
80        walk = next;
81    }
82}
83
Note: See TracBrowser for help on using the repository browser.