The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
C-Class Management

Functions

FSTATIC void _init_proj_class_module (void)
 Initialize our object system tables. More...
 
FSTATIC void proj_class_change_debug (const char *Cclass, gint incr)
 Change debug level for this class and all its subclasses by 'incr'. More...
 
void proj_class_finalize_sys (void)
 Shut down (finalize) our object class system. Only do on shutdown to make valgrind happy :-D. More...
 
void proj_class_register_object (gpointer object, const char *static_classname)
 Log the creation of a new object, and its association with a given type. More...
 
void proj_class_register_debug_counter (const char *classname, guint *debugcount)
 
void proj_class_incr_debug (const char *Cclass)
 Increment debug level for this class and all its subclasses by one. More...
 
void proj_class_decr_debug (const char *Cclass)
 Decrement debug level for this class and all its subclasses by one. More...
 
gpointer proj_class_register_subclassed (gpointer object, const char *static_subclassname)
 Log the creation of a subclassed object from a superclassed object. More...
 
gpointer proj_class_new (gsize objsize, const char *static_classname)
 Malloc a new object and register it in our class system. More...
 
void proj_class_dissociate (gpointer object)
 Dissociate an object from the C class system (typically coupled with freeing it). More...
 
void proj_class_free (gpointer object)
 Free a registered object from our class system. More...
 
gboolean proj_class_is_a (gconstpointer object, const char *Cclass)
 Return TRUE if the given object ISA castclass object. More...
 
gpointer proj_class_castas (gpointer object, const char *castclass)
 "Safely" cast an object to a const object of the given C-class. More...
 
gconstpointer proj_class_castasconst (gconstpointer object, const char *castclass)
 "Safely" cast an object to a const object of the given C-class. More...
 
const char * proj_class_classname (gconstpointer object)
 Return the class name of one of our managed objects. More...
 
void proj_class_quark_add_superclass_relationship (GQuark superclass, GQuark subclass)
 Register a superclass/subclass relationship in our type system (using Quarks of the classes)) More...
 
gboolean proj_class_quark_is_a (GQuark objectclass, GQuark testclass)
 Determine whether an 'objectclass' ISA member of 'testclass' - with quarks of types as arguments Since this little C-class system only supports single-inheritance, this isn't exactly rocket science. More...
 
void proj_class_dump_live_objects (void)
 Dump all live C class objects (address and Class) More...
 
void proj_class_debug_dump (const char *prefix, const AssimObj *obj, const char *suffix)
 Send the object in question to g_debug() for printing... More...
 
guint32 proj_class_live_object_count (void)
 Return the count of live C class objects. More...
 
guint32 proj_class_max_object_count (void)
 Return the maximum number of live C class objects that we've ever had. More...
 

Variables

gboolean badfree = FALSE
 
#define MALLOCBASECLASS(Cclass)   ((Cclass *) proj_class_new(sizeof(Cclass), #Cclass))
 Allocate memory for a C-class object of base class class G(not to be further subclassed) - and register it with our C-Class system. More...
 
#define MALLOCCLASS(Cclass, size)   ((Cclass *) proj_class_new(size, #Cclass))
 Allocate memory for an object (which might be further subclassed) - and register it with our C-Class system. More...
 
#define CASTTOCLASS(Cclass, obj)   ((Cclass *) proj_class_castas(obj, #Cclass))
 Safely cast 'obj' to C-class 'class' - verifying that it was registerd as being of type class More...
 
#define NEWSUBCLASS(Cclass, obj)   ((Cclass *) proj_class_register_subclassed(obj, #Cclass))
 
#define CASTTOCONSTCLASS(Cclass, obj)   ((const Cclass *) proj_class_castasconst(obj, #Cclass))
 Safely cast 'obj' to const C-class 'class' - verifying that it was registered as being of type class More...
 
#define OBJ_IS_A(obj, Cclass)   proj_class_is_a(obj, Cclass)
 
#define FREECLASSOBJ(obj)   {proj_class_free(obj); obj = NULL;}
 Free a C-class object. More...
 
#define DEBUGVAR   __class_debug_count
 
#define DEBUGDECLARATIONS
 
#define BINDDEBUG(Cclass)   {if (!__class_debug_registered) {proj_class_register_debug_counter(#Cclass, &__class_debug_count); __class_debug_registered = TRUE;};}
 BINDDEBUG is for telling the class system where the debug variable for this class is - put it in the base constructor for the class. More...
 
#define DEBUG   (DEBUGVAR)
 
#define DEBUGMSG(...)   {if (DEBUG) {g_debug(__VA_ARGS__);};}
 
