~ubuntu-branches/ubuntu/natty/orbit2/natty

« back to all changes in this revision

Viewing changes to src/orb/orb-core/orbit-object.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Waters
  • Date: 2002-03-25 17:24:03 UTC
  • Revision ID: james.westby@ubuntu.com-20020325172403-8lexv63608acfqgt
Tags: upstream-2.3.107
ImportĀ upstreamĀ versionĀ 2.3.107

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <config.h>
 
2
#include <stdio.h>
 
3
#include <orbit/orbit.h>
 
4
 
 
5
#include "orbit-debug.h"
 
6
#include "orb-core-private.h"
 
7
 
 
8
static glong alive_root_objects = 0;
 
9
static glong total_refs = 0;
 
10
 
 
11
 
 
12
#ifdef G_ENABLE_DEBUG
 
13
static GHashTable *object_hash = NULL;
 
14
 
 
15
#define TYPE_CASE(e,n) \
 
16
        case ORBIT_ROT_##e: str = g_strdup (n); break;
 
17
 
 
18
static void
 
19
object_hash_dump (gpointer key,
 
20
                  gpointer value,
 
21
                  gpointer user_data)
 
22
{
 
23
        char *str = NULL;
 
24
        ORBit_RootObject obj = key;
 
25
        const ORBit_RootObject_Interface *interface = obj->interface;
 
26
        
 
27
        switch (interface->type) {
 
28
                TYPE_CASE (NULL, "Null");
 
29
        case ORBIT_ROT_OBJREF: {
 
30
                CORBA_Object o = (CORBA_Object) obj;
 
31
                str = g_strdup_printf ("Object (type '%s')",
 
32
                                       g_quark_to_string (o->type_qid));
 
33
                break;
 
34
        }
 
35
                /* psuedo-objects */
 
36
                TYPE_CASE (ORB, "ORB");
 
37
                TYPE_CASE (ADAPTOR, "Adaptor");
 
38
                TYPE_CASE (POLICY, "Policy");
 
39
                TYPE_CASE (TYPECODE, "TypeCode");
 
40
                TYPE_CASE (REQUEST, "Request");
 
41
                TYPE_CASE (SERVERREQUEST, "Server Request");
 
42
                TYPE_CASE (CONTEXT, "Context");
 
43
                TYPE_CASE (DYNANY, "Dynany");
 
44
                TYPE_CASE (OAOBJECT, "Object Adaptor Object");
 
45
                TYPE_CASE (ORBGROUP, "ORB Group");
 
46
                TYPE_CASE (POAMANAGER, "POA Manager");
 
47
                TYPE_CASE (POACURRENT, "Current POA");
 
48
        }
 
49
 
 
50
        if (!str)
 
51
                str = g_strdup_printf ("Error unknown type '%d'",
 
52
                                       interface->type);
 
53
 
 
54
        fprintf (stderr, "%3d ref%c to '%s'\n",
 
55
                 obj->refs, obj->refs ? 's' : ' ', str);
 
56
 
 
57
        g_free (str);
 
58
}
 
59
#endif
 
60
 
 
61
int
 
62
ORBit_RootObject_shutdown (void)
 
63
{
 
64
        int valid_running = 1; /* The ORB */
 
65
 
 
66
        if (!ORBit_RootObject_lifecycle_lock &&
 
67
            alive_root_objects - valid_running)
 
68
                g_warning ("ORB: a total of %ld refs to %ld ORB "
 
69
                           "objects were leaked",
 
70
                           total_refs - valid_running,
 
71
                           alive_root_objects - valid_running);
 
72
        else if (total_refs - valid_running)
 
73
                g_warning ("ORB: a total of %ld refs to ORB "
 
74
                           "objects were leaked",
 
75
                           total_refs - valid_running);
 
76
        else
 
77
                return 0;
 
78
 
 
79
#ifdef G_ENABLE_DEBUG
 
80
        if (_orbit_debug_flags & ORBIT_DEBUG_REFS)
 
81
                g_hash_table_foreach (
 
82
                        object_hash, object_hash_dump, NULL);
 
83
#endif
 
84
 
 
85
 
 
86
        return 1;
 
87
}
 
