Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Functions
xml.cpp File Reference
#include <portability.h>
#include "xml.h"
#include "agent.h"
#include "soar_TraceNames.h"
#include "XMLTrace.h"
#include "ElementXML.h"
#include "print.h"
#include "wmem.h"
#include "assert.h"

Go to the source code of this file.

Functions

void xml_att_val (agent *pAgent, char const *pAttribute, uint64_t value)
void xml_att_val (agent *pAgent, char const *pAttribute, int value)
void xml_att_val (agent *pAgent, char const *pAttribute, int64_t value)
void xml_att_val (agent *pAgent, char const *pAttribute, double value)
void xml_att_val (agent *pAgent, char const *pAttribute, char const *pValue)
void xml_att_val (agent *pAgent, char const *pAttribute, Symbol *pSymbol)
void xml_begin_command_mode (agent *pAgent)
void xml_begin_tag (agent *pAgent, char const *pTag)
void xml_create (agent *pAgent)
void xml_destroy (agent *pAgent)
soarxml::ElementXML * xml_end_command_mode (agent *pAgent)
void xml_end_tag (agent *pAgent, char const *pTag)
void xml_generate_error (agent *pAgent, const char *pMessage)
void xml_generate_message (agent *pAgent, const char *pMessage)
void xml_generate_verbose (agent *pAgent, const char *pMessage)
void xml_generate_warning (agent *pAgent, const char *pMessage)
soarxml::ElementXML * xml_get_xml (agent *pAgent)
void xml_invoke_callback (agent *pAgent)
void xml_move_current_to_child (agent *pAgent, int index)
void xml_move_current_to_last_child (agent *pAgent)
void xml_move_current_to_parent (agent *pAgent)
void xml_object (agent *pAgent, char const *pTag)
void xml_object (agent *pAgent, char const *pTag, char const *pAttribute, char const *pValue)
void xml_object (agent *pAgent, char const *pTag, char const *pAttribute, uint64_t value)
void xml_object (agent *pAgent, char const *pTag, char const *pAttribute, int64_t value)
void xml_object (agent *pAgent, char const *pTag, char const *pAttribute, double value)
void xml_object (agent *pAgent, wme *pWME, bool printTimetag)
void xml_reset (agent *pAgent)

Function Documentation

void xml_att_val ( agent pAgent,
char const *  pAttribute,
uint64_t  value 
)
void xml_att_val ( agent pAgent,
char const *  pAttribute,
int  value 
)

Definition at line 141 of file xml.cpp.

References agent_struct::xml_destination.

{
char buf[51];
SNPRINTF(buf, 50, "%d", value);
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->AddAttribute( pAttribute, buf ) ;
}
void xml_att_val ( agent pAgent,
char const *  pAttribute,
int64_t  value 
)

Definition at line 150 of file xml.cpp.

References agent_struct::xml_destination.

{
char buf[51];
SNPRINTF(buf, 50, "%lld", static_cast<long long>(value));
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->AddAttribute( pAttribute, buf ) ;
}
void xml_att_val ( agent pAgent,
char const *  pAttribute,
double  value 
)

Definition at line 159 of file xml.cpp.

References agent_struct::xml_destination.

{
char buf[51];
SNPRINTF(buf, 50, "%f", value);
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->AddAttribute( pAttribute, buf ) ;
}
void xml_att_val ( agent pAgent,
char const *  pAttribute,
char const *  pValue 
)

Definition at line 168 of file xml.cpp.

References agent_struct::xml_destination.

{
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->AddAttribute( pAttribute, pValue ) ;
}
void xml_att_val ( agent pAgent,
char const *  pAttribute,
Symbol pSymbol 
)

Definition at line 174 of file xml.cpp.

References symbol_to_string(), and agent_struct::xml_destination.

{
// Passing 0, 0 as buffer to symbol to string causes it to use internal, temporary buffers
// which is fine because we immediately copy that string in XMLAddAttribute.
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->AddAttribute( pAttribute, symbol_to_string( pAgent, pSymbol, true, 0, 0 ) ) ;
}
void xml_begin_command_mode ( agent pAgent)

Definition at line 320 of file xml.cpp.

References agent_struct::xml_commands, agent_struct::xml_destination, and agent_struct::xml_trace.

{
if ( !pAgent || !pAgent->xml_trace || !pAgent->xml_commands )
{
assert( pAgent );
assert( pAgent->xml_trace );
assert( pAgent->xml_commands );
return;
}
pAgent->xml_destination = pAgent->xml_commands;
}
void xml_begin_tag ( agent pAgent,
char const *  pTag 
)
void xml_create ( agent pAgent)