#define DEBUGMSGn(n,...)   {if (DEBUG >= (n)) {g_debug(__VA_ARGS__);};}
 
#define DEBUGMSG1(...)   DEBUGMSG ( __VA_ARGS__)
 
#define DEBUGMSG2(...)   DEBUGMSGn(2, __VA_ARGS__)
 
#define DEBUGMSG3(...)   DEBUGMSGn(3, __VA_ARGS__)
 
#define DEBUGMSG4(...)   DEBUGMSGn(4, __VA_ARGS__)
 
#define DEBUGMSG5(...)   DEBUGMSGn(5, __VA_ARGS__)
 
#define DUMP(prefix, obj, suffix)   {proj_class_debug_dump(prefix, obj, suffix);}
 
#define DUMP1(prefix, obj, suffix)   {if (DEBUG>=1) {DUMP(prefix, obj, suffix);};}
 
#define DUMP2(prefix, obj, suffix)   {if (DEBUG>=2) {DUMP(prefix, obj, suffix);};}
 
#define DUMP3(prefix, obj, suffix)   {if (DEBUG>=3) {DUMP(prefix, obj, suffix);};}
 
#define DUMP4(prefix, obj, suffix)   {if (DEBUG>=4) {DUMP(prefix, obj, suffix);};}
 
#define DUMP5(prefix, obj, suffix)   {if (DEBUG>=5) {DUMP(prefix, obj, suffix);};}
 

Detailed Description

Macro Definition Documentation

#define BINDDEBUG (   Cclass)    {if (!__class_debug_registered) {proj_class_register_debug_counter(#Cclass, &__class_debug_count); __class_debug_registered = TRUE;};}
#define CASTTOCLASS (   Cclass,
  obj 
)    ((Cclass *) proj_class_castas(obj, #Cclass))

Safely cast 'obj' to C-class 'class' - verifying that it was registerd as being of type class

Parameters
Cclassclass to cast obj (the object) to.
objthe object to be cast to type class

Definition at line 66 of file proj_classes.h.

Referenced by _addrframe_finalize(), _assimobj_ref(), _assimobj_unref(), _authlistener_associate(), _authlistener_dissociate(), _authlistener_finalize(), _authlistener_got_frameset(), _childprocess_childexit(), _childprocess_finalize(), _childprocess_setup_child(), _childprocess_timeout(), _compressframe_updatedata(), _configcontext_elem_toString(), _configcontext_finalize(), _configcontext_getaddr(), _configcontext_getarray(), _configcontext_getbool(), _configcontext_getconfig(), _configcontext_getframe(), _configcontext_getint(), _configcontext_getstring(), _configcontext_gettype(), _configcontext_getvalue(), _configcontext_value_finalize(), _configcontext_value_vfinalize(), _discovery_finalize(), _discovery_ghash_destructor(), _discovery_rediscover(), _frame_default_finalize(), _frameset_finalize(), _frameset_getseqno(), _frameset_indir_finalize(), _frameset_toString(), _fsprotocol_finalize(), _fsprotocol_send(), _fsprotocol_timeoutfun(), _fsprotocol_xmitifwecan(), _fsqueue_deq(), _fsqueue_finalize(), _fsqueue_flush(), _fsqueue_flush1(), _fsqueue_inqsorted(), _fsqueue_qhead(), _fsqueue_toString(), _hblistener_checktimeouts(), _hblistener_finalize(), _hbsender_gsourcefunc(), _hbsender_notify_function(), _intframe_updatedata(), _ipportframe_finalize(), _jsondiscovery_childwatch(), _jsondiscovery_discover(), _jsondiscovery_finalize(), _listener_finalize(), _nano_send_rscexitstatus(), _netaddr_finalize(), _netgsource_check(), _netgsource_del_listener(), _netgsource_dispatch(), _netgsource_finalize(), _netio_finalize(), _netio_netaddr_destroy(), _netio_sendframesets(), _packetdecoder_finalize(), _reliableudp_ackmessage(), _reliableudp_closeconn(), _reliableudp_finalize(), _reliableudp_outputpending(), _reliableudp_recvframesets(), _reliableudp_sendareliablefs(), _reliableudp_sendreliablefs(), _resource_queue_cancel(), _resource_queue_cancelall(), _resource_queue_endnotify(), _resource_queue_finalize(), _resource_queue_hash_data_destructor(), _resource_queue_runqueue(), _resourcecmd_finalize(), _resourcelsb_child_notify(), _resourcelsb_execute(), _resourcelsb_finalize(), _resourceocf_child_notify(), _resourceocf_execute(), _resourceocf_finalize(), _seqnoframe_updatedata(), _shell_array_value(), _signframe_updatedata(), _switchdiscovery_dispatch(), _switchdiscovery_finalize(), address_tests(), addrframe_new(), cast_frameset_tests(), check_JSON(), check_output_at_exit(), cryptframe_new(), cryptframe_tlvconstructor(), cstringframe_tlvconstructor(), frameset_construct_packet(), frameset_dump(), g_source_pcap_check(), g_source_pcap_dispatch(), g_source_pcap_finalize(), g_source_pcap_new(), gmainfd_gsource_check(), gmainfd_gsource_dispatch(), gmainfd_gsource_finalize(), hblistener_find_by_address(), hblistener_new(), hblistener_shutdown(), hbsender_stopallsenders(), hbsender_stopsend(), intframe_new(), intframe_tlvconstructor(), logsourcefd_finalize(), logsourcefd_newtext(), main(), nano_initiate_shutdown(), nano_shutdown(), nano_start_full(), nanoobey_cancelrscoperation(), nanoobey_change_debug(), nanoobey_dorscoperation(), nanoobey_expecthb(), nanoobey_sendhb(), nanoobey_setconfig(), nanoobey_startdiscover(), nanoobey_stopdiscover(), nanoobey_stopexpecthb(), nanoobey_stopsendhb(), netaddr_new(), netgsource_new(), netio_new(), netioudp_new(), nvpairframe_new(), nvpairframe_tlvconstructor(), obey_pingpong(), packetdecoder_new(), proj_class_dump_live_objects(), quit_at_child_exit(), quit_at_childprocess_exit(), seqnoframe_tlvconstructor(), shutdown_when_outdone(), signframe_new(), signframe_tlvconstructor(), switchdiscovery_new(), timeout_agent(), unknownframe_new(), and unknownframe_tlvconstructor().

#define CASTTOCONSTCLASS (   Cclass,
  obj 
)    ((const Cclass *) proj_class_castasconst(obj, #Cclass))
#define DEBUG   (DEBUGVAR)

Definition at line 85 of file proj_classes.h.

Referenced by _fsprotocol_closeconn(), and _jsondiscovery_childwatch().

#define DEBUGDECLARATIONS
Value:
static gboolean __class_debug_registered = FALSE; \
static guint __class_debug_count = 0;

Definition at line 79 of file proj_classes.h.

#define DEBUGMSG4 (   ...)    DEBUGMSGn(4, __VA_ARGS__)
#define DEBUGMSGn (   n,
  ... 
)    {if (DEBUG >= (n)) {g_debug(__VA_ARGS__);};}

Definition at line 88 of file proj_classes.h.

#define DEBUGVAR   __class_debug_count

Definition at line 78 of file proj_classes.h.

#define DUMP (   prefix,
  obj,
  suffix 
)    {proj_class_debug_dump(prefix, obj, suffix);}
#define DUMP1 (   prefix,
  obj,
  suffix 
)    {if (DEBUG>=1) {DUMP(prefix, obj, suffix);};}

