From GridLAB-D Wiki
Jump to: navigation, search

Class Functions

It is possible to use gl_publish_function to give the GridLAB-D core an arbitrarily named function to use as a callback, by classes both internal and external to the module publishing the function.

In practice, this is used to allow objects to subscribe to another object, which either pushes or pulls values to and from those objects. Examples include the market module's auction object allowing objects to 'bid in' to a double auction, and for home appliances to push power draw to a house's circuit breaker panel.

Publishing Functions

Given a function int my_func(int, int, void *) and a GridLAB-D class my_class, we would publish the function with

fn = gl_publish_function(my_class, "my_func", (FUNCTIONADDR)my_func);

"fn" is a pointer to a FUNCTION struct. This will be a null pointer if the function could not be published for some reason, an event that should be caught by the module and should cause the simulation to stop prematurely.


FUNCTION struct

The FUNCTION struct is defined with

typedef struct s_function_map {
   OBJECTTYPE otype;
   FUNCTIONNAME name;
   FUNCTIONADDR addr;
   struct s_function_map *next;
} FUNCTION;

where FUNCTIONNAME is a string and FUNCTIONADDR is a void pointer.