Definition at line 44 of file xml.cpp.

References agent_struct::xml_commands, agent_struct::xml_destination, and agent_struct::xml_trace.

Referenced by create_soar_agent().

{
if ( !pAgent )
{
assert( pAgent );
return;
}
soarxml::XMLTrace* pTrace = new soarxml::XMLTrace();
soarxml::XMLTrace* pCommands = new soarxml::XMLTrace();
pAgent->xml_trace = static_cast< xml_handle >( pTrace );
pAgent->xml_commands = static_cast< xml_handle >( pCommands );
pAgent->xml_destination = pAgent->xml_trace;
}
void xml_destroy ( agent pAgent)

Definition at line 78 of file xml.cpp.

References agent_struct::xml_commands, agent_struct::xml_destination, and agent_struct::xml_trace.

Referenced by destroy_soar_agent().

{
if ( !pAgent || !pAgent->xml_trace || !pAgent->xml_commands )
{
assert( pAgent );
assert( pAgent->xml_trace );
assert( pAgent->xml_commands );
return;
}
soarxml::XMLTrace* pTrace = static_cast< soarxml::XMLTrace* >( pAgent->xml_trace );
soarxml::XMLTrace* pCommands = static_cast< soarxml::XMLTrace* >( pAgent->xml_commands );
delete pTrace;
delete pCommands;
pAgent->xml_trace = 0;
pAgent->xml_commands = 0;
pAgent->xml_destination = 0;
}
soarxml::ElementXML* xml_end_command_mode ( agent pAgent)

Definition at line 333 of file xml.cpp.

References agent_struct::xml_destination, xml_get_xml(), and agent_struct::xml_trace.

{
if ( !pAgent )
{
assert( pAgent );
return 0;
}
soarxml::ElementXML* pReturn = xml_get_xml( pAgent );
pAgent->xml_destination = pAgent->xml_trace;
return pReturn;
}
void xml_end_tag ( agent pAgent,
char const *  pTag 
)
void xml_generate_error ( agent pAgent,
const char *  pMessage 
)

Definition at line 256 of file xml.cpp.

References xml_object().

Referenced by abort_with_fatal_error(), and do_one_top_level_phase().

{
xml_object( pAgent, stn::kTagError, stn::kTypeString, pMessage );
}
void xml_generate_message ( agent pAgent,
const char *  pMessage 
)

Definition at line 261 of file xml.cpp.

References xml_object().

Referenced by rl_perform_update(), smem_path_param::set_value(), epmem_path_param::set_value(), and wma_go().

{
xml_object( pAgent, stn::kTagMessage, stn::kTypeString, pMessage );
}
void xml_generate_verbose ( agent pAgent,
const char *  pMessage 
)
void xml_generate_warning ( agent pAgent,
const char *  pMessage 
)
soarxml::ElementXML* xml_get_xml ( agent pAgent)

Definition at line 303 of file xml.cpp.

References agent_struct::xml_destination.

Referenced by xml_end_command_mode().

{
if ( !pAgent || !pAgent->xml_destination )
{
assert( pAgent );
assert( pAgent->xml_destination );
return 0;
}
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
soarxml::ElementXML* pReturn = pXML->DetatchObject();
pXML->Reset();
return pReturn;
}
void xml_invoke_callback ( agent pAgent)

Definition at line 271 of file xml.cpp.

References callback_struct::data, callback_struct::eventid, callback_struct::function, NIL, agent_struct::soar_callbacks, agent_struct::xml_destination, and XML_GENERATION_CALLBACK.

Referenced by do_one_top_level_phase().

{
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
if ( pXML->IsEmpty() )
{
return;
}
soarxml::ElementXML* pResult = pXML->DetatchObject();
pXML->Reset();
#ifdef _DEBUG
char* pStr = pResult->GenerateXMLString( true ) ;
pResult->DeleteString( pStr ) ;
#endif // _DEBUG
// We need to call the handler explicitly here instead of using soar_invoke_callbacks
// because we need to create a new ElementXML object for each handler that gets called.
for ( cons* c = pAgent->soar_callbacks[XML_GENERATION_CALLBACK]; c != NIL; c = c->rest )
{
soarxml::ElementXML* pCallbackData = new soarxml::ElementXML( pResult->GetXMLHandle() );
pCallbackData->AddRefOnHandle();
soar_callback* cb = static_cast< soar_callback* >( c->first );
// handler responsible for deleting pCallbackData
cb->function( pAgent, cb->eventid, cb->data, static_cast< soar_call_data >( pCallbackData ) );
}
delete pResult;
}
void xml_move_current_to_child ( agent pAgent,
int  index 
)