Definition at line 95 of file proj_classes.h.

#define DUMP2 (   prefix,
  obj,
  suffix 
)    {if (DEBUG>=2) {DUMP(prefix, obj, suffix);};}

Definition at line 96 of file proj_classes.h.

Referenced by _fsproto_fsa(), _reliableudp_closeconn(), and _reliableudp_finalize().

#define DUMP4 (   prefix,
  obj,
  suffix 
)    {if (DEBUG>=4) {DUMP(prefix, obj, suffix);};}

Definition at line 98 of file proj_classes.h.

Referenced by _fsprotocol_read(), and _fsqueue_flush().

#define DUMP5 (   prefix,
  obj,
  suffix 
)    {if (DEBUG>=5) {DUMP(prefix, obj, suffix);};}
#define FREECLASSOBJ (   obj)    {proj_class_free(obj); obj = NULL;}
#define MALLOCBASECLASS (   Cclass)    ((Cclass *) proj_class_new(sizeof(Cclass), #Cclass))

Allocate memory for a C-class object of base class class G(not to be further subclassed) - and register it with our C-Class system.

Parameters
Cclassname of class to malloc data for. Amount malloced will be sizeof(class), return type is class*.
Returns
sizeof(class) bytes of newly allocated heap data of type class*. Don't forget to give it to FREECLASSOBJ eventually.

Definition at line 55 of file proj_classes.h.

Referenced by netgsource_new().

