📄 nnadkstubplugin.cpp
字号:
iret = true;
}
else
{
NNADK_THROW_CRITICAL ("No file to read");
iret = false;
}
}
else
{
NNADK_THROW_CRITICAL ("No file to read");
iret = false;
}
}
if (iret)
{
iret = false; // set so will not come back unless get data
while ((ch != EOF) && (pInfile->get(ch)))
{
if ((ch == EOF) || (ch == '\n'))
{
if (pos == 0)
{
if (ch == EOF)
{
StandardErrorStream
<< "data all done"
<< StreamEndLine;
iret = false;
}
else
{
iret = true;
}
dataBuffer.setData ( (void*) buf.c_str(), buf.length());
if (VerboseOn)
{
StandardErrorStream << dataBuffer.getData() << StreamEndLine;
StandardErrorStream << buf.c_str() << StreamEndLine;
}
break;
} // empty newline
buf += ch;
pos = 0;
} // newline or EOF
else
{
buf += ch;
pos++;
}
} // end while
} // file object found
return iret;
}
bool readTree (NNSY_NDO_NAMESPACE NNDOObject& ndo,
void* userdata)
{
bool iret = false;
OFStream* pOutfile = NULL;
STL_STRING Name;
STL_STRING Value;
if (!userdata)
{
StandardErrorStream << "User Data not set" << StreamEndLine;
NNADK_THROW_CRITICAL ("User Data not set");
}
else
{
FileObjectsStruct* pFileObjects = (FileObjectsStruct*) (userdata);
if (pFileObjects)
{
if (pFileObjects->pOutfile)
{
pOutfile = pFileObjects->pOutfile;
iret = true;
}
else
{
NNADK_THROW_CRITICAL ("No file to write");
iret = false;
}
}
else
{
NNADK_THROW_CRITICAL ("No file to write");
iret = false;
}
}
if (iret)
{
const NNDODataNode* pDataTree = ndo.getDataTree();
if (pDataTree)
{
CONST_DATA_NODE_RCLIST_ITER iter1 = pDataTree->getChildListBegin();
for ( ;
( iter1 != pDataTree->getChildListEnd() );
++iter1 )
{
const NNDODataNode* pDataNode = *iter1;
Name = pDataNode->getName();
pDataNode->getData(Value);
*pOutfile << Name << "," << Value << StreamEndLine;
}
*pOutfile << StreamEndLine;
}
}
return iret;
}
bool readBuffer (NNSY_ADK_NAMESPACE NNDataBuffer& dataBuffer,
void* userdata)
{
bool iret = true;
OFStream* pOutfile = NULL;
STL_STRING Name;
STL_STRING Value;
if (!userdata)
{
StandardErrorStream << "User Data not set" << StreamEndLine;
NNADK_THROW_CRITICAL ("User Data not set");
}
else
{
FileObjectsStruct* pFileObjects = (FileObjectsStruct*) (userdata);
if (pFileObjects)
{
if (pFileObjects->pOutfile)
{
pOutfile = pFileObjects->pOutfile;
iret = true;
}
else
{
NNADK_THROW_CRITICAL ("No file to write");
iret = false;
}
}
else
{
NNADK_THROW_CRITICAL ("No file to write");
iret = false;
}
}
if (iret)
{
pOutfile->write ((char*) dataBuffer.getData(),
dataBuffer.getLength());
*pOutfile << StreamEndLine;
}
return iret;
}
NNADKSTUBPLUGIN_API bool acquireSchema(const STL_STRING& schemaName,
NNSY_NDO_NAMESPACE NNDOObject& tree,
void* userdata, int instance)
{
// TO DO Define all formats that the Formatter will need to know about
// format may conatin a name to a certain format, otherwise it is NULL
// TIP!! You may find it useful to define a varable in your userdata struct
// that may contain the name of a certain Schema you might want when
// you are putting data to the queue via the PutData function
// make an instance of the Schema Class
bool iret = true;
iret = createTree (true, tree, userdata);
return iret;
}
NNADKSTUBPLUGIN_API bool acquireData(NNSY_NDO_NAMESPACE NNDOObject& dataObject,
void* userdata,
NNSY_ADK_NAMESPACE NNADKOutOfBand& oobInformation)
{
// TO DO .... Fill the given tree with the proper data
// NOTE!! you can reassign this tree with another tree
// the would contain another structure via the = operator
// RETURN VALUES
// return false when you are done putting data to the Queue
// return true to have another pass.
bool iret = true;
iret = createTree (false, dataObject, userdata);
return iret;
}
NNADKSTUBPLUGIN_API bool deliverData(NNSY_NDO_NAMESPACE NNDOObject& dataObject,
void *userdata,
NNSY_ADK_NAMESPACE NNADKOutOfBand& oobInformation)
{
// TO DO .... The dataObject member contains a tree with data
// that was pulled off the Queue (or some other source).
// Use this data to put to your source
// NOTE!! this class will loop until you return false
// or until some extern source causes a stop
// RETURN VALUES
// return true if you want to loop again
// return false when you want to exit the loop
bool iret = true;
iret = readTree (dataObject, userdata);
return iret;
}
NNADKSTUBPLUGIN_API bool processData(NNSY_NDO_NAMESPACE NNDOObject& in,
NNSY_NDO_NAMESPACE NNDOObject& out,
void *userdata,
NNSY_ADK_NAMESPACE NNADKOutOfBand &OB)
{
// TO DO: anything needed with the in data and provide what data
// should go out this function is a mix of Acquire and Deliver.
// NOTE!! this class will loop until you return false
// or until some extern source causes a stop
// RETURN VALUES
// return true if you want to loop again
// return false when you want to exit the loop
bool iret = true;
iret = ( readTree (in, userdata) && createTree (false, out, userdata) );
return iret;
}
NNADKSTUBPLUGIN_API bool acknowledgePutData(NNSY_NDO_NAMESPACE NNDOObject& dataObject,
NNSY_ADK_NAMESPACE NNADKOutOfBand &OB,
void* userdata,
e_Acknowledge ackStatus)
{
if (VerboseOn)
{
STL_STRING Name;
STL_STRING Value;
const NNDODataNode* pDataTree = dataObject.getDataTree();
if (pDataTree)
{
CONST_DATA_NODE_RCLIST_ITER iter1 = pDataTree->getChildListBegin();
for ( ;
( iter1 != pDataTree->getChildListEnd() );
++iter1 )
{
const NNDODataNode* pDataNode = *iter1;
Name = pDataNode->getName();
pDataNode->getData(Value);
StandardErrorStream << "NDO sent to Adapter" << StreamEndLine;
StandardErrorStream << Name.c_str();
StandardErrorStream << "\t\t"
<< Value.c_str()
<< StreamEndLine;
}
}
}
LogDebug(g_log, LogObject::Info, "Entered plugIn acknowledgePutData");
bool success = true;
return success;
}
NNADKSTUBPLUGIN_API bool acquireBuffer(
NNSY_ADK_NAMESPACE NNDataBuffer &dataBuffer,
void *userdata, NNSY_ADK_NAMESPACE NNADKOutOfBand &OB)
{
// TO DO .... Fill the given buffer with the proper data
// NOTE!! you can reassign this tree with another tree
// the would contain another structure via the = operator
// RETURN VALUES
// return false when you are done putting data to the Queue
// return true to have another pass.
bool iret = true;
iret = createBuffer (dataBuffer, userdata);
return iret;
}
NNADKSTUBPLUGIN_API bool deliverBuffer(
NNSY_ADK_NAMESPACE NNDataBuffer& dataBuffer,
void *userdata,
NNSY_ADK_NAMESPACE NNADKOutOfBand& oobInformation)
{
// TO DO .... The dataBuffer member contains a buffer with data
// that was pulled off the Queue (or some other source).
// Use this data to put to your source
// NOTE!! this class will loop until you return false
// or until some extern source causes a stop
// RETURN VALUES
// return true if you want to loop again
// return false when you want to exit the loop
bool iret = true;
iret = readBuffer (dataBuffer, userdata);
return iret;
}
NNADKSTUBPLUGIN_API bool processBuffer(
NNSY_ADK_NAMESPACE NNDataBuffer& in,
NNSY_ADK_NAMESPACE NNDataBuffer& out,
void* userdata,
NNSY_ADK_NAMESPACE NNADKOutOfBand& oobInformation)
{
// TO DO .... do anything needed with the in data and provide what
// data should go out
// this function is a mix of Acquire and Deliver.
// NOTE!! this class will loop until you return false
// or until some extern source causes a stop
// RETURN VALUES
// return true if you want to loop again
// return false when you want to exit the loop
bool iret = true;
iret = ( readBuffer (in, userdata) && createBuffer (out, userdata) );
return iret;
}
NNADKSTUBPLUGIN_API bool acknowledgePutBuffer(NNSY_ADK_NAMESPACE NNDataBuffer& dataBuffer,
NNSY_ADK_NAMESPACE NNADKOutOfBand &OB,
void* userdata,
e_Acknowledge ackStatus)
{
LogDebug(g_log, LogObject::Info, "Entered plugIn acknowledgePutData");
if (VerboseOn)
{
StandardErrorStream << "Buffer sent to Adapter" << StreamEndLine;
StandardErrorStream << dataBuffer << StreamEndLine;
}
bool success = true;
return success;
}
NNADKSTUBPLUGIN_API bool handleQuietState(void* userdata)
{
if (VerboseOn)
{
StandardErrorStream << "In handle quiet state" << StreamEndLine;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -