Interest in Another c++ Stack?
Andy Dent <[email protected]> Fri, 11 Jul 2003 05:27:59 +0800
| Newsgroups | gmane.network.beep.beepcore.c.general |
|---|---|
| Message-ID | <a05210600bb3384cb1087@[203.34.30.7]> |
BEEPX is a sort of BEEP descendant, after the first frame it becomes pure
XML even for the framing. That's because it was designed for use with Flash.
However, the parsing bit which assumes XML framing is well-isolated and
could be easily modified.
The stack uses only plain C++ that runs on PocketPC (Embedded VC3), Windows
and OS/X.
I'm considering if it would help me in some final debugging to have it open
sourced or not because I'll have to convince my client that it wouldn't be
a time-wasting distraction.
The only 3rd party libraries that BEEPX uses are some of the utilities from
my OOFILE suite and expatpp - my OO layer on top of expat. Both are
released under the Mozilla license, as would be BEEPX.
How much interest is there out there?
It runs fairly well and I have Python tests (not really an implementation
of the stack as they don't retain messages) that help exercise the echo
profile etc. There are also quite a few unit tests (the entire suite is 120
tests at present but many of those are app-specific) using cppunit on VC
and CodeWarrior for Mac, no PocketPC tests at present.
Unlike most of the projects I've seen, it is based around commercial
compilers, being developed on CodeWarrior Pro 8.3 for Mac (also builds with
ProjectBuilder), Visual C++ and Embedded VC. It doesn't require a deep
understanding of Unix development idioms to build.
Remember, I'm making no promises but if I have a few people willing to be
enthusiastic about using and testing this stuff then I will hopefully be
able to convince my client he's better off with it open sourced.
I'll have to contribute my time to packaging it and stripping some
proprietary stuff from the documentation, so I'm not making this offer
lightly - apart from being overloaded with work I'm still coping with the
effects of us moving to a new house and the "fixup period".
As an example, the complete Echo Profile is included below.
Expatpp <http://www.oofile.com.au/xml/expatpp.html> makes it very easy to
write call-back driven C++ parsers for expat and particularly to invoke
"subroutine" parsers so you can write very small sub-parsers that are
invoked when appropriate.
#include "BEEPXEchoProfile.h"
#include "BEEPXErrorReporter.h"
#include <assert.h>
#ifdef OOF_MEM_DEBUG_LAST_INCLUDE
#include OOF_MEM_DEBUG_LAST_INCLUDE
#endif
using namespace BEEPX;
// -------------------------------------------------------
// E c h o S e s s i o n F a c t o r y
// -------------------------------------------------------
EchoProfile EchoSessionFactory::sEchoProfile;
/**
\return Session owned by caller.
*/
Session*
EchoSessionFactory::makeSession(Transport* adoptedTransport, ErrorReporter*
inReporter, SessionOwner* inOwner)
{
Session* orphanedSession = new Session(adoptedTransport,
inReporter, inOwner);
orphanedSession->registerProfile(&sEchoProfile);
return orphanedSession;
}
// -------------------------------------------------------
// E c h o P r o f i l e
// -------------------------------------------------------
oofString EchoProfile::sEchoURI = "http://ibva.com/BEEPX/Echo";
bool
EchoProfile::matchesURI(const char* matchingURI) const
{
assert(matchingURI);
return (sEchoURI==matchingURI);
}
const oofString&
EchoProfile::uri() const
{
return sEchoURI;
}
ChannelParser*
EchoProfile::makeParser(const char* matchingURI)
{
if (!matchingURI || matchesURI(matchingURI))
return new EchoParser;
else
return 0;
}
// -------------------------------------------------------
// E c h o P a r s e r
// -------------------------------------------------------
/**
Just send back the raw payload as it was for any incoming MSG.
If we responded regardless of type, would have an echo storm!
*/
void
EchoParser::parseFrame(Frame* inFrame)
{
assert(inFrame);
assert(mErrorReporter);
mCurrentFrame = inFrame;
mErrorReporter->resetError();
assert (inFrame->type()==Frame::eMSG);
const oofString raw = RawPayload(inFrame);
Reply(raw);
StCriticalSection protectMember(this);
mLastFrameParsed = *inFrame; // hang onto for unit tests
}
void
EchoParser::parseReplyFrame(Frame* inMessageSent, Frame* inReply)
{
StCriticalSection protectMember(this);
mLastReplyFrameParsed = *inReply; // hang onto for unit tests
}
========================
The above Echo parser intercepts the entire frame. Normally you would write
something lower level which responded to the XML, like this.
void TriggerRequestParser::startElement(const XML_Char *name, const
XML_Char **atts)
{
if (IgnoringContent())
return;
if(strcmp(name,"TriggerRequest")==0) {
mState = eBuildingRequest;
ParseRequestAtts(atts);
}
else if(strcmp(name,"Peak")==0) {
StartPeak(atts);
}
else if(strcmp(name,"Average")==0) {
StartAverage(atts);
}
else if(strcmp(name,"Sum")==0) {
StartSum(atts);
}
else if(strcmp(name,"CompareRange")==0) {
StartCompareRange(atts);
}
else if(strcmp(name,"Frequency")==0) {
StartFrequency(atts);
}
else {
handleUnknown(name, atts);
}
}
--
Andy Dent BSc MACS AACM http://www.oofile.com.au/
OOFILE - Database, Reports, Graphs, GUI for c++ on Mac, Unix & Windows
PP2MFC - PowerPlant->MFC portability
-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1