88
 
 
89
void
 
90
ORBit_RootObject_init (ORBit_RootObject obj,
 
91
                       const ORBit_RootObject_Interface *interface)
 
92
{
 
93
        if (!ORBit_RootObject_lifecycle_lock) /* No locking */
 
94
                alive_root_objects++;
 
95
 
 
96
#ifdef G_ENABLE_DEBUG
 
97
        if (!object_hash)
 
98
                object_hash = g_hash_table_new (NULL, NULL);
 
99
 
 
100
        if (_orbit_debug_flags & ORBIT_DEBUG_REFS)
 
101
                g_hash_table_insert (object_hash, obj, obj);
 
102
#endif
 
103
 
 
104
        obj->interface = interface;
 
105
        obj->refs = 0;
 
106
}
 
107
 
 
108
gpointer
 
109
ORBit_RootObject_duplicate (gpointer obj)
 
110
{
 
111
        ORBit_RootObject robj = obj;
 
112
 
 
113
        if (robj && robj->refs != ORBIT_REFCOUNT_STATIC) {
 
114
                LINC_MUTEX_LOCK   (ORBit_RootObject_lifecycle_lock);
 
115
                robj->refs++;
 
116
                total_refs++;
 
117
                LINC_MUTEX_UNLOCK (ORBit_RootObject_lifecycle_lock);
 
118
        }
 
119
 
 
120
        return obj;
 
121
}
 
122
 
 
123
gpointer
 
124
ORBit_RootObject_duplicate_T (gpointer obj)
 
125
{
 
126
        ORBit_RootObject robj = obj;
 
127
 
 
128
        if (robj && robj->refs != ORBIT_REFCOUNT_STATIC) {
 
129
                robj->refs++;
 
130
                total_refs++;
 
131
        }
 
132
 
 
133
        return obj;
 
134
}
 
135
 
 
136
static void
 
137
do_unref (ORBit_RootObject robj)
 
138
{
 
139
        g_assert (robj->refs < ORBIT_REFCOUNT_MAX && robj->refs > 0);
 
140
 
 
141
        robj->refs--;
 
142
        total_refs--;
 
143
 
 
144
        if (robj->refs == 0) {
 
145
                if (!ORBit_RootObject_lifecycle_lock) /* No locking */
 
146
                        alive_root_objects--;
 
147
#ifdef G_ENABLE_DEBUG
 
148
                if (_orbit_debug_flags & ORBIT_DEBUG_REFS)
 
149
                        g_hash_table_remove (object_hash, robj);
 
150
#endif
 
151
 
 
152
                if (robj->interface && robj->interface->destroy)
 
153
                        robj->interface->destroy (robj);
 
154
                else
 
155
                        g_free (robj);
 
156
        }
 
157
}
 
158
 
 
159
void
 
160
ORBit_RootObject_release_T (gpointer obj)
 
161
{
 
162
        ORBit_RootObject robj = obj;
 
163
 
 
164
        if (robj && robj->refs != ORBIT_REFCOUNT_STATIC)
 
165
                do_unref (robj);
 
166
}
 
167
 
 
168
void
 
169
ORBit_RootObject_release (gpointer obj)
 
170
{
 
171
        ORBit_RootObject robj = obj;
 
172
 
 
173
        if (robj && robj->refs != ORBIT_REFCOUNT_STATIC) {
 
174
 
 
175
                LINC_MUTEX_LOCK   (ORBit_RootObject_lifecycle_lock);
 
176
 
 
177
                do_unref (robj);
 
178
 
 
179
                LINC_MUTEX_UNLOCK (ORBit_RootObject_lifecycle_lock);
 
180
        }
 
181
}
 
182