Last change
on this file since 7528 was
7528,
checked in by charles, 12 years ago
|
(trunk libT) avoid some unnecessary memory fragmentation... for composited objects that have a tr_publisher, contain the it directly rather than a pointer to one allocated elsewhere on the heap.
|
-
Property svn:keywords set to
Date Rev Author Id
|
File size:
1.6 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 7528 2008-12-29 18:10:07Z charles $ |
---|
11 | */ |
---|
12 | |
---|
13 | #include <assert.h> |
---|
14 | #include "list.h" |
---|
15 | #include "publish.h" |
---|
16 | #include "utils.h" |
---|
17 | |
---|
18 | struct tr_publisher_node |
---|
19 | { |
---|
20 | tr_delivery_func * func; |
---|
21 | void * user_data; |
---|
22 | }; |
---|
23 | |
---|
24 | const tr_publisher TR_PUBLISHER_INIT = { NULL }; |
---|
25 | |
---|
26 | void |
---|
27 | tr_publisherDestruct( tr_publisher * p ) |
---|
28 | { |
---|
29 | tr_list_free( &p->list, NULL ); |
---|
30 | } |
---|
31 | |
---|
32 | tr_publisher_tag |
---|
33 | tr_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 | |
---|
45 | void |
---|
46 | tr_publisherUnsubscribe( tr_publisher * p, |
---|
47 | tr_publisher_tag tag ) |
---|
48 | { |
---|
49 | tr_list_remove_data( &p->list, tag ); |
---|
50 | tr_free( tag ); |
---|
51 | } |
---|
52 | |
---|
53 | void |
---|
54 | tr_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.