Working with the enactment history

Previous: Working with users ] [ Top:  ] [ Next: Sending notifications ]

Everything that happens to a process is stored in its enactment history. At some point the level of enactment will be parametrized, but for the time being, we write an enactment entry on each task action, each data setting, and probably each request or alert. We also provide a log function which can be called with an arbitrary string.

The userid in the session is used to mark who took each action; at this level, that's not authenticated at all, simply set using wftk_session_setuser. Caveat callor.

Anyway, the enactment itself is just a child of the main datasheet element which is an "enactment" node. If there isn't one, we create it, pretty much the same as the state.
WFTK_EXPORT XML * wftk_enactment (XML * session, XML * datasheet)
   XML * en;

   en = xml_loc (datasheet, ".enactment");
   if (!en) {
      en = xml_create ("enactment");
      xml_append_pretty (datasheet, en);

   return (en);
To write an enactment entry, we take an arbitrary piece of XML, copy its head element, copy that element's attributes, add a by= which is taken from the session's assigned user and an at= which is the current time, and tack it onto the enactment. Note that this isn't actually saving the datasheet.
WFTK_EXPORT int wftk_enactment_write (XML * session, XML * datasheet, XML * xml, const char * attribute, const char * value)
   XML * copy;
   XML_ATTR * attr;
   XML * en = wftk_enactment (session, datasheet);
   if (!en) return 0;

   if (!xml) return 0;

   copy = xml_create (xml_name (xml));
   attr = xml_attrfirst (xml);
   while (attr) {
      xml_set (copy, xml_attrname (attr), xml_attrvalue (attr));
      attr = xml_attrnext (attr);
   if (wftk_session_getuser(session)) {
      xml_set (copy, "by", xml_attrval (wftk_session_getuser(session), "id"));
   xml_set_nodup (copy, "at", _wftk_value_special (session, datasheet, "!now"));
   if (attribute && value) {
      xml_set (copy, attribute, value);
   xml_append_pretty (en, copy);

   return 1;
Our final little piece is a more convenient log-entry call which takes a string, wraps a log element around it, and calls the above function.
WFTK_EXPORT int wftk_log (XML * session, XML * datasheet, char * log)
   int retval;
   XML * logxml = xml_create ("log");

   xml_set (logxml, "text", log);
   retval = wftk_enactment_write (session, datasheet, logxml, NULL, NULL);
   xml_free (logxml);
   return (retval);
That wasn't so hard, was it?
Previous: Working with users ] [ Top:  ] [ Next: Sending notifications ]

This code and documentation are released under the terms of the GNU license. They are copyright (c) 2000-2004, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.