Definition at line 120 of file xml.cpp.

References agent_struct::xml_destination.

{
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->MoveCurrentToChild( index );
}
void xml_move_current_to_last_child ( agent pAgent)

Definition at line 126 of file xml.cpp.

References agent_struct::xml_destination.

Referenced by xml_aux().

{
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->MoveCurrentToLastChild();
}
void xml_move_current_to_parent ( agent pAgent)

Definition at line 114 of file xml.cpp.

References agent_struct::xml_destination.

Referenced by xml_aux().

{
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->MoveCurrentToParent();
}
void xml_object ( agent pAgent,
char const *  pTag 
)

Definition at line 182 of file xml.cpp.

References agent_struct::xml_destination.

Referenced by create_instantiation(), print_wme(), print_wme_without_timetag(), retract_instantiation(), write_rhs_function_code(), xml_aux(), xml_generate_error(), xml_generate_message(), xml_generate_verbose(), xml_generate_warning(), xml_instantiation_with_wmes(), and xml_whole_token().

{
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->BeginTag( pTag ) ;
pXML->EndTag( pTag ) ;
}
void xml_object ( agent pAgent,
char const *  pTag,
char const *  pAttribute,
char const *  pValue 
)

Definition at line 190 of file xml.cpp.

References agent_struct::xml_destination.

{
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->BeginTag( pTag ) ;
pXML->AddAttribute( pAttribute, pValue ) ;
pXML->EndTag( pTag ) ;
}
void xml_object ( agent pAgent,
char const *  pTag,
char const *  pAttribute,
uint64_t  value 
)

Definition at line 199 of file xml.cpp.

References xml_att_val(), and agent_struct::xml_destination.

{
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->BeginTag( pTag ) ;
xml_att_val( pAgent, pAttribute, value );
pXML->EndTag( pTag ) ;
}
void xml_object ( agent pAgent,
char const *  pTag,
char const *  pAttribute,
int64_t  value 
)

Definition at line 208 of file xml.cpp.

References xml_att_val(), and agent_struct::xml_destination.

{
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->BeginTag( pTag ) ;
xml_att_val( pAgent, pAttribute, value );
pXML->EndTag( pTag ) ;
}
void xml_object ( agent pAgent,
char const *  pTag,
char const *  pAttribute,
double  value 
)

Definition at line 217 of file xml.cpp.

References xml_att_val(), and agent_struct::xml_destination.

{
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->BeginTag( pTag ) ;
xml_att_val( pAgent, pAttribute, value );
pXML->EndTag( pTag ) ;
}
void xml_object ( agent pAgent,
wme pWME,
bool  printTimetag 
)

Definition at line 226 of file xml.cpp.

References wme_struct::acceptable, wme_struct::attr, wme_struct::id, symbol_to_typeString(), wme_struct::timetag, wme_struct::value, xml_att_val(), and agent_struct::xml_destination.

{
// <wme tag="123" id="s1" attr="foo" attrtype="string" val="123" valtype="string"></wme>
soarxml::XMLTrace* pXML = static_cast< soarxml::XMLTrace* >( pAgent->xml_destination );
pXML->BeginTag( stn::kTagWME ) ;
// BADBAD: These calls are redundantly converting pXML again. Possibly optimize.
if ( printTimetag )
{
xml_att_val( pAgent, kWME_TimeTag, pWME->timetag );
}
xml_att_val( pAgent, kWME_Id, pWME->id );
xml_att_val( pAgent, kWME_Attribute, pWME->attr );
xml_att_val( pAgent, kWME_Value, pWME->value );
xml_att_val( pAgent, kWME_ValueType, symbol_to_typeString( pAgent, pWME->value ) );
if ( pWME->acceptable )
{
xml_att_val( pAgent, kWMEPreference, "+" );
}
pXML->EndTag( stn::kTagWME ) ;
}
void xml_reset ( agent pAgent)

Definition at line 61 of file xml.cpp.

References agent_struct::xml_commands, and agent_struct::xml_trace.

Referenced by reinitialize_soar().

{
if ( !pAgent || !pAgent->xml_trace || !pAgent->xml_commands )
{
assert( pAgent );
assert( pAgent->xml_trace );
assert( pAgent->xml_commands );
return;
}
soarxml::XMLTrace* pTrace = static_cast< soarxml::XMLTrace* >( pAgent->xml_trace );
soarxml::XMLTrace* pCommands = static_cast< soarxml::XMLTrace* >( pAgent->xml_commands );
pTrace->Reset();
pCommands->Reset();
}