globus_object.h

00001 /*
00002  * Copyright 1999-2006 University of Chicago
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #ifndef GLOBUS_OBJECT_H
00019 #define GLOBUS_OBJECT_H
00020 
00021 
00022 #include "globus_types.h"
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 /**********************************************************************
00029  * Object API Types
00030  *   globus_object_type_t          --   class definitions
00031  *   globus_object_t               --   class instances
00032  **********************************************************************/
00033 
00034 typedef void (*globus_object_copy_func_t) (void *  src_instance_data,
00035                                            void ** dst_instance_data);
00036 
00037 typedef void (*globus_object_destructor_func_t) (void * instance_data);
00038 
00039 typedef struct globus_object_type_s {
00040   const struct globus_object_type_s * const   parent_type;
00041   globus_object_copy_func_t const             copy_func;
00042   globus_object_destructor_func_t const       destructor;
00043   void * const                                class_data;
00044 } globus_object_type_t;
00045 
00046 typedef struct globus_object_s {
00047   const globus_object_type_t *   type;
00048   struct globus_object_s *       parent_object;
00049   void *                         instance_data;
00050   int                            ref_count;
00051 } globus_object_t;
00052 
00053 typedef char * (*globus_object_printable_string_func_t)
00054      (globus_object_t * error);
00055 
00056 
00057 /**********************************************************************
00058  * Object Creation API
00059  **********************************************************************/
00060 
00061 extern globus_object_t *
00062 globus_object_construct (const globus_object_type_t * create_type);
00063 /* returns new object, or 
00064  * returns NULL on any failure */
00065 
00066 extern globus_object_t *
00067 globus_object_initialize_base (globus_object_t * object);
00068 
00069 extern globus_object_t *
00070 globus_object_construct_base ();
00071 
00072 #define globus_object_static_initializer(object_type,                      \
00073                                          parent_prototype)                 \
00074 {                                                                          \
00075   (object_type),                                                           \
00076   (parent_prototype),                                                      \
00077   ((void *) NULL),                                                         \
00078   1                                                                        \
00079 }
00080 
00081 extern globus_object_t *
00082 globus_object_copy (const globus_object_t * object);
00083 /* returns fresh copy, or
00084  * returns NULL on error or if object is NULL */
00085 
00086 void
00087 globus_object_reference(globus_object_t * object);
00088 
00089 extern void
00090 globus_object_free (globus_object_t * object);
00091 /* does nothing if object is NULL or globus_object_is_static(object) is true
00092  */
00093 
00094 #define globus_object_type_static_initializer(parent_type,                 \
00095                                               copy_func,                   \
00096                                               destructor,                  \
00097                                               class_data)                  \
00098 {                                                                          \
00099   (parent_type),                                                           \
00100   (copy_func),                                                             \
00101   (destructor),                                                            \
00102   (class_data)                                                             \
00103 }
00104 
00105 #define globus_object_printable_type_static_initializer(pt,cf,df,s) \
00106         globus_object_type_static_initializer((pt),(cf),(df),(void *)(s))
00107 
00108 extern globus_object_t *
00109 globus_object_initialize_printable (globus_object_t * object);
00110 
00111 extern globus_object_t *
00112 globus_object_construct_printable ();
00113 
00114 
00115 /**********************************************************************
00116  * Standard Object Type
00117  **********************************************************************/
00118 
00119 extern const globus_object_type_t GLOBUS_OBJECT_TYPE_BASE_DEFINITION;
00120 #define GLOBUS_OBJECT_TYPE_BASE (&GLOBUS_OBJECT_TYPE_BASE_DEFINITION)
00121 
00122 extern const globus_object_type_t
00123 GLOBUS_OBJECT_TYPE_PRINTABLE_DEFINITION;
00124 #define GLOBUS_OBJECT_TYPE_PRINTABLE \
00125       (&GLOBUS_OBJECT_TYPE_PRINTABLE_DEFINITION)
00126 
00127 /**********************************************************************
00128  * Basic Static Object Value
00129  **********************************************************************/
00130 
00131 extern globus_object_t GLOBUS_OBJECT_BASE_STATIC_PROTOTYPE;
00132 #define GLOBUS_OBJECT_BASE_PROTOTYPE (&GLOBUS_OBJECT_BASE_STATIC_PROTOTYPE)
00133 
00134 extern globus_object_t 
00135 GLOBUS_OBJECT_PRINTABLE_STATIC_PROTOTYPE; 
00136 #define GLOBUS_OBJECT_PRINTABLE_PROTOTYPE \
00137       (&GLOBUS_OBJECT_PRINTABLE_STATIC_PROTOTYPE)
00138 
00139 /**********************************************************************
00140  * Object Manipulation API
00141  **********************************************************************/
00142 
00143 extern const globus_object_type_t *
00144 globus_object_get_type (const globus_object_t * object);
00145 /* returns type of object, or
00146  * returns NULL if object is NULL */
00147 
00148 extern const globus_object_type_t *
00149 globus_object_type_get_parent_type (const globus_object_type_t * type);
00150 /* returns parent type of type, or
00151  * returns NULL if type is NULL */
00152 
00153 extern globus_bool_t
00154 globus_object_is_static (const globus_object_t * object);
00155 /* returns GLOBUS_TRUE if either object is initialized by 
00156  *    globus_object_initialize_static() or
00157  * returns GLOBUS_FALSE otherwise */
00158 
00159 extern void *
00160 globus_object_type_get_class_data (const globus_object_type_t * type);
00161 /* returns class data (may be NULL), or 
00162  * returns NULL if object is NULL */
00163 
00164 extern globus_bool_t
00165 globus_object_type_match (const globus_object_type_t * subtype,
00166                           const globus_object_type_t * supertype);
00167 /* returns GLOBUS_TRUE iff subtype is an ancestor of supertype,
00168  * returns GLOBUS_FALSE otherwise */
00169 
00170 extern globus_object_t *
00171 globus_object_upcast (globus_object_t *      object,
00172                       const globus_object_type_t * desired_type);
00173 /* returns object representing the desired_type portion of the object if
00174  * the object was constructed as an instance of desired_type (or one of its
00175  *    descendants), or
00176  * returns NULL otherwise.
00177  * objects returned are shared subsets of the original object. */
00178 
00179 extern void
00180 globus_object_set_local_instance_data (globus_object_t * object,
00181                                        void *            instance_data);
00182 /* does nothing if object is NULL */
00183 
00184 extern void *
00185 globus_object_get_local_instance_data (const globus_object_t * object);
00186 /* returns instance data of object (may be NULL), or
00187  * returns NULL if object is NULL */
00188 
00189 
00190 extern char *
00191 globus_object_printable_to_string (globus_object_t * object);
00192 
00193 extern globus_object_printable_string_func_t 
00194 globus_object_printable_get_string_func (globus_object_t * object);
00195 
00196 #include "globus_module.h"
00197 
00198 extern globus_module_descriptor_t globus_i_object_module;
00199 
00200 #define GLOBUS_OBJECT_MODULE (&globus_i_object_module)
00201 
00202 #ifdef __cplusplus
00203 }
00204 #endif
00205 #endif /* GLOBUS_OBJECT_H */

Generated on 17 Mar 2017 for globus_common by  doxygen 1.4.7