Protocol Implementation > Implement the main function > The CProtocolExtension Class |
CProtocolExtension is a singleton. It is instantiated the first time a reference is made to CProtocolExtension::Instance() and can be accessed at any point in the protocol implementation. CProtocolExtension manages protocol internal issues such as event handling, and also handles registration in the LoadRunner execution environment. It also provides protocol services such as logging, data point generation, and so on.
See CProtocolExtension Class Reference
One of the important services CProtocolExtension provides is the ability to save strings to LoadRunner parameters. The advantage of using LoadRunner parameters is that the user does not have to manage memory buffers allocated to string values (see SaveStringToParameter below).
The following are other services provided by CProtocolExtension:
Register. Register the protocol in the LoadRunner execution environment.
RegisterEventHandler. Register an event handler to respond to LoadRunner execution environment events.
SetVirtualUserData. Keep a pointer to the virtual user data in Thread Local Storage.
GetVirtualUserData. Get the virtual user data from Thread Local Storage.
LogErrorMessage. Send a formatted error message to the execution log and update the step status.
LogWarningMessage. Send a formatted warning message to the execution log and update the step status.
LogNotifyMessage. Send a formatted notification to the execution log.
LogTextMessage. Send a text message to the log. Can be used for printing network buffers.
CreateDataPoint. Create a data point.
EvaluateString. Return the string argument after evaluating embedded parameters.
SaveStringToParameter. Save a string value into a parameter.
GetConfigurationAttribute. Returns a configuration setting value.
Register/UnregisterTimer. Creates and registers a timer for invoking a callback asynchronically.
GetNumberOfMillisecondsFromStartOfRun. Get number of milliseconds from start of run.
Usage examples of CProtocolExtension |
Copy Code
|
---|---|
CMyVirtualUserData* myData = (CMyVirtualUserData*)CProtocolExtension::Instance()->GetVirtualUserData(); CProtocolExtension::Instance()->CreateDataPoint("CONNECT", 1.0); CProtocolExtension::Instance()-> LogErrorMessage(ECHO_INTERNAL_ERROR, "Failed to create socket"); CProtocolExtension::Instance()->SetVirtualUserData(myData); |