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