1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
13 #ifndef _ASF_DEBUG_MOONLIGHT_H
14 #define _ASF_DEBUG_MOONLIGHT_H
23 ObjectTracker (const char* tn
)
28 printf ("ObjectTracer::ObjectTracker (%s): id = %i\n", tn
, id
);
33 printf ("ObjectTracker::~ObjectTracker (%s): id = %i\n", tn
, id
);
38 static bool PrintStatus (const char* tn
)
40 GHashTable
* list
= NULL
;
42 if (current_objects
!= NULL
) {
43 list
= (GHashTable
*)g_hash_table_lookup (current_objects
, tn
);
47 guint count
= g_hash_table_size (list
);
49 printf ("ObjectTracking::PrintStatus (%s): No unfreed objects.\n", tn
);
51 printf ("ObjectTracking::PrintStatus (%s): %u unfreed objects:\n", tn
, count
);
53 g_hash_table_foreach (list
, print
, &max_items
);
57 printf ("ObjectTracking::PrintStatus (%s): No objects tracked.\n", tn
);
63 static void print (gpointer key
, gpointer value
, gpointer user_data
)
65 ObjectTracker
* obj
= (ObjectTracker
*) value
;
67 int items_left
= *(int*)user_data
;
68 if (items_left
>= 0) {
69 printf (" ObjectTracking::Print (%s): #%i is still alive.\n", obj
->tn
, obj
->id
);
74 int GetNextID (const char* tn
)
78 if (current_ids
== NULL
)
79 current_ids
= g_hash_table_new (g_str_hash
, g_str_equal
);
84 if (g_hash_table_lookup_extended (current_ids
, tn
, NULL
, &idp
)) {
85 idn
= GPOINTER_TO_INT (idp
);
90 printf ("ObjectTracer::GetNextID (%s): %i\n", tn
, result
);
92 g_hash_table_insert (current_ids
, (gpointer
) tn
, GINT_TO_POINTER (idn
));
99 GHashTable
* list
= NULL
;
101 if (current_objects
== NULL
)
102 current_objects
= g_hash_table_new (g_str_hash
, g_str_equal
);
104 list
= (GHashTable
*) g_hash_table_lookup (current_objects
, tn
);
107 list
= g_hash_table_new (g_direct_hash
, g_direct_equal
);
108 g_hash_table_insert (current_objects
, (gpointer
) tn
, list
);
110 g_hash_table_insert (list
, GINT_TO_POINTER (id
), this);
115 GHashTable
* list
= NULL
;
117 if (current_objects
== NULL
) {
118 printf ("ObjectTracker::Remove (): the hashtable where I should be is NULL.\n");
122 list
= (GHashTable
*) g_hash_table_lookup (current_objects
, tn
);
125 printf ("ObjectTracker::Remove (): the list where the I should be is NULL.\n");
129 g_hash_table_remove (list
, GINT_TO_POINTER (id
));
132 // No automagic C++ stuff.
134 ObjectTracker (const ObjectTracker
&);
135 ObjectTracker
operator= (const ObjectTracker
&);
139 static GHashTable
* current_ids
;
140 static GHashTable
* current_objects
;