/* Runtime classes. Copyright (C) 2001 Johan Rydberg. All Rights Reserved. This file is part of Crust. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __CFRuntime_h #define __CFRuntime_h 1 #include #include #include struct CFRuntimeClass { /* Version numbering. Should be zero at all time. */ CFIndex version; /* NULL-terminated string that represents the class name. */ const char *class_name; /* Size of instance. This must at least be greater than the size of CFRuntimeBase. */ unsigned int inst_size; /* Function to be called on a newly created instance. */ void (*init_fn) (void *inst); /* Called when an instance have lost all its references. */ void (*final_fn) (void *inst); }; typedef struct CFRuntimeClass CFRuntimeClass; typedef void (*CFSignalFunction) (CFTypeRef type, void *signal_arg, void *signal_data); struct CFRuntimeSignal { /* Point to next signal in list. */ struct CFRuntimeSignal *next_signal; /* Signal name. */ char *signal_name; /* Signal argument. */ void *signal_arg; /* Signal function. */ CFSignalFunction signal_fn; }; typedef struct CFRuntimeSignal CFRuntimeSignal; struct CFRuntimeBase { /* Spin lock for reference counter. */ spin_lock_t reflock; /* Pointer to first signal. */ CFRuntimeSignal *signal_list; /* Reference counter. When this drops to zero the instance can be deallocated. */ unsigned short refcount; /* Pointer to runtime class that this object is an instance of. */ struct CFRuntimeClass *inst_class; }; typedef struct CFRuntimeBase CFRuntimeBase; /* Register a new runtime class. Class information is contained in RUNTIME_CLASS. Class type ID is returned. */ CF_EXTERN CFTypeID CFRuntimeRegisterClass (CFRuntimeClass *runtime_class); /* Get runtime class structure from TYPE_ID. */ CF_EXTERN CFRuntimeClass *CFRuntimeGetClassWithTypeID (CFTypeID type_id); /* Allocate a new instance for class specified by TYPE_ID. NULL is returned if we ran out of memory. */ CF_EXTERN CFTypeRef CFRuntimeCreateInstance (CFTypeID type_id); /* Set instance type for instance INST to TYPE_ID. If TYPE_ID is unknown at this point - we leave the instance untouched. */ CF_EXTERN void CFRuntimeSetInstanceTypeID (CFTypeRef inst, CFTypeID type_id); /* Retain a reference to INST. */ CF_EXTERN void CFRetain (CFTypeRef inst); /* Release a reference to INST. If reference counter drops to zero the instance is deallocated. */ CF_EXTERN void CFRelease (CFTypeRef inst); /* Obtains the refernece count of an Core Foundation instance. */ CF_EXTERN int CFGetRetainCount (CFTypeRef inst); /* Obtains the unique identifier of the opaque tyoe to which INST belongs. */ CF_EXTERN CFTypeID CFGetTypeID (CFTypeRef inst); /* Connect instance OBJECT to signal SIGNAL_NAME. SIGNAL_ARG will be sent to signal function as second argument. */ CF_EXTERN void CFRuntimeSignalConnect (CFTypeRef object, char *signal_name, CFSignalFunction signal_fn, void *signal_arg); /* Emit SINGAL_NAME on OBJECT. SIGNAL_DATA will be sent a signal dependent data. Returns TRUE if signal was emitted. */ CF_EXTERN bool CFRuntimeSignalEmit (CFTypeRef object, char *signal_name, void *signal_data); #endif /* CFRuntime.h */