MAK Data Logger API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sampleFilter Example

This example shows how to make a simple packet filter plugin.


The main application:

/*******************************************************************************
** Copyright (c) 1992-2010 VT MAK
** All rights reserved.
*******************************************************************************/
#define DT_DLL_SAMPLE __declspec ( dllexport )
#define DT_DLL_SAMPLE_C extern "C" __declspec ( dllexport )
#ifdef _WIN32
#ifdef LGRSAMPLE_EXPORTS
#define DT_DLL_SAMPLE __declspec ( dllexport )
#else
#define DT_DLL_SAMPLE __declspec ( dllimport )
#endif
#else
#define DT_DLL_SAMPLE
#endif
#include <lgrCore/logger.h>
#define DT_LGR_PLUGIN_EXPORT_MACRO DT_DLL_SAMPLE
using namespace MAKLogger;
class DT_DLL_SAMPLE SampleFilter : public DtLgrPacketFilter
{
public:
SampleFilter() : DtLgrPacketFilter(),
myFilterAllPacketsFlag(false)
{
}
virtual ~SampleFilter()
{
}
static DtLgrPacketFilter* staticCreator()
{
return new SampleFilter();
}
virtual bool filterPacket(DtPacket* packet)
{
DtLgrPrinter::info("Filtering Packet via Plugin");
return myFilterAllPacketsFlag;
}
virtual const DtString& type() const { return theFilterType;}
virtual void activate(const DtMessageIOInfo* info)
{
DtLgrPrinter::info("Activated Plugin");
}
virtual void deactivate()
{
DtLgrPrinter::info("Deactivated Plugin");
}
virtual char* serialize(int& size) const
{
char* buffer = new char[1];
size = 1;
unsigned char* flagPtr = (unsigned char*) buffer;
*flagPtr = myFilterAllPacketsFlag;
return buffer;
}
virtual int setFromSerialization(const char* data,int size)
{
if(size != 1)
{
DtTHROW_NEW(DtInvalidInput,
"SampleFilter: Size does not match expected size");
}
unsigned char* flagPtr = (unsigned char*) data;
myFilterAllPacketsFlag = *flagPtr;
return sizeof(unsigned char);
}
protected:
bool myFilterAllPacketsFlag;
static DtString theFilterType;
};
DtString SampleFilter::theFilterType = "SampleFilter";
extern "C" {
void LoadPlugin()
{
}
{
}
{
}
{
// Create a filter object.
SampleFilter* aFilter = new SampleFilter();
// Register the Filter Type to allow the logger to know how to create them if necessary.
DtLgrPacketFilterFactory::registerFilterType(aFilter->type(),&SampleFilter::staticCreator);
// Create a sim interface to add a filter to process data.
DtLgrSimInterface* simInterface = DtLgrSimInterface::create(application.logger());
// Add a filter object to process data.
simInterface->addFilter(aFilter);
// Do not use the filter after it has been added.
aFilter = 0;
// Clean up the interface
delete simInterface;
}
}

Document ID: Generated on Wed Jun 5 18:45:18 EDT 2019 from SVN revision 198968
Copyright © 2019 VT MAK. All Rights Reserved (www.mak.com)