ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/object.C
Revision: 1.4
Committed: Tue Aug 28 17:08:12 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +8 -13 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

# Content
1 /*
2 * object.C: Object management.
3 * Rights to this code are documented in doc/pod/license.pod.
4 *
5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 */
7
8 static char const rcsid[] = "$Id: object.C,v 1.3 2007-07-21 13:23:22 pippijn Exp $";
9
10 #include "atheme.h"
11
12 /*
13 * object_init
14 *
15 * Populates the object manager part of an object.
16 *
17 * Inputs:
18 * - pointer to object manager area
19 * - (optional) name of object
20 * - (optional) custom destructor
21 *
22 * Outputs:
23 * - none
24 *
25 * Side Effects:
26 * - none
27 */
28 void
29 object_init (object_t * obj, const char *name, destructor_t des)
30 {
31 return_if_fail (obj != NULL);
32
33 if (name != NULL)
34 obj->name = sstrdup (name);
35 else
36 obj->name = sstrdup ("");
37
38 obj->destructor = des;
39 obj->refcount = 1;
40 }
41
42 /*
43 * object_ref
44 *
45 * Increment the reference counter on an object.
46 *
47 * Inputs:
48 * - the object to refcount
49 *
50 * Outputs:
51 * - none
52 *
53 * Side Effects:
54 * - none
55 */
56 void *
57 object_ref (void *object)
58 {
59 return_val_if_fail (object != NULL, NULL);
60
61 asobject (object)->refcount++;
62
63 return object;
64 }
65
66 /*
67 * object_unref
68 *
69 * Decrement the reference counter on an object.
70 *
71 * Inputs:
72 * - the object to refcount
73 *
74 * Outputs:
75 * - none
76 *
77 * Side Effects:
78 * - if the refcount is 0, the object is destroyed.
79 */
80 void
81 object_unref (void *object)
82 {
83 object_t *obj;
84
85 return_if_fail (object != NULL);
86 obj = asobject (object);
87
88 obj->refcount--;
89
90 if (obj->refcount <= 0)
91 {
92 sfree (obj->name);
93
94 if (obj->destructor != NULL)
95 obj->destructor (obj);
96 else
97 sfree (obj);
98 }
99 }