#define MALLOCCLASS (   Cclass,
  size 
)    ((Cclass *) proj_class_new(size, #Cclass))

Allocate memory for an object (which might be further subclassed) - and register it with our C-Class system.

Parameters
Cclassname of class to malloc data for
sizenumber of bytes to malloc
Returns
size bytes of newly allocated heap data of type class*. Don't forget to give it to FREECLASSOBJ eventually.

Definition at line 61 of file proj_classes.h.

Referenced by _resource_queue_qelem_new(), assimobj_new(), and hbsender_new().

#define OBJ_IS_A (   obj,
  Cclass 
)    proj_class_is_a(obj, Cclass)

Function Documentation

FSTATIC void _init_proj_class_module ( void  )

Initialize our object system tables.

Definition at line 79 of file proj_classes.c.

Referenced by proj_class_register_debug_counter(), proj_class_register_object(), and proj_class_register_subclassed().

Here is the caller graph for this function:

gpointer proj_class_castas ( gpointer  object,
const char *  castclass 
)

"Safely" cast an object to a const object of the given C-class.

"Safely" cast an object to a given C-class. What we mean by that, is that before returning, we verify that the object in question ISA castclass object. If it's not, we abort. Better a semi-predictable abort than a random and unpredictable crash.

Parameters
objectObject to be "cast" as "castclass"
castclassClass to cast "object" as

Definition at line 285 of file proj_classes.c.

References BADCASTMSG, badfree, OBJ_IS_A, and proj_class_classname().

Here is the call graph for this function:

gconstpointer proj_class_castasconst ( gconstpointer  object,
const char *  castclass 
)

"Safely" cast an object to a const object of the given C-class.

What we mean by that, is that before returning, we verify that the object in question ISA castclass object. If it's not, we abort. Better a semi-predictable abort than a random and unpredictable crash.

Parameters
objectObject to be "cast" to "castclass"
castclassClass to cast "object" as

Definition at line 305 of file proj_classes.c.

References BADCASTMSG, badfree, proj_class_classname(), and proj_class_is_a().

Here is the call graph for this function:

FSTATIC void proj_class_change_debug ( const char *  Cclass,
gint  incr 
)

Change debug level for this class and all its subclasses by 'incr'.

NULL Cclass class name means modify debug for all classes.

Definition at line 156 of file proj_classes.c.

References classname, and proj_class_quark_is_a().

Referenced by proj_class_decr_debug(), and proj_class_incr_debug().

Here is the call graph for this function:

Here is the caller graph for this function:

const char* proj_class_classname ( gconstpointer  object)

Return the class name of one of our managed objects.

Return the class name of one of our managed objects

Parameters
objectpointer to the object whose name we want to find

Definition at line 324 of file proj_classes.c.

Referenced by _assimobj_toString(), _frame_dump(), cma.AssimCclasses.pyAssimObj::cclassname(), cma.AssimCclasses.pyFrame::Cstruct2Frame(), frameset_construct_packet(), proj_class_castas(), proj_class_castasconst(), and proj_class_dump_live_objects().

Here is the caller graph for this function:

void proj_class_debug_dump ( const char *  prefix,
const AssimObj obj,
const char *  suffix 
)

Send the object in question to g_debug() for printing...

Definition at line 382 of file proj_classes.c.

References cma.monitoring::pad, and _AssimObj::toString.

void proj_class_decr_debug ( const char *  Cclass)

Decrement debug level for this class and all its subclasses by one.

NULL Cclass class name means decrement debug for all classes.

Definition at line 148 of file proj_classes.c.

References proj_class_change_debug().

Referenced by catch_a_signal(), nanoobey_change_debug(), cma.tests.cclass_wrappers_test.pyNetAddrTest::test_dns_strinit(), cma.tests.cclass_wrappers_test.pyNetAddrTest::test_ipv6_strinit(), and cma.tests.cclass_wrappers_test.pyConfigContextTest::test_kitchen_sink().

Here is the call graph for this function:

Here is the caller graph for this function:

void proj_class_dissociate ( gpointer  object)

Dissociate an object from the C class system (typically coupled with freeing it).

If it's not a registered C-class object, we abort. Better a semi-predictable abort than a random and unpredictable crash.

Parameters
objectObject be 'dissociated' from class

Definition at line 228 of file proj_classes.c.

References BADCASTMSG, and badfree.

Referenced by _netgsource_finalize(), g_source_pcap_finalize(), gmainfd_gsource_finalize(), and proj_class_free().

Here is the caller graph for this function:

void proj_class_finalize_sys ( void  )

Shut down (finalize) our object class system. Only do on shutdown to make valgrind happy :-D.

Definition at line 88 of file proj_classes.c.

Referenced by main().

Here is the caller graph for this function:

void proj_class_free ( gpointer  object)

Free a registered object from our class system.

If it's not a registered C-class object, we abort. Better a semi-predictable abort than a random and unpredictable crash.

Parameters
objectObject be freed

Definition at line 249 of file proj_classes.c.

References FREE, and proj_class_dissociate().

Here is the call graph for this function:

void proj_class_incr_debug ( const char *  Cclass)

Increment debug level for this class and all its subclasses by one.

NULL Cclass class name means increment debug for all classes.

Definition at line 140 of file proj_classes.c.

References proj_class_change_debug().

Referenced by catch_a_signal(), cma.cma::main(), main(), nanoobey_change_debug(), cma.tests.cclass_wrappers_test.pyNetAddrTest::test_dns_strinit(), cma.tests.cclass_wrappers_test.pyNetAddrTest::test_ipv6_strinit(), and cma.tests.cclass_wrappers_test.pyConfigContextTest::test_kitchen_sink().

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean proj_class_is_a ( gconstpointer  object,
const char *  Cclass 
)

Return TRUE if the given object ISA castclass object.

Parameters
object[i] Object to be queried
Cclass[i] Class to be queried

Definition at line 257 of file proj_classes.c.

References proj_class_quark_is_a().

Referenced by proj_class_castasconst().

Here is the call graph for this function:

Here is the caller graph for this function:

guint32 proj_class_max_object_count ( void  )

Return the maximum number of live C class objects that we've ever had.

Definition at line 426 of file proj_classes.c.

Referenced by cma.messagedispatcher.MessageDispatcher::dispatch().

Here is the caller graph for this function:

gpointer proj_class_new ( gsize  objsize,
const char *  static_classname 
)

Malloc a new object and register it in our class system.

Parameters
objsizeSize of object to be allocated
static_classnameStatic string giving name of class

Definition at line 214 of file proj_classes.c.

References MALLOC0, and proj_class_register_object().

Here is the call graph for this function:

void proj_class_quark_add_superclass_relationship ( GQuark  superclass,
GQuark  subclass 
)

Register a superclass/subclass relationship in our type system (using Quarks of the classes))

