globus_common 18.14
Loading...
Searching...
No Matches
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
25extern "C" {
26#endif
27
28/**********************************************************************
29 * Object API Types
30 * globus_object_type_t -- class definitions
31 * globus_object_t -- class instances
32 **********************************************************************/
33
34typedef void (*globus_object_copy_func_t) (void * src_instance_data,
35 void ** dst_instance_data);
36
37typedef void (*globus_object_destructor_func_t) (void * instance_data);
38
39typedef 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
46typedef 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
53typedef char * (*globus_object_printable_string_func_t)
54 (globus_object_t * error);
55
56
57/**********************************************************************
58 * Object Creation API
59 **********************************************************************/
60
61extern globus_object_t *
62globus_object_construct (const globus_object_type_t * create_type);
63/* returns new object, or
64 * returns NULL on any failure */
65
66extern globus_object_t *
67globus_object_initialize_base (globus_object_t * object);
68
69extern globus_object_t *
70globus_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
81extern globus_object_t *
82globus_object_copy (const globus_object_t * object);
83/* returns fresh copy, or
84 * returns NULL on error or if object is NULL */
85
86void
87globus_object_reference(globus_object_t * object);
88
89extern void
90globus_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
108extern globus_object_t *
109globus_object_initialize_printable (globus_object_t * object);
110
111extern globus_object_t *
112globus_object_construct_printable ();
113
114
115/**********************************************************************
116 * Standard Object Type
117 **********************************************************************/
118
119extern const globus_object_type_t GLOBUS_OBJECT_TYPE_BASE_DEFINITION;
120#define GLOBUS_OBJECT_TYPE_BASE (&GLOBUS_OBJECT_TYPE_BASE_DEFINITION)
121
122extern const globus_object_type_t
123GLOBUS_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
131extern globus_object_t GLOBUS_OBJECT_BASE_STATIC_PROTOTYPE;
132#define GLOBUS_OBJECT_BASE_PROTOTYPE (&GLOBUS_OBJECT_BASE_STATIC_PROTOTYPE)
133
134extern globus_object_t
135GLOBUS_OBJECT_PRINTABLE_STATIC_PROTOTYPE;
136#define GLOBUS_OBJECT_PRINTABLE_PROTOTYPE \
137 (&GLOBUS_OBJECT_PRINTABLE_STATIC_PROTOTYPE)
138
139/**********************************************************************
140 * Object Manipulation API
141 **********************************************************************/
142
143extern const globus_object_type_t *
144globus_object_get_type (const globus_object_t * object);
145/* returns type of object, or
146 * returns NULL if object is NULL */
147
148extern const globus_object_type_t *
149globus_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
153extern globus_bool_t
154globus_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
159extern void *
160globus_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
164extern globus_bool_t
165globus_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
170extern globus_object_t *
171globus_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
179extern void
180globus_object_set_local_instance_data (globus_object_t * object,
181 void * instance_data);
182/* does nothing if object is NULL */
183
184extern void *
185globus_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
190extern char *
191globus_object_printable_to_string (globus_object_t * object);
192
193extern globus_object_printable_string_func_t
194globus_object_printable_get_string_func (globus_object_t * object);
195
196#include "globus_module.h"
197
198extern 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 */
Reference Counting Module Activation and Deactivation.
Common Primitive Types.
int globus_bool_t
Boolean type.
Definition globus_types.h:93
Module Descriptor.
Definition globus_module.h:72