Teledyne LeCroy USB Analyzer Automation Manual User Manual

Page 94

Advertising
background image

Teledyne LeCroy Automation API Reference Manual for USBTracer, USB Advisor, and Voyager USB Protocol
Suite

94

C++:

class CVSEngineSink : public IDispEventImpl<IDC_SRCOBJ_VSE, CVSEngineSink >
{
public:

. . .


BEGIN_SINK_MAP(CVSEngineSink)

// Make sure the Event Handlers have __stdcall calling convention.

SINK_ENTRY( IDC_SRCOBJ_VSE, 1, OnVScriptReportUpdated )

SINK_ENTRY( IDC_SRCOBJ_VSE, 2, OnVScriptFinished )
SINK_ENTRY( IDC_SRCOBJ_VSE, 3, OnNotifyClient )

END_SINK_MAP()

HRESULT __stdcall OnVScriptReportUpdated ( BSTR newLine, int TAG );
HRESULT __stdcall OnVScriptFinished( BSTR script_name, VS_RESULT result, int TAG );
HRESULT __stdcall OnNotifyClient ( int eventId, VARIANT eventBody, int TAG );

HRESULT Advise(IUnknown* pUnk)
{
AtlGetObjectSourceInterface(pUnk, &m_libid, &m_iid, &m_wMajorVerNum, &m_wMinorVerNum);
return DispEventAdvise(pUnk, &m_iid);
}

HRESULT Unadvise(IUnknown* pUnk)
{
AtlGetObjectSourceInterface(pUnk, &m_libid, &m_iid, &m_wMajorVerNum, &m_wMinorVerNum);
return DispEventUnadvise(pUnk, &m_iid);
}
...

};

Then, after you establish the connection with the server, you need to advise your implementation of the
event interface:


IVScriptEngine vscript_engine = NULL;

try
{ vscript_engine = vscript ->GetVScriptEngine( "Test_1" ); }
catch ( _com_error& er )
{ SetStatusError( er ); }


if( vscript_engine == NULL )
{
vscript = NULL;
return E_FAIL;
}

CVSEngineSink vse_sink;
HRESULT hr = vse_sink . Advise( vscript_engine ); // “Subscribe” for receiving events
...
VS_RESULT res = SCRIPT_NOT_FOUND;
try
{
res = (VS_RESULT)vscript_engine ->RunVScript();
}
catch ( _com_error& er)
{ SetStatusError( er ); }

// Tear connection with the test case.
vse_sink. Unadvise( vscript_engine );
...

Advertising