Parameters
superclassQuark for Superclass
subclassQuark for Subclass

Definition at line 333 of file proj_classes.c.

Referenced by proj_class_register_subclassed().

Here is the caller graph for this function:

gboolean proj_class_quark_is_a ( GQuark  objectclass,
GQuark  testclass 
)

Determine whether an 'objectclass' ISA member of 'testclass' - with quarks of types as arguments Since this little C-class system only supports single-inheritance, this isn't exactly rocket science.

Parameters
objectclassObject to be tested
testclassClass/Superclass to test object against

Definition at line 342 of file proj_classes.c.

Referenced by proj_class_change_debug(), and proj_class_is_a().

Here is the caller graph for this function:

void proj_class_register_debug_counter ( const char *  classname,
guint *  debugcount 
)

Definition at line 122 of file proj_classes.c.

References _init_proj_class_module().

Here is the call graph for this function:

void proj_class_register_object ( gpointer  object,
const char *  static_classname 
)

Log the creation of a new object, and its association with a given type.

This involves locating (or registering) the class, and creating an association of the object with a given class (type).

Parameters
objectObject to be registered
static_classnameClass to register it as

Definition at line 100 of file proj_classes.c.

References _init_proj_class_module().

Referenced by g_source_pcap_new(), gmainfd_new(), netgsource_new(), and proj_class_new().

Here is the call graph for this function:

Here is the caller graph for this function:

gpointer proj_class_register_subclassed ( gpointer  object,
const char *  static_subclassname 
)

Log the creation of a subclassed object from a superclassed object.

The subclass name given must be the immediate subclass of the class of the object, not through multiple levels of subclassing.

todo create a superclass/subclass hierarchy...

Parameters
objectObject (currently registered as superclass)
static_subclassnameSubclass to register it as

Definition at line 192 of file proj_classes.c.

References _init_proj_class_module(), and proj_class_quark_add_superclass_relationship().

Referenced by addrframe_new(), cryptframe_new(), g_source_pcap_new(), hblistener_new(), intframe_new(), netaddr_new(), netgsource_new(), netioudp_new(), nvpairframe_new(), packetdecoder_new(), signframe_new(), switchdiscovery_new(), and unknownframe_new().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

gboolean badfree = FALSE

Definition at line 72 of file proj_classes.c.

Referenced by proj_class_castas(), proj_class_castasconst(), and proj_class_dissociate().