globus_common  17.9
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
globus_object.h
1 
2 
3 #ifndef GLOBUS_OBJECT_H
4 #define GLOBUS_OBJECT_H
5 
6 
7 #include "globus_types.h"
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /**********************************************************************
14  * Object API Types
15  * globus_object_type_t -- class definitions
16  * globus_object_t -- class instances
17  **********************************************************************/
18 
19 typedef void (*globus_object_copy_func_t) (void * src_instance_data,
20  void ** dst_instance_data);
21 
22 typedef void (*globus_object_destructor_func_t) (void * instance_data);
23 
24 typedef struct globus_object_type_s {
25  const struct globus_object_type_s * const parent_type;
26  globus_object_copy_func_t const copy_func;
27  globus_object_destructor_func_t const destructor;
28  void * const class_data;
29 } globus_object_type_t;
30 
31 typedef struct globus_object_s {
32  const globus_object_type_t * type;
33  struct globus_object_s * parent_object;
34  void * instance_data;
35  int ref_count;
36 } globus_object_t;
37 
38 typedef char * (*globus_object_printable_string_func_t)
39  (globus_object_t * error);
40 
41 
42 /**********************************************************************
43  * Object Creation API
44  **********************************************************************/
45 
46 extern globus_object_t *
47 globus_object_construct (const globus_object_type_t * create_type);
48 /* returns new object, or
49  * returns NULL on any failure */
50 
51 extern globus_object_t *
52 globus_object_initialize_base (globus_object_t * object);
53 
54 extern globus_object_t *
55 globus_object_construct_base ();
56 
57 #define globus_object_static_initializer(object_type, \
58  parent_prototype) \
59 { \
60  (object_type), \
61  (parent_prototype), \
62  ((void *) NULL), \
63  1 \
64 }
65 
66 extern globus_object_t *
67 globus_object_copy (const globus_object_t * object);
68 /* returns fresh copy, or
69  * returns NULL on error or if object is NULL */
70 
71 void
72 globus_object_reference(globus_object_t * object);
73 
74 extern void
75 globus_object_free (globus_object_t * object);
76 /* does nothing if object is NULL or globus_object_is_static(object) is true
77  */
78 
79 #define globus_object_type_static_initializer(parent_type, \
80  copy_func, \
81  destructor, \
82  class_data) \
83 { \
84  (parent_type), \
85  (copy_func), \
86  (destructor), \
87  (class_data) \
88 }
89 
90 #define globus_object_printable_type_static_initializer(pt,cf,df,s) \
91  globus_object_type_static_initializer((pt),(cf),(df),(void *)(s))
92 
93 extern globus_object_t *
94 globus_object_initialize_printable (globus_object_t * object);
95 
96 extern globus_object_t *
97 globus_object_construct_printable ();
98 
99 
100 /**********************************************************************
101  * Standard Object Type
102  **********************************************************************/
103 
104 extern const globus_object_type_t GLOBUS_OBJECT_TYPE_BASE_DEFINITION;
105 #define GLOBUS_OBJECT_TYPE_BASE (&GLOBUS_OBJECT_TYPE_BASE_DEFINITION)
106 
107 extern const globus_object_type_t
108 GLOBUS_OBJECT_TYPE_PRINTABLE_DEFINITION;
109 #define GLOBUS_OBJECT_TYPE_PRINTABLE \
110  (&GLOBUS_OBJECT_TYPE_PRINTABLE_DEFINITION)
111 
112 /**********************************************************************
113  * Basic Static Object Value
114  **********************************************************************/
115 
116 extern globus_object_t GLOBUS_OBJECT_BASE_STATIC_PROTOTYPE;
117 #define GLOBUS_OBJECT_BASE_PROTOTYPE (&GLOBUS_OBJECT_BASE_STATIC_PROTOTYPE)
118 
119 extern globus_object_t
120 GLOBUS_OBJECT_PRINTABLE_STATIC_PROTOTYPE;
121 #define GLOBUS_OBJECT_PRINTABLE_PROTOTYPE \
122  (&GLOBUS_OBJECT_PRINTABLE_STATIC_PROTOTYPE)
123 
124 /**********************************************************************
125  * Object Manipulation API
126  **********************************************************************/
127 
128 extern const globus_object_type_t *
129 globus_object_get_type (const globus_object_t * object);
130 /* returns type of object, or
131  * returns NULL if object is NULL */
132 
133 extern const globus_object_type_t *
134 globus_object_type_get_parent_type (const globus_object_type_t * type);
135 /* returns parent type of type, or
136  * returns NULL if type is NULL */
137 
138 extern globus_bool_t
139 globus_object_is_static (const globus_object_t * object);
140 /* returns GLOBUS_TRUE if either object is initialized by
141  * globus_object_initialize_static() or
142  * returns GLOBUS_FALSE otherwise */
143 
144 extern void *
145 globus_object_type_get_class_data (const globus_object_type_t * type);
146 /* returns class data (may be NULL), or
147  * returns NULL if object is NULL */
148 
149 extern globus_bool_t
150 globus_object_type_match (const globus_object_type_t * subtype,
151  const globus_object_type_t * supertype);
152 /* returns GLOBUS_TRUE iff subtype is an ancestor of supertype,
153  * returns GLOBUS_FALSE otherwise */
154 
155 extern globus_object_t *
156 globus_object_upcast (globus_object_t * object,
157  const globus_object_type_t * desired_type);
158 /* returns object representing the desired_type portion of the object if
159  * the object was constructed as an instance of desired_type (or one of its
160  * descendants), or
161  * returns NULL otherwise.
162  * objects returned are shared subsets of the original object. */
163 
164 extern void
165 globus_object_set_local_instance_data (globus_object_t * object,
166  void * instance_data);
167 /* does nothing if object is NULL */
168 
169 extern void *
170 globus_object_get_local_instance_data (const globus_object_t * object);
171 /* returns instance data of object (may be NULL), or
172  * returns NULL if object is NULL */
173 
174 
175 extern char *
176 globus_object_printable_to_string (globus_object_t * object);
177 
178 extern globus_object_printable_string_func_t
179 globus_object_printable_get_string_func (globus_object_t * object);
180 
181 #include "globus_module.h"
182 
183 extern globus_module_descriptor_t globus_i_object_module;
184 
185 #define GLOBUS_OBJECT_MODULE (&globus_i_object_module)
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 #endif /* GLOBUS_OBJECT_H */
Common Primitive Types.
int globus_bool_t
Boolean type.
Definition: globus_types.h:78
Reference Counting Module Activation and Deactivation.
Module Descriptor.
Definition: globus_module.h:54