From f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 3 Apr 2007 03:49:53 +0000 Subject: Ok, no code is left in src, it's all in src/old. We'll gradually move code back into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier. --- src/plugger.h | 198 ---------------------------------------------------------- 1 file changed, 198 deletions(-) delete mode 100644 src/plugger.h (limited to 'src/plugger.h') diff --git a/src/plugger.h b/src/plugger.h deleted file mode 100644 index d92f194..0000000 --- a/src/plugger.h +++ /dev/null @@ -1,198 +0,0 @@ -#ifndef PLUGGER_H -#define PLUGGER_H - - -#include "hashtable.h" -#include "list" -#include "hashfunctionstring.h" -#include "hashfunctionint.h" -#include "dlfcn.h" -#include "exceptions.h" - -typedef struct PluginInfo -{ - const char *sID; - const char *sAuthor; - unsigned short nVersion; - unsigned short nRevision; - void *(*createPlugin)(); - void (*destroyPlugin)( void * ); -} PluginInfo; - -typedef struct PluginReg -{ - bool bBuiltin; - void *dlHandle; - PluginInfo *pInfo; -} PluginReg; - -#define PluginInterface( classname, baseclass, name, ver, rev ) \ -extern "C" { \ - baseclass *create ##classname() \ - { \ - return new classname(); \ - } \ - void destroy ##classname( baseclass *pCls ) \ - { \ - delete pCls; \ - } \ - PluginInfo classname = { \ - #classname, name, ver, rev, \ - create ##classname, destroy ##classname }; \ -} - -#define PluginInterface2( pluginname, classname, baseclass, name, ver, rev ) \ -extern "C" { \ - baseclass *create ##classname() \ - { \ - return new classname(); \ - } \ - void destroy ##classname( baseclass *pCls ) \ - { \ - delete pCls; \ - } \ - PluginInfo pluginname = { \ - #pluginname, name, ver, rev, \ - (void *(*)())(create ##classname), \ - (void (*)( void * ))(destroy ##classname) }; \ -} - -#define PluginInterface3( structname, pluginname, classname, baseclass, name, ver, rev ) \ -extern "C" { \ - baseclass *create ##classname() \ - { \ - return new classname(); \ - } \ - void destroy ##classname( baseclass *pCls ) \ - { \ - delete pCls; \ - } \ - PluginInfo structname = { \ - #pluginname, name, ver, rev, \ - (void *(*)())(create ##classname), \ - (void (*)( void * ))(destroy ##classname) }; \ -} - -template -class Plugger -{ -public: - -public: - Plugger() : - hPlugin( new HashFunctionString(), 11 ), - hObj( new HashFunctionInt(), 11 ) - { - } - - virtual ~Plugger() - { - void *pos = hObj.getFirstItemPos(); - while( (pos = hObj.getNextItemPos( pos )) ) - { - T *pPlug = (T *)hObj.getItemID( pos ); - PluginReg *pReg = (PluginReg *)hObj.getItemData( pos ); - pReg->pInfo->destroyPlugin( pPlug ); - } - - std::list::iterator i; - for( i = lPlugin.begin(); i != lPlugin.end(); i++ ) - { - if( (*i)->bBuiltin == false ) - { - dlclose( (*i)->dlHandle ); - } - delete (*i); - } - } - - void registerBuiltinPlugin( PluginInfo *pInfo ) - { - PluginReg *pReg = new PluginReg; - pReg->bBuiltin = true; - pReg->pInfo = pInfo; - lPlugin.insert( lPlugin.end(), pReg ); - hPlugin.insert( pInfo->sID, pReg ); - } - - void registerExternalPlugin( const char *sFName, const char *sPluginName ) - { - PluginReg *pReg = (PluginReg *)hPlugin[sPluginName]; - if( pReg != NULL ) - { - hPlugin.del( sPluginName ); - dlclose( pReg->dlHandle ); - delete pReg; - pReg = NULL; - } - - pReg = new PluginReg; - - pReg->bBuiltin = false; - pReg->dlHandle = dlopen( sFName, RTLD_NOW ); - if( pReg->dlHandle == NULL ) - { - throw PluginException( 1, "Error on %s: %s", sFName, dlerror() ); - } - pReg->pInfo = (PluginInfo *)dlsym( pReg->dlHandle, sPluginName ); - if( pReg->pInfo == NULL ) - { - throw PluginException( 2, "Error on %s: %s", sFName, dlerror() ); - } - hPlugin.insert( pReg->pInfo->sID, pReg ); - lPlugin.insert( lPlugin.end(), pReg ); - } - - T *instantiate( const char *lpName ) - { - PluginReg *pReg = (PluginReg *)hPlugin[lpName]; - if( pReg == NULL ) - return NULL; - - T *p = (T *)pReg->pInfo->createPlugin(); - hObj.insert( p, pReg ); - //printf("pReg: %08X, pPlug: %08X\n", pReg, p ); - - return p; - } - - bool hasPlugin( const char *lpName ) - { - if( hPlugin[lpName] == NULL ) - return false; - return true; - } - - void destroy( T *pPlug ) - { - PluginReg *pReg = (PluginReg *)hObj[pPlug]; - //printf("pReg: %08X, pPlug: %08X\n", pReg, pPlug ); - if( pReg == NULL ) - return; - - pReg->pInfo->destroyPlugin( pPlug ); - - hObj.del( pPlug ); - } - - void unloadAll() - { - std::list::iterator i; - for( i = lPlugin.begin(); i != lPlugin.end(); i++ ) - { - if( (*i)->bBuiltin == false ) - { - dlclose( (*i)->dlHandle ); - } - delete (*i); - } - hPlugin.clear(); - } - -private: - std::list lPlugin; - HashTable hPlugin; - HashTable hObj; -}; - -#endif -- cgit v1.2.3 From 3f26c19b0b7a9fa73c58189788972ea43b72f014 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 25 Jun 2007 21:15:55 +0000 Subject: I think the plugger and programchain are all up to date to work with the new libbu++. The program chain may undergo heavy changes still, or be removed entirely, but we need it for congo and squirrelmud, so here it is for a while longer. The TafWriter isn't much closer, you still only get the groups in the output. --- src/linkmessage.cpp | 43 ++++++++++ src/linkmessage.h | 42 ++++++++++ src/old/linkmessage.cpp | 44 ----------- src/old/linkmessage.h | 39 ---------- src/old/plugger.cpp | 1 - src/old/plugger.h | 198 ----------------------------------------------- src/old/programchain.cpp | 96 ----------------------- src/old/programchain.h | 95 ----------------------- src/old/programlink.cpp | 54 ------------- src/old/programlink.h | 99 ------------------------ src/plugger.cpp | 1 + src/plugger.h | 196 ++++++++++++++++++++++++++++++++++++++++++++++ src/programchain.cpp | 97 +++++++++++++++++++++++ src/programchain.h | 98 +++++++++++++++++++++++ src/programlink.cpp | 56 ++++++++++++++ src/programlink.h | 100 ++++++++++++++++++++++++ src/tafwriter.cpp | 25 +++++- src/tafwriter.h | 10 ++- 18 files changed, 665 insertions(+), 629 deletions(-) create mode 100644 src/linkmessage.cpp create mode 100644 src/linkmessage.h delete mode 100644 src/old/linkmessage.cpp delete mode 100644 src/old/linkmessage.h delete mode 100644 src/old/plugger.cpp delete mode 100644 src/old/plugger.h delete mode 100644 src/old/programchain.cpp delete mode 100644 src/old/programchain.h delete mode 100644 src/old/programlink.cpp delete mode 100644 src/old/programlink.h create mode 100644 src/plugger.cpp create mode 100644 src/plugger.h create mode 100644 src/programchain.cpp create mode 100644 src/programchain.h create mode 100644 src/programlink.cpp create mode 100644 src/programlink.h (limited to 'src/plugger.h') diff --git a/src/linkmessage.cpp b/src/linkmessage.cpp new file mode 100644 index 0000000..abe113c --- /dev/null +++ b/src/linkmessage.cpp @@ -0,0 +1,43 @@ +#include "bu/linkmessage.h" + +Bu::LinkMessage::LinkMessage( int nNewMsg ) +{ + nMsg = nNewMsg; +} + +Bu::LinkMessage::~LinkMessage() +{ +} + +/* +void LinkMessage::setBroadcast( bool bOn ) +{ + bBroadcast = bOn; +} + +bool LinkMessage::isBroadcast() +{ + return bBroadcast; +} + + +void LinkMessage::setFromID( int id ) +{ + nFromLinkID = id; +} + +int LinkMessage::getFromID() +{ + return nFromLinkID; +} + +void LinkMessage::setToID( int id ) +{ + nTargetLinkID = id; +} + +int LinkMessage::getToID() +{ + return nTargetLinkID; +} +*/ diff --git a/src/linkmessage.h b/src/linkmessage.h new file mode 100644 index 0000000..64b8bc2 --- /dev/null +++ b/src/linkmessage.h @@ -0,0 +1,42 @@ +/**\file linkmessage.h + */ + +#ifndef LINKMESSAGE_H +#define LINKMESSAGE_H + +namespace Bu +{ + /** + * A message to be broadcast accross ProgramLinks in a ProgramChain. Generally + * one would make a subclass of this in order to transmit more useful + * information, but sometimes it isn't necesarry. + *@author Mike Buland + */ + class LinkMessage + { + public: + /** + * Construct a blank LinkMessage. + */ + LinkMessage() {}; + + /** + * Deconstruct a LinkMessage. + */ + virtual ~LinkMessage(); + + /** + * Create a LinkMessage object with a specific message assosiated with it + * to start with. + *@param nNewMsg The message to use in the Message object. + */ + LinkMessage( int nNewMsg ); + + /** + * The message contained in the Message object. + */ + int nMsg; + }; +} + +#endif diff --git a/src/old/linkmessage.cpp b/src/old/linkmessage.cpp deleted file mode 100644 index cf3df42..0000000 --- a/src/old/linkmessage.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "linkmessage.h" -#include - -LinkMessage::LinkMessage( int nNewMsg ) -{ - nMsg = nNewMsg; -} - -LinkMessage::~LinkMessage() -{ -} - -/* -void LinkMessage::setBroadcast( bool bOn ) -{ - bBroadcast = bOn; -} - -bool LinkMessage::isBroadcast() -{ - return bBroadcast; -} - - -void LinkMessage::setFromID( int id ) -{ - nFromLinkID = id; -} - -int LinkMessage::getFromID() -{ - return nFromLinkID; -} - -void LinkMessage::setToID( int id ) -{ - nTargetLinkID = id; -} - -int LinkMessage::getToID() -{ - return nTargetLinkID; -} -*/ diff --git a/src/old/linkmessage.h b/src/old/linkmessage.h deleted file mode 100644 index 6cdfb2f..0000000 --- a/src/old/linkmessage.h +++ /dev/null @@ -1,39 +0,0 @@ -/**\file linkmessage.h - */ - -#ifndef LINKMESSAGE_H -#define LINKMESSAGE_H - -/** - * A message to be broadcast accross ProgramLinks in a ProgramChain. Generally - * one would make a subclass of this in order to transmit more useful - * information, but sometimes it isn't necesarry. - *@author Mike Buland - */ -class LinkMessage -{ -public: - /** - * Construct a blank LinkMessage. - */ - LinkMessage() {}; - - /** - * Deconstruct a LinkMessage. - */ - virtual ~LinkMessage(); - - /** - * Create a LinkMessage object with a specific message assosiated with it - * to start with. - *@param nNewMsg The message to use in the Message object. - */ - LinkMessage( int nNewMsg ); - - /** - * The message contained in the Message object. - */ - int nMsg; -}; - -#endif diff --git a/src/old/plugger.cpp b/src/old/plugger.cpp deleted file mode 100644 index f3bfa67..0000000 --- a/src/old/plugger.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "plugger.h" diff --git a/src/old/plugger.h b/src/old/plugger.h deleted file mode 100644 index d92f194..0000000 --- a/src/old/plugger.h +++ /dev/null @@ -1,198 +0,0 @@ -#ifndef PLUGGER_H -#define PLUGGER_H - - -#include "hashtable.h" -#include "list" -#include "hashfunctionstring.h" -#include "hashfunctionint.h" -#include "dlfcn.h" -#include "exceptions.h" - -typedef struct PluginInfo -{ - const char *sID; - const char *sAuthor; - unsigned short nVersion; - unsigned short nRevision; - void *(*createPlugin)(); - void (*destroyPlugin)( void * ); -} PluginInfo; - -typedef struct PluginReg -{ - bool bBuiltin; - void *dlHandle; - PluginInfo *pInfo; -} PluginReg; - -#define PluginInterface( classname, baseclass, name, ver, rev ) \ -extern "C" { \ - baseclass *create ##classname() \ - { \ - return new classname(); \ - } \ - void destroy ##classname( baseclass *pCls ) \ - { \ - delete pCls; \ - } \ - PluginInfo classname = { \ - #classname, name, ver, rev, \ - create ##classname, destroy ##classname }; \ -} - -#define PluginInterface2( pluginname, classname, baseclass, name, ver, rev ) \ -extern "C" { \ - baseclass *create ##classname() \ - { \ - return new classname(); \ - } \ - void destroy ##classname( baseclass *pCls ) \ - { \ - delete pCls; \ - } \ - PluginInfo pluginname = { \ - #pluginname, name, ver, rev, \ - (void *(*)())(create ##classname), \ - (void (*)( void * ))(destroy ##classname) }; \ -} - -#define PluginInterface3( structname, pluginname, classname, baseclass, name, ver, rev ) \ -extern "C" { \ - baseclass *create ##classname() \ - { \ - return new classname(); \ - } \ - void destroy ##classname( baseclass *pCls ) \ - { \ - delete pCls; \ - } \ - PluginInfo structname = { \ - #pluginname, name, ver, rev, \ - (void *(*)())(create ##classname), \ - (void (*)( void * ))(destroy ##classname) }; \ -} - -template -class Plugger -{ -public: - -public: - Plugger() : - hPlugin( new HashFunctionString(), 11 ), - hObj( new HashFunctionInt(), 11 ) - { - } - - virtual ~Plugger() - { - void *pos = hObj.getFirstItemPos(); - while( (pos = hObj.getNextItemPos( pos )) ) - { - T *pPlug = (T *)hObj.getItemID( pos ); - PluginReg *pReg = (PluginReg *)hObj.getItemData( pos ); - pReg->pInfo->destroyPlugin( pPlug ); - } - - std::list::iterator i; - for( i = lPlugin.begin(); i != lPlugin.end(); i++ ) - { - if( (*i)->bBuiltin == false ) - { - dlclose( (*i)->dlHandle ); - } - delete (*i); - } - } - - void registerBuiltinPlugin( PluginInfo *pInfo ) - { - PluginReg *pReg = new PluginReg; - pReg->bBuiltin = true; - pReg->pInfo = pInfo; - lPlugin.insert( lPlugin.end(), pReg ); - hPlugin.insert( pInfo->sID, pReg ); - } - - void registerExternalPlugin( const char *sFName, const char *sPluginName ) - { - PluginReg *pReg = (PluginReg *)hPlugin[sPluginName]; - if( pReg != NULL ) - { - hPlugin.del( sPluginName ); - dlclose( pReg->dlHandle ); - delete pReg; - pReg = NULL; - } - - pReg = new PluginReg; - - pReg->bBuiltin = false; - pReg->dlHandle = dlopen( sFName, RTLD_NOW ); - if( pReg->dlHandle == NULL ) - { - throw PluginException( 1, "Error on %s: %s", sFName, dlerror() ); - } - pReg->pInfo = (PluginInfo *)dlsym( pReg->dlHandle, sPluginName ); - if( pReg->pInfo == NULL ) - { - throw PluginException( 2, "Error on %s: %s", sFName, dlerror() ); - } - hPlugin.insert( pReg->pInfo->sID, pReg ); - lPlugin.insert( lPlugin.end(), pReg ); - } - - T *instantiate( const char *lpName ) - { - PluginReg *pReg = (PluginReg *)hPlugin[lpName]; - if( pReg == NULL ) - return NULL; - - T *p = (T *)pReg->pInfo->createPlugin(); - hObj.insert( p, pReg ); - //printf("pReg: %08X, pPlug: %08X\n", pReg, p ); - - return p; - } - - bool hasPlugin( const char *lpName ) - { - if( hPlugin[lpName] == NULL ) - return false; - return true; - } - - void destroy( T *pPlug ) - { - PluginReg *pReg = (PluginReg *)hObj[pPlug]; - //printf("pReg: %08X, pPlug: %08X\n", pReg, pPlug ); - if( pReg == NULL ) - return; - - pReg->pInfo->destroyPlugin( pPlug ); - - hObj.del( pPlug ); - } - - void unloadAll() - { - std::list::iterator i; - for( i = lPlugin.begin(); i != lPlugin.end(); i++ ) - { - if( (*i)->bBuiltin == false ) - { - dlclose( (*i)->dlHandle ); - } - delete (*i); - } - hPlugin.clear(); - } - -private: - std::list lPlugin; - HashTable hPlugin; - HashTable hObj; -}; - -#endif diff --git a/src/old/programchain.cpp b/src/old/programchain.cpp deleted file mode 100644 index 6120d58..0000000 --- a/src/old/programchain.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include "programchain.h" - -ProgramChain::ProgramChain() : - xLog( MultiLog::getInstance() ) -{ - xLog.LineLog( MultiLog::LStatus, "Program Chain Initialized." ); -} - -ProgramChain::~ProgramChain() -{ -} - -bool ProgramChain::addLink( ProgramLink *pLink ) -{ - if( pLink->init() == false ) - { - emergencyShutdown(); - return false; - } - - lLink.append( pLink ); - - pLink->setChain( this ); - - return true; -} - -ProgramLink *ProgramChain::getLink( const char *lpName ) -{ - char a; - a = lpName[0]; - return NULL; -} - -ProgramLink *ProgramChain::getBaseLink() -{ - return NULL; -} - -bool ProgramChain::execChainOnce() -{ - int nLen = lLink.getSize(); - for( int j = 0; j < nLen; j++ ) - { - if( ((ProgramLink *)lLink[j])->timeSlice() == false ) - { - xLog.LineLog( MultiLog::LInfo, "Shutting down due to signal from link #%d", j ); - emergencyShutdown(); - return false; - } - } - - return true; -} - -bool ProgramChain::enterChainLoop() -{ - for(;;) - { - if( execChainOnce() == false ) - { - return false; - } - } - - return true; -} - -void ProgramChain::emergencyShutdown() -{ - int nLen = lLink.getSize(); - for( int j = 0; j < nLen; j++ ) - { - ((ProgramLink *)lLink[j])->deInit(); - delete (ProgramLink *)lLink[j]; - } - lLink.empty(); -} - -LinkMessage *ProgramChain::broadcastIRM( LinkMessage *pMsgOut, ProgramLink *pSender ) -{ - int nLen = lLink.getSize(); - for( int j = 0; j < nLen; j++ ) - { - LinkMessage *pMsg = ((ProgramLink *)lLink[j])->processIRM( pMsgOut ); - if( pMsg != NULL ) - { - delete pMsgOut; - return pMsg; - } - } - - delete pMsgOut; - return NULL; -} diff --git a/src/old/programchain.h b/src/old/programchain.h deleted file mode 100644 index 2bdfeee..0000000 --- a/src/old/programchain.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef PROGRAMCHAIN_H -#define PROGRAMCHAIN_H - -#include "linkedlist.h" -#include "multilog.h" -#include "programlink.h" - -/** - * The Program Chain links together program "chunks" to more easily facilitate - * a generalized program loop with modular extensions. - *@author Mike Buland - */ -class ProgramChain -{ -public: - /** - * Construct an empty chain. - */ - ProgramChain(); - - /** - * Destroy your chain. - */ - virtual ~ProgramChain(); - - /** - * Adds a link to the end of the chain. - *@param pLink A pointer to the link to add to the chain. - *@returns True if adding the link was successful, otherwise false - *@author Mike Buland - */ - bool addLink( ProgramLink *pLink ); - - /** - * Gets a link by name. - *@param lpName The name of the link you're looking for. Every link has a - * name, apparently. - *@returns A pointer to the specified ProgramLink, or NULL if none were - * found matching your criteria. - *@author Mike Buland - */ - class ProgramLink *getLink( const char *lpName ); - - /** - * Gets the very first link in the chain. - *@returns A pointer to the first link in the chain. - *@author Mike Buland - */ - class ProgramLink *getBaseLink(); - - /** - * Runs through the chain once. Useful if you want to have more control - * over the operation of the chain. - *@returns true if every link returned true. If at least one link returns - * false, then returns false. - *@author Mike Buland - */ - bool execChainOnce(); - - /** - * Enters the master chain loop, looping over the entire chain and - * executing every link's TimeSlice routine in order, over and over, until - * a link returns a false value. - *@returns False, always. It returns true unless a link returned false, - * but loops until a link does return false. - *@author Mike Buland - **/ - bool enterChainLoop(); - - /** - * Broadcasts an Immediate Response Message to all active links, save the - * sender. Whatever link first responds with a non-null response message - * will have it's messages sent back to the broadcasting link as the returns - * of this function call. Therefore it is very important that all message - * processing code is handled in a fairly timely fasion. - *@param pMsgOut The message to broadcast in hopes of a response. - *@param pSender The message that sent out the message and doesn't want to - * receive it's own message. This should always just be "this". - *@returns The message that was returned by the first link to return a - * non-null response. If all messages return null responses then this also - * returns null. Please note that whoever calls this will be responsible - * for deleting the message returned by it, if non-null. - */ - class LinkMessage *broadcastIRM( LinkMessage *pMsgOut, ProgramLink *pSender ); - -private: - /** - * Shuts down all operation no matter what point in the operation we were. - */ - void emergencyShutdown(); - MultiLog &xLog; /**< A reference to the log. */ - LinkedList lLink; /**< The linked list that contains all of the links. */ -}; - -#endif diff --git a/src/old/programlink.cpp b/src/old/programlink.cpp deleted file mode 100644 index 21c6fe4..0000000 --- a/src/old/programlink.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "programlink.h" -#include "programchain.h" - -ProgramLink::ProgramLink() -{ -} - -ProgramLink::~ProgramLink() -{ -} - -LinkMessage *ProgramLink::sendIRM( LinkMessage *pMsgOut ) -{ - return pChain->broadcastIRM( pMsgOut, this ); -} - -void ProgramLink::setChain( ProgramChain *pNewChain ) -{ - pChain = pNewChain; -} - -/* -void ProgramLink::postMessage( LinkMessage *pMsg, int nLvl ) -{ - if( nLvl == msgToChain ) - { - qMsgToChain.enqueue( pMsg ); - } - else if( nLvl == msgToLink ) - { - qMsgToLink.enqueue( pMsg ); - } - else - { - // ERROR! - } -} - -LinkMessage *ProgramLink::getMessage( int nLvl ) -{ - if( nLvl == msgToChain ) - { - return (LinkMessage *)qMsgToChain.dequeue(); - } - else if( nLvl == msgToLink ) - { - return (LinkMessage *)qMsgToLink.dequeue(); - } - else - { - // ERROR! - } -} -*/ diff --git a/src/old/programlink.h b/src/old/programlink.h deleted file mode 100644 index f93edcc..0000000 --- a/src/old/programlink.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef PROGRAMLINK_H -#define PROGRAMLINK_H - -class ProgramLink; -#include "queue.h" -#include "linkmessage.h" -#include "programchain.h" - -/** - * Program Link is the base class for any object that will be a piece of the - * main program chain loop. - *@author Mike Buland - */ -class ProgramLink -{ -friend class ProgramChain; -public: - /** - * Construct a program link. - */ - ProgramLink(); - - /** - * Deconstruct. - */ - virtual ~ProgramLink(); - - /** - * Initialization code required for a link that wasn't performed in the - * constructor. - *@returns true if initialization was successful. A false value will halt - * the chain. - */ - virtual bool init()=0; - - /** - * DeInitialization code that should happen, but doesn't belong in the - * destructor. - *@returns true means everything worked, false means failure, but is - * meaningless. - */ - virtual bool deInit()=0; - - /** - * Executed once per link per chain pass. Contains the guts of the program. - *@returns true if everything went well. A false value will halt the chain. - */ - virtual bool timeSlice()=0; - - /** - * This must be handled in order to process Instant Response Messages. - * This function should return null on all messages that it doesn't - * understand how to handle, and construct new messages to return to sender - * in the cases where it does understand. - *@param pMsgIn The message that must be processed. - *@returns Either a new message in cases where a response is required, - * or null if nothing needs to be done by this link. - */ - virtual LinkMessage *processIRM( LinkMessage *pMsgIn ) = 0; - - /** - * Broadcast a LinkMessage to all other links in the system. Each other - * link will get a call of their processIRM function. If the message gets - * a response then you will regain control immediately, otherwise the system - * will give all other Links a chance to respond before returning NULL. - *@param pMsgOut The message to broadcast. - *@returns The message response, or NULL if no Link understood your message. - */ - LinkMessage *sendIRM( LinkMessage *pMsgOut ); - -private: - /** - * Set which chain we're assosiated with. This is how IRM messages make - * it out to the rest of the world. - *@param pNewChain A pointer to the containing program chain. - */ - void setChain( class ProgramChain *pNewChain ); - - /** - * The pointer to the containing chain. - */ - class ProgramChain *pChain; -/* - void postMessage( LinkMessage *pMsg, int nLvl ); - LinkMessage *getMessage( int nLvl ); - - enum - { - msgToChain, - msgToLink - }; - -private: - Queue qMsgToChain; - Queue qMsgToLink; -*/ -}; - -#endif diff --git a/src/plugger.cpp b/src/plugger.cpp new file mode 100644 index 0000000..f3bfa67 --- /dev/null +++ b/src/plugger.cpp @@ -0,0 +1 @@ +#include "plugger.h" diff --git a/src/plugger.h b/src/plugger.h new file mode 100644 index 0000000..98d4ecc --- /dev/null +++ b/src/plugger.h @@ -0,0 +1,196 @@ +#ifndef PLUGGER_H +#define PLUGGER_H + + +#include "bu/hash.h" +#include "bu/list.h" +#include +#include "bu/exceptions.h" +#include "bu/fstring.h" + +namespace Bu +{ + typedef struct PluginInfo + { + const char *sID; + const char *sAuthor; + unsigned short nVersion; + unsigned short nRevision; + void *(*createPlugin)(); + void (*destroyPlugin)( void * ); + } PluginInfo; + + typedef struct PluginReg + { + bool bBuiltin; + void *dlHandle; + PluginInfo *pInfo; + } PluginReg; + +#define PluginInterface( classname, baseclass, name, ver, rev ) \ + extern "C" { \ + baseclass *create ##classname() \ + { \ + return new classname(); \ + } \ + void destroy ##classname( baseclass *pCls ) \ + { \ + delete pCls; \ + } \ + PluginInfo classname = { \ + #classname, name, ver, rev, \ + create ##classname, destroy ##classname }; \ + } + +#define PluginInterface2( pluginname, classname, baseclass, name, ver, rev ) \ + extern "C" { \ + baseclass *create ##classname() \ + { \ + return new classname(); \ + } \ + void destroy ##classname( baseclass *pCls ) \ + { \ + delete pCls; \ + } \ + PluginInfo pluginname = { \ + #pluginname, name, ver, rev, \ + (void *(*)())(create ##classname), \ + (void (*)( void * ))(destroy ##classname) }; \ + } + +#define PluginInterface3( structname, pluginname, classname, baseclass, name, ver, rev ) \ + extern "C" { \ + baseclass *create ##classname() \ + { \ + return new classname(); \ + } \ + void destroy ##classname( baseclass *pCls ) \ + { \ + delete pCls; \ + } \ + PluginInfo structname = { \ + #pluginname, name, ver, rev, \ + (void *(*)())(create ##classname), \ + (void (*)( void * ))(destroy ##classname) }; \ + } + + template + class Plugger + { + public: + typedef Bu::Hash PluginHash; + typedef Bu::Hash InstHash; + + public: + Plugger() + { + } + + virtual ~Plugger() + { + for( InstHash::iterator i = hObj.begin(); i != hObj.end(); i++ ) + { + T *pPlug = (T *)i.getKey(); + PluginReg *pReg = (PluginReg *)*i; + pReg->pInfo->destroyPlugin( pPlug ); + } + + for( PluginHash::iterator i = hPlugin.begin(); + i != hPlugin.end(); i++ ) + { + if( (*i)->bBuiltin == false ) + { + dlclose( (*i)->dlHandle ); + } + delete (*i); + } + } + + void registerBuiltinPlugin( PluginInfo *pInfo ) + { + PluginReg *pReg = new PluginReg; + pReg->bBuiltin = true; + pReg->pInfo = pInfo; + hPlugin.insert( pInfo->sID, pReg ); + } + + void registerExternalPlugin( const char *sFName, const char *sPluginName ) + { + PluginReg *pReg = (PluginReg *)hPlugin[sPluginName]; + if( pReg != NULL ) + { + hPlugin.erase( sPluginName ); + dlclose( pReg->dlHandle ); + delete pReg; + pReg = NULL; + } + + pReg = new PluginReg; + + pReg->bBuiltin = false; + pReg->dlHandle = dlopen( sFName, RTLD_NOW ); + if( pReg->dlHandle == NULL ) + { + throw PluginException( 1, "Error on %s: %s", sFName, dlerror() ); + } + pReg->pInfo = (PluginInfo *)dlsym( pReg->dlHandle, sPluginName ); + if( pReg->pInfo == NULL ) + { + throw PluginException( 2, "Error on %s: %s", sFName, dlerror() ); + } + hPlugin.insert( pReg->pInfo->sID, pReg ); + } + + T *instantiate( const char *lpName ) + { + PluginReg *pReg = (PluginReg *)hPlugin[lpName]; + if( pReg == NULL ) + return NULL; + + T *p = (T *)pReg->pInfo->createPlugin(); + hObj.insert( p, pReg ); + //printf("pReg: %08X, pPlug: %08X\n", pReg, p ); + + return p; + } + + bool hasPlugin( const char *lpName ) + { + if( hPlugin[lpName] == NULL ) + return false; + return true; + } + + void destroy( T *pPlug ) + { + PluginReg *pReg = (PluginReg *)hObj[pPlug]; + //printf("pReg: %08X, pPlug: %08X\n", pReg, pPlug ); + if( pReg == NULL ) + return; + + pReg->pInfo->destroyPlugin( pPlug ); + + hObj.erase( pPlug ); + } + + void unloadAll() + { + for( PluginHash::iterator i = hPlugin.begin(); + i != hPlugin.end(); i++ ) + { + if( (*i)->bBuiltin == false ) + { + dlclose( (*i)->dlHandle ); + } + delete (*i); + } + hPlugin.clear(); + } + + private: + PluginHash hPlugin; + InstHash hObj; + }; +} + +#endif diff --git a/src/programchain.cpp b/src/programchain.cpp new file mode 100644 index 0000000..0bb7a77 --- /dev/null +++ b/src/programchain.cpp @@ -0,0 +1,97 @@ +#include +#include "bu/programchain.h" +#include "bu/programlink.h" + +using namespace Bu; + +Bu::ProgramChain::ProgramChain() +{ +} + +Bu::ProgramChain::~ProgramChain() +{ +} + +bool Bu::ProgramChain::addLink( ProgramLink *pLink ) +{ + if( pLink->init() == false ) + { + emergencyShutdown(); + return false; + } + + lLink.append( pLink ); + + pLink->setChain( this ); + + return true; +} + +ProgramLink *Bu::ProgramChain::getLink( const char *lpName ) +{ + char a; + a = lpName[0]; + return NULL; +} + +ProgramLink *Bu::ProgramChain::getBaseLink() +{ + return NULL; +} + +bool Bu::ProgramChain::execChainOnce() +{ + for( Bu::List::iterator i = lLink.begin(); + i != lLink.end(); i++ ) + { + if( (*i)->timeSlice() == false ) + { + emergencyShutdown(); + return false; + } + } + + return true; +} + +bool Bu::ProgramChain::enterChainLoop() +{ + for(;;) + { + if( execChainOnce() == false ) + { + return false; + } + } + + return true; +} + +void Bu::ProgramChain::emergencyShutdown() +{ + for( Bu::List::iterator i = lLink.begin(); + i != lLink.end(); i++ ) + { + (*i)->deInit(); + delete *i; + } + lLink.clear(); +} + +LinkMessage *Bu::ProgramChain::broadcastIRM( LinkMessage *pMsgOut, ProgramLink *pSender ) +{ + for( Bu::List::iterator i = lLink.begin(); + i != lLink.end(); i++ ) + { + LinkMessage *pMsg = (*i)->processIRM( pMsgOut ); + if( pMsg != NULL ) + { + delete pMsgOut; + return pMsg; + } + } + + delete pMsgOut; + return NULL; +} + diff --git a/src/programchain.h b/src/programchain.h new file mode 100644 index 0000000..e73d659 --- /dev/null +++ b/src/programchain.h @@ -0,0 +1,98 @@ +#ifndef PROGRAMCHAIN_H +#define PROGRAMCHAIN_H + +#include "bu/list.h" +#include "bu/linkmessage.h" + +namespace Bu +{ + class ProgramLink; + /** + * The Program Chain links together program "chunks" to more easily facilitate + * a generalized program loop with modular extensions. + *@author Mike Buland + */ + class ProgramChain + { + public: + /** + * Construct an empty chain. + */ + ProgramChain(); + + /** + * Destroy your chain. + */ + virtual ~ProgramChain(); + + /** + * Adds a link to the end of the chain. + *@param pLink A pointer to the link to add to the chain. + *@returns True if adding the link was successful, otherwise false + *@author Mike Buland + */ + bool addLink( Bu::ProgramLink *pLink ); + + /** + * Gets a link by name. + *@param lpName The name of the link you're looking for. Every link has a + * name, apparently. + *@returns A pointer to the specified ProgramLink, or NULL if none were + * found matching your criteria. + *@author Mike Buland + */ + class ProgramLink *getLink( const char *lpName ); + + /** + * Gets the very first link in the chain. + *@returns A pointer to the first link in the chain. + *@author Mike Buland + */ + class ProgramLink *getBaseLink(); + + /** + * Runs through the chain once. Useful if you want to have more control + * over the operation of the chain. + *@returns true if every link returned true. If at least one link returns + * false, then returns false. + *@author Mike Buland + */ + bool execChainOnce(); + + /** + * Enters the master chain loop, looping over the entire chain and + * executing every link's TimeSlice routine in order, over and over, until + * a link returns a false value. + *@returns False, always. It returns true unless a link returned false, + * but loops until a link does return false. + *@author Mike Buland + **/ + bool enterChainLoop(); + + /** + * Broadcasts an Immediate Response Message to all active links, save the + * sender. Whatever link first responds with a non-null response message + * will have it's messages sent back to the broadcasting link as the returns + * of this function call. Therefore it is very important that all message + * processing code is handled in a fairly timely fasion. + *@param pMsgOut The message to broadcast in hopes of a response. + *@param pSender The message that sent out the message and doesn't want to + * receive it's own message. This should always just be "this". + *@returns The message that was returned by the first link to return a + * non-null response. If all messages return null responses then this also + * returns null. Please note that whoever calls this will be responsible + * for deleting the message returned by it, if non-null. + */ + class LinkMessage *broadcastIRM( LinkMessage *pMsgOut, ProgramLink *pSender ); + + private: + /** + * Shuts down all operation no matter what point in the operation we were. + */ + void emergencyShutdown(); + Bu::List lLink; /**< The linked list that contains all of the links. */ + }; +} + + +#endif diff --git a/src/programlink.cpp b/src/programlink.cpp new file mode 100644 index 0000000..e5c624c --- /dev/null +++ b/src/programlink.cpp @@ -0,0 +1,56 @@ +#include "bu/programlink.h" +#include "bu/programchain.h" + +using namespace Bu; + +Bu::ProgramLink::ProgramLink() +{ +} + +Bu::ProgramLink::~ProgramLink() +{ +} + +LinkMessage *Bu::ProgramLink::sendIRM( LinkMessage *pMsgOut ) +{ + return pChain->broadcastIRM( pMsgOut, this ); +} + +void Bu::ProgramLink::setChain( ProgramChain *pNewChain ) +{ + pChain = pNewChain; +} + +/* +void ProgramLink::postMessage( LinkMessage *pMsg, int nLvl ) +{ + if( nLvl == msgToChain ) + { + qMsgToChain.enqueue( pMsg ); + } + else if( nLvl == msgToLink ) + { + qMsgToLink.enqueue( pMsg ); + } + else + { + // ERROR! + } +} + +LinkMessage *ProgramLink::getMessage( int nLvl ) +{ + if( nLvl == msgToChain ) + { + return (LinkMessage *)qMsgToChain.dequeue(); + } + else if( nLvl == msgToLink ) + { + return (LinkMessage *)qMsgToLink.dequeue(); + } + else + { + // ERROR! + } +} +*/ diff --git a/src/programlink.h b/src/programlink.h new file mode 100644 index 0000000..7c31a18 --- /dev/null +++ b/src/programlink.h @@ -0,0 +1,100 @@ +#ifndef PROGRAMLINK_H +#define PROGRAMLINK_H + +#include "bu/linkmessage.h" +#include "bu/programchain.h" + +namespace Bu +{ + /** + * Program Link is the base class for any object that will be a piece of the + * main program chain loop. + *@author Mike Buland + */ + class ProgramLink + { + friend class Bu::ProgramChain; + public: + /** + * Construct a program link. + */ + ProgramLink(); + + /** + * Deconstruct. + */ + virtual ~ProgramLink(); + + /** + * Initialization code required for a link that wasn't performed in the + * constructor. + *@returns true if initialization was successful. A false value will halt + * the chain. + */ + virtual bool init()=0; + + /** + * DeInitialization code that should happen, but doesn't belong in the + * destructor. + *@returns true means everything worked, false means failure, but is + * meaningless. + */ + virtual bool deInit()=0; + + /** + * Executed once per link per chain pass. Contains the guts of the program. + *@returns true if everything went well. A false value will halt the chain. + */ + virtual bool timeSlice()=0; + + /** + * This must be handled in order to process Instant Response Messages. + * This function should return null on all messages that it doesn't + * understand how to handle, and construct new messages to return to sender + * in the cases where it does understand. + *@param pMsgIn The message that must be processed. + *@returns Either a new message in cases where a response is required, + * or null if nothing needs to be done by this link. + */ + virtual LinkMessage *processIRM( LinkMessage *pMsgIn ) = 0; + + /** + * Broadcast a LinkMessage to all other links in the system. Each other + * link will get a call of their processIRM function. If the message gets + * a response then you will regain control immediately, otherwise the system + * will give all other Links a chance to respond before returning NULL. + *@param pMsgOut The message to broadcast. + *@returns The message response, or NULL if no Link understood your message. + */ + LinkMessage *sendIRM( LinkMessage *pMsgOut ); + + private: + /** + * Set which chain we're assosiated with. This is how IRM messages make + * it out to the rest of the world. + *@param pNewChain A pointer to the containing program chain. + */ + void setChain( class ProgramChain *pNewChain ); + + /** + * The pointer to the containing chain. + */ + class ProgramChain *pChain; + /* + void postMessage( LinkMessage *pMsg, int nLvl ); + LinkMessage *getMessage( int nLvl ); + + enum + { + msgToChain, + msgToLink + }; + + private: + Queue qMsgToChain; + Queue qMsgToLink; + */ + }; +} + +#endif diff --git a/src/tafwriter.cpp b/src/tafwriter.cpp index 3e6c025..ac42d3d 100644 --- a/src/tafwriter.cpp +++ b/src/tafwriter.cpp @@ -1,9 +1,32 @@ #include "tafwriter.h" -Bu::TafWriter::TafWriter() +Bu::TafWriter::TafWriter( Bu::Stream &sOut ) : + sOut( sOut ) { } Bu::TafWriter::~TafWriter() { } + +void Bu::TafWriter::writeNode( Bu::TafNode *pRoot ) +{ + sOut.write("{", 1 ); + writeString( pRoot->getName().getStr() ); + sOut.write(": ", 2 ); + sOut.write("}", 1 ); +} + +void Bu::TafWriter::writeString( const Bu::FString &str ) +{ + sOut.write("\"", 1 ); + for( const char *s = str.getStr(); *s; s++ ) + { + if( *s == '\"' ) + sOut.write("\\\"", 2 ); + else + sOut.write( s, 1 ); + } + sOut.write("\"", 1 ); +} + diff --git a/src/tafwriter.h b/src/tafwriter.h index 7057d62..4310e62 100644 --- a/src/tafwriter.h +++ b/src/tafwriter.h @@ -2,6 +2,9 @@ #define BU_TAF_WRITER_H #include +#include "bu/tafnode.h" +#include "bu/stream.h" +#include "bu/fstring.h" namespace Bu { @@ -11,11 +14,14 @@ namespace Bu class TafWriter { public: - TafWriter(); + TafWriter( Bu::Stream &sOut ); virtual ~TafWriter(); - private: + void writeNode( Bu::TafNode *pRoot ); + private: + void writeString( const Bu::FString &str ); + Bu::Stream &sOut; }; } -- cgit v1.2.3 From 01ecf54b07e75c17ca5f7039084daeefaea9a1c7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 26 Jun 2007 19:22:02 +0000 Subject: Fixed a bug in the plugger and added the skeleton of the MemBuf class. --- src/membuf.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/membuf.h | 43 +++++++++++++++++++++++++++++++ src/plugger.h | 2 +- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/membuf.cpp create mode 100644 src/membuf.h (limited to 'src/plugger.h') diff --git a/src/membuf.cpp b/src/membuf.cpp new file mode 100644 index 0000000..fdb4366 --- /dev/null +++ b/src/membuf.cpp @@ -0,0 +1,81 @@ +#include "bu/membuf.h" + +using namespace Bu; + +Bu::MemBuf::MemBuf() +{ +} + +Bu::MemBuf::~MemBuf() +{ +} + +void Bu::MemBuf::close() +{ +} + +size_t Bu::MemBuf::read( void *pBuf, size_t nBytes ) +{ + +} + +size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) +{ +} + +long Bu::MemBuf::tell() +{ +} + +void Bu::MemBuf::seek( long offset ) +{ +} + +void Bu::MemBuf::setPos( long pos ) +{ +} + +void Bu::MemBuf::setPosEnd( long pos ) +{ +} + +bool Bu::MemBuf::isEOS() +{ +} + +bool Bu::MemBuf::isOpen() +{ +} + +void Bu::MemBuf::flush() +{ +} + +bool Bu::MemBuf::canRead() +{ +} + +bool Bu::MemBuf::canWrite() +{ +} + +bool Bu::MemBuf::isReadable() +{ +} + +bool Bu::MemBuf::isWritable() +{ +} + +bool Bu::MemBuf::isSeekable() +{ +} + +bool Bu::MemBuf::isBlocking() +{ +} + +void Bu::MemBuf::setBlocking( bool bBlocking ) +{ +} + diff --git a/src/membuf.h b/src/membuf.h new file mode 100644 index 0000000..2cbbbdc --- /dev/null +++ b/src/membuf.h @@ -0,0 +1,43 @@ +#ifndef MEM_BUF_H +#define MEM_BUF_H + +#include + +#include "bu/stream.h" + +namespace Bu +{ + /** + * A memory buffer stream. + */ + class MemBuf : public Stream + { + public: + MemBuf(); + virtual ~MemBuf(); + + virtual void close(); + virtual size_t read( void *pBuf, size_t nBytes ); + virtual size_t write( const void *pBuf, size_t nBytes ); + virtual long tell(); + virtual void seek( long offset ); + virtual void setPos( long pos ); + virtual void setPosEnd( long pos ); + virtual bool isEOS(); + virtual bool isOpen(); + virtual void flush(); + virtual bool canRead(); + virtual bool canWrite(); + virtual bool isReadable(); + virtual bool isWritable(); + virtual bool isSeekable(); + virtual bool isBlocking(); + virtual void setBlocking( bool bBlocking=true ); + + private: + Bu::FString sBuf; + long nPos; + }; +} + +#endif diff --git a/src/plugger.h b/src/plugger.h index 98d4ecc..01bbb50 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -148,7 +148,7 @@ namespace Bu return NULL; T *p = (T *)pReg->pInfo->createPlugin(); - hObj.insert( p, pReg ); + hObj.insert( (int )p, pReg ); //printf("pReg: %08X, pPlug: %08X\n", pReg, p ); return p; -- cgit v1.2.3 From 45124f3982e41994bb203420c9a13e7039c973b5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 28 Jun 2007 19:22:00 +0000 Subject: Another stupid plugger bug. --- src/plugger.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugger.h') diff --git a/src/plugger.h b/src/plugger.h index 01bbb50..019cc23 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -163,7 +163,7 @@ namespace Bu void destroy( T *pPlug ) { - PluginReg *pReg = (PluginReg *)hObj[pPlug]; + PluginReg *pReg = (PluginReg *)hObj[(int)pPlug]; //printf("pReg: %08X, pPlug: %08X\n", pReg, pPlug ); if( pReg == NULL ) return; -- cgit v1.2.3 From db15bc90703b0ccafd53ca16c0ef68673f66a184 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 28 Jun 2007 19:23:14 +0000 Subject: Oi, another bug fix, the same line... --- src/plugger.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugger.h') diff --git a/src/plugger.h b/src/plugger.h index 019cc23..2a85e17 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -163,7 +163,7 @@ namespace Bu void destroy( T *pPlug ) { - PluginReg *pReg = (PluginReg *)hObj[(int)pPlug]; + PluginReg *pReg = (PluginReg *)hObj.get((int)pPlug); //printf("pReg: %08X, pPlug: %08X\n", pReg, pPlug ); if( pReg == NULL ) return; -- cgit v1.2.3 From d35ef3b116e793dca1c9c5b07e47aec44b109c25 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 28 Jun 2007 19:24:20 +0000 Subject: Another one, five lines down. --- src/plugger.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugger.h') diff --git a/src/plugger.h b/src/plugger.h index 2a85e17..4d2e7af 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -170,7 +170,7 @@ namespace Bu pReg->pInfo->destroyPlugin( pPlug ); - hObj.erase( pPlug ); + hObj.erase( (int)pPlug ); } void unloadAll() -- cgit v1.2.3 From 932677862376e9642a496a15b7f09f1106f495a5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 28 Jun 2007 20:49:39 +0000 Subject: Many minor changes, hopefully the header fixes will keep future header macro conflicts from happening. And, from now on, other projects should do -Ilibbu++ not -Ilibbu++/src so we can get ready for an installed version of libbu++. --- bu | 1 + src/archival.h | 4 ++-- src/archive.h | 4 ++-- src/atom.h | 4 ++-- src/bzip2.h | 4 ++-- src/client.h | 4 ++-- src/exceptionbase.h | 4 ++-- src/exceptions.h | 4 ++-- src/file.h | 4 ++-- src/filter.h | 4 ++-- src/fstring.h | 4 ++-- src/hash.h | 4 ++-- src/ito.h | 4 ++-- src/itoatom.h | 4 ++-- src/itocondition.h | 4 ++-- src/itomutex.h | 4 ++-- src/itoqueue.h | 4 ++-- src/linkmessage.h | 4 ++-- src/list.h | 4 ++-- src/membuf.h | 4 ++-- src/paramproc.h | 4 ++-- src/plugger.h | 4 ++-- src/programchain.h | 4 ++-- src/programlink.h | 4 ++-- src/protocol.h | 4 ++-- src/ringbuffer.h | 4 ++-- src/server.h | 4 ++-- src/serversocket.h | 4 ++-- src/singleton.h | 4 ++-- src/socket.h | 4 ++-- src/sptr.h | 4 ++-- src/stream.h | 4 ++-- src/unitsuite.h | 4 ++-- 33 files changed, 65 insertions(+), 64 deletions(-) create mode 120000 bu (limited to 'src/plugger.h') diff --git a/bu b/bu new file mode 120000 index 0000000..02b8847 --- /dev/null +++ b/bu @@ -0,0 +1 @@ +src/bu/ \ No newline at end of file diff --git a/src/archival.h b/src/archival.h index e2c803c..8be3308 100644 --- a/src/archival.h +++ b/src/archival.h @@ -1,5 +1,5 @@ -#ifndef ARCHIVAL_H -#define ARCHIVAL_H +#ifndef BU_ARCHIVAL_H +#define BU_ARCHIVAL_H namespace Bu { diff --git a/src/archive.h b/src/archive.h index 05c6f57..6c0c1df 100644 --- a/src/archive.h +++ b/src/archive.h @@ -1,5 +1,5 @@ -#ifndef ARCHIVE_H -#define ARCHIVE_H +#ifndef BU_ARCHIVE_H +#define BU_ARCHIVE_H #include #include diff --git a/src/atom.h b/src/atom.h index a0469b6..fad47eb 100644 --- a/src/atom.h +++ b/src/atom.h @@ -1,5 +1,5 @@ -#ifndef ATOM_H -#define ATOM_H +#ifndef BU_ATOM_H +#define BU_ATOM_H #include #include diff --git a/src/bzip2.h b/src/bzip2.h index 25f10c5..0a111e8 100644 --- a/src/bzip2.h +++ b/src/bzip2.h @@ -1,5 +1,5 @@ -#ifndef B_ZIP2_H -#define B_ZIP2_H +#ifndef BU_BZIP2_H +#define BU_BZIP2_H #include #include diff --git a/src/client.h b/src/client.h index 02ba077..cee558d 100644 --- a/src/client.h +++ b/src/client.h @@ -1,5 +1,5 @@ -#ifndef CLIENT_H -#define CLIENT_H +#ifndef BU_CLIENT_H +#define BU_CLIENT_H #include diff --git a/src/exceptionbase.h b/src/exceptionbase.h index fd78089..24e4bbf 100644 --- a/src/exceptionbase.h +++ b/src/exceptionbase.h @@ -1,5 +1,5 @@ -#ifndef EXCEPTION_BASE_H -#define EXCEPTION_BASE_H +#ifndef BU_EXCEPTION_BASE_H +#define BU_EXCEPTION_BASE_H #include #include diff --git a/src/exceptions.h b/src/exceptions.h index d5a9d39..b824b91 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -1,5 +1,5 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H +#ifndef BU_EXCEPTIONS_H +#define BU_EXCEPTIONS_H #include "exceptionbase.h" #include diff --git a/src/file.h b/src/file.h index 0f638a7..d4e43eb 100644 --- a/src/file.h +++ b/src/file.h @@ -1,5 +1,5 @@ -#ifndef FILE_H -#define FILE_H +#ifndef BU_FILE_H +#define BU_FILE_H #include diff --git a/src/filter.h b/src/filter.h index 7bb04bc..bd557b2 100644 --- a/src/filter.h +++ b/src/filter.h @@ -1,5 +1,5 @@ -#ifndef FILTER_H -#define FILTER_H +#ifndef BU_FILTER_H +#define BU_FILTER_H #include diff --git a/src/fstring.h b/src/fstring.h index 7180f5f..bf6518b 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -1,5 +1,5 @@ -#ifndef F_STRING_H -#define F_STRING_H +#ifndef BU_F_STRING_H +#define BU_F_STRING_H #include #include diff --git a/src/hash.h b/src/hash.h index 6c4a443..0fa3af7 100644 --- a/src/hash.h +++ b/src/hash.h @@ -1,5 +1,5 @@ -#ifndef HASH_H -#define HASH_H +#ifndef BU_HASH_H +#define BU_HASH_H #include #include diff --git a/src/ito.h b/src/ito.h index 01253f5..c062052 100644 --- a/src/ito.h +++ b/src/ito.h @@ -1,5 +1,5 @@ -#ifndef ITO_H -#define ITO_H +#ifndef BU_ITO_H +#define BU_ITO_H #include diff --git a/src/itoatom.h b/src/itoatom.h index 96090f2..7fc9090 100644 --- a/src/itoatom.h +++ b/src/itoatom.h @@ -1,5 +1,5 @@ -#ifndef ITO_QUEUE_H -#define ITO_QUEUE_H +#ifndef BU_ITO_QUEUE_H +#define BU_ITO_QUEUE_H #include diff --git a/src/itocondition.h b/src/itocondition.h index 4771b22..1793f81 100644 --- a/src/itocondition.h +++ b/src/itocondition.h @@ -1,5 +1,5 @@ -#ifndef ITO_CONDITION_H -#define ITO_CONDITION_H +#ifndef BU_ITO_CONDITION_H +#define BU_ITO_CONDITION_H #include diff --git a/src/itomutex.h b/src/itomutex.h index 80956b8..9c9d205 100644 --- a/src/itomutex.h +++ b/src/itomutex.h @@ -1,5 +1,5 @@ -#ifndef ITO_MUTEX_H -#define ITO_MUTEX_H +#ifndef BU_ITO_MUTEX_H +#define BU_ITO_MUTEX_H #include diff --git a/src/itoqueue.h b/src/itoqueue.h index 322698d..75a2f27 100644 --- a/src/itoqueue.h +++ b/src/itoqueue.h @@ -1,5 +1,5 @@ -#ifndef ITO_QUEUE_H -#define ITO_QUEUE_H +#ifndef BU_ITO_QUEUE_H +#define BU_ITO_QUEUE_H #include diff --git a/src/linkmessage.h b/src/linkmessage.h index 64b8bc2..baa22a6 100644 --- a/src/linkmessage.h +++ b/src/linkmessage.h @@ -1,8 +1,8 @@ /**\file linkmessage.h */ -#ifndef LINKMESSAGE_H -#define LINKMESSAGE_H +#ifndef BU_LINKMESSAGE_H +#define BU_LINKMESSAGE_H namespace Bu { diff --git a/src/list.h b/src/list.h index 314459e..6235619 100644 --- a/src/list.h +++ b/src/list.h @@ -1,5 +1,5 @@ -#ifndef LIST_H -#define LIST_H +#ifndef BU_LIST_H +#define BU_LIST_H #include #include "bu/exceptionbase.h" diff --git a/src/membuf.h b/src/membuf.h index 877b35e..b82f943 100644 --- a/src/membuf.h +++ b/src/membuf.h @@ -1,5 +1,5 @@ -#ifndef MEM_BUF_H -#define MEM_BUF_H +#ifndef BU_MEM_BUF_H +#define BU_MEM_BUF_H #include diff --git a/src/paramproc.h b/src/paramproc.h index beee4a0..2bca588 100644 --- a/src/paramproc.h +++ b/src/paramproc.h @@ -1,5 +1,5 @@ -#ifndef PARAM_PROC_H -#define PARAM_PROC_H +#ifndef BU_PARAM_PROC_H +#define BU_PARAM_PROC_H #include #include diff --git a/src/plugger.h b/src/plugger.h index 4d2e7af..79a3271 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -1,5 +1,5 @@ -#ifndef PLUGGER_H -#define PLUGGER_H +#ifndef BU_PLUGGER_H +#define BU_PLUGGER_H #include "bu/hash.h" diff --git a/src/programchain.h b/src/programchain.h index e73d659..336a9f1 100644 --- a/src/programchain.h +++ b/src/programchain.h @@ -1,5 +1,5 @@ -#ifndef PROGRAMCHAIN_H -#define PROGRAMCHAIN_H +#ifndef BU_PROGRAMCHAIN_H +#define BU_PROGRAMCHAIN_H #include "bu/list.h" #include "bu/linkmessage.h" diff --git a/src/programlink.h b/src/programlink.h index 7c31a18..07d7489 100644 --- a/src/programlink.h +++ b/src/programlink.h @@ -1,5 +1,5 @@ -#ifndef PROGRAMLINK_H -#define PROGRAMLINK_H +#ifndef BU_PROGRAMLINK_H +#define BU_PROGRAMLINK_H #include "bu/linkmessage.h" #include "bu/programchain.h" diff --git a/src/protocol.h b/src/protocol.h index 3accd99..c7a9275 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -1,5 +1,5 @@ -#ifndef PROTOCOL_H -#define PROTOCOL_H +#ifndef BU_PROTOCOL_H +#define BU_PROTOCOL_H #include diff --git a/src/ringbuffer.h b/src/ringbuffer.h index 625f65b..be80e2f 100644 --- a/src/ringbuffer.h +++ b/src/ringbuffer.h @@ -1,5 +1,5 @@ -#ifndef RING_BUFFER_H -#define RING_BUFFER_H +#ifndef BU_RING_BUFFER_H +#define BU_RING_BUFFER_H #include #include "bu/exceptionbase.h" diff --git a/src/server.h b/src/server.h index 07eef95..302b6e3 100644 --- a/src/server.h +++ b/src/server.h @@ -1,5 +1,5 @@ -#ifndef SERVER_H -#define SERVER_H +#ifndef BU_SERVER_H +#define BU_SERVER_H #include diff --git a/src/serversocket.h b/src/serversocket.h index cb86078..b4ee247 100644 --- a/src/serversocket.h +++ b/src/serversocket.h @@ -1,5 +1,5 @@ -#ifndef SERVER_SOCKET_H -#define SERVER_SOCKET_H +#ifndef BU_SERVER_SOCKET_H +#define BU_SERVER_SOCKET_H #include #include "bu/fstring.h" diff --git a/src/singleton.h b/src/singleton.h index 4976a61..c43d71b 100644 --- a/src/singleton.h +++ b/src/singleton.h @@ -1,5 +1,5 @@ -#ifndef SINGLETON_H -#define SINGLETON_H +#ifndef BU_SINGLETON_H +#define BU_SINGLETON_H #include diff --git a/src/socket.h b/src/socket.h index c9dbd8d..0ccee3b 100644 --- a/src/socket.h +++ b/src/socket.h @@ -1,5 +1,5 @@ -#ifndef SOCKET_H -#define SOCKET_H +#ifndef BU_SOCKET_H +#define BU_SOCKET_H #include diff --git a/src/sptr.h b/src/sptr.h index 4baa697..75851a6 100644 --- a/src/sptr.h +++ b/src/sptr.h @@ -1,5 +1,5 @@ -#ifndef SPTR_H -#define SPTR_H +#ifndef BU_SPTR_H +#define BU_SPTR_H #include #include diff --git a/src/stream.h b/src/stream.h index 056de0c..1e236a6 100644 --- a/src/stream.h +++ b/src/stream.h @@ -1,5 +1,5 @@ -#ifndef STREAM_H -#define STREAM_H +#ifndef BU_STREAM_H +#define BU_STREAM_H #include #include diff --git a/src/unitsuite.h b/src/unitsuite.h index 6e9270a..578b4cc 100644 --- a/src/unitsuite.h +++ b/src/unitsuite.h @@ -1,5 +1,5 @@ -#ifndef UNIT_SUITE_H -#define UNIT_SUITE_H +#ifndef BU_UNIT_SUITE_H +#define BU_UNIT_SUITE_H #include #include -- cgit v1.2.3 From f896b0e207e0b656109ef0e9f721f27ce53a836e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 28 Jun 2007 22:47:03 +0000 Subject: Client code is better, so is the socket, you can get addresses and other cool things from it. The plugger had yet another bugfix...plugger... --- src/client.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- src/client.h | 10 +++++++++- src/plugger.h | 6 +++--- src/socket.cpp | 12 ++++++++++++ src/socket.h | 2 ++ 5 files changed, 79 insertions(+), 5 deletions(-) (limited to 'src/plugger.h') diff --git a/src/client.cpp b/src/client.cpp index 0e48285..63822ba 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -10,7 +10,8 @@ Bu::Client::Client( Bu::Socket *pSocket ) : pSocket( pSocket ), - pProto( NULL ) + pProto( NULL ), + nRBOffset( 0 ) { } @@ -103,3 +104,54 @@ void Bu::Client::write( const char *pData, int nBytes ) sWriteBuf.append( pData, nBytes ); } +void Bu::Client::write( int8_t nData ) +{ + sWriteBuf.append( (const char *)&nData, sizeof(nData) ); +} + +void Bu::Client::write( int16_t nData ) +{ + sWriteBuf.append( (const char *)&nData, sizeof(nData) ); +} + +void Bu::Client::write( int32_t nData ) +{ + sWriteBuf.append( (const char *)&nData, sizeof(nData) ); +} + +void Bu::Client::write( int64_t nData ) +{ + sWriteBuf.append( (const char *)&nData, sizeof(nData) ); +} + +void Bu::Client::read( char *pData, int nBytes ) +{ + memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes ); + nRBOffset += nBytes; + if( sReadBuf.getSize()-nRBOffset == 0 ) + { + sReadBuf.clear(); + nRBOffset = 0; + } + // This is an experimental threshold, maybe I'll make this configurable + // later on. + else if( + (sReadBuf.getSize() >= 1024 && nRBOffset >= sReadBuf.getSize()/2) || + (nRBOffset >= sReadBuf.getSize()/4) + ) + { + sReadBuf.trimFront( nRBOffset ); + nRBOffset = 0; + } +} + +long Bu::Client::getInputSize() +{ + return sReadBuf.getSize()-nRBOffset; +} + +const Bu::Socket *Bu::Client::getSocket() const +{ + return pSocket; +} + diff --git a/src/client.h b/src/client.h index f228e96..b400bb3 100644 --- a/src/client.h +++ b/src/client.h @@ -25,7 +25,12 @@ namespace Bu Bu::FString &getInput(); Bu::FString &getOutput(); void write( const char *pData, int nBytes ); - void read( const char *pData, int nBytes ); + void write( int8_t nData ); + void write( int16_t nData ); + void write( int32_t nData ); + void write( int64_t nData ); + void read( char *pData, int nBytes ); + long getInputSize(); void setProtocol( Protocol *pProto ); Bu::Protocol *getProtocol(); @@ -33,10 +38,13 @@ namespace Bu bool isOpen(); + const Bu::Socket *getSocket() const; + private: Bu::Socket *pSocket; Bu::Protocol *pProto; Bu::FString sReadBuf; + int nRBOffset; Bu::FString sWriteBuf; }; } diff --git a/src/plugger.h b/src/plugger.h index 79a3271..615a662 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -37,7 +37,7 @@ namespace Bu { \ delete pCls; \ } \ - PluginInfo classname = { \ + Bu::PluginInfo classname = { \ #classname, name, ver, rev, \ create ##classname, destroy ##classname }; \ } @@ -52,7 +52,7 @@ namespace Bu { \ delete pCls; \ } \ - PluginInfo pluginname = { \ + Bu::PluginInfo pluginname = { \ #pluginname, name, ver, rev, \ (void *(*)())(create ##classname), \ (void (*)( void * ))(destroy ##classname) }; \ @@ -68,7 +68,7 @@ namespace Bu { \ delete pCls; \ } \ - PluginInfo structname = { \ + Bu::PluginInfo structname = { \ #pluginname, name, ver, rev, \ (void *(*)())(create ##classname), \ (void (*)( void * ))(destroy ##classname) }; \ diff --git a/src/socket.cpp b/src/socket.cpp index bd05024..5a3097c 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -276,3 +276,15 @@ bool Bu::Socket::isOpen() return bActive; } +Bu::FString Bu::Socket::getAddress() const +{ + struct sockaddr_in addr; + socklen_t len = sizeof(addr); + addr.sin_family = AF_INET; + getsockname( nSocket, (sockaddr *)(&addr), &len ); + char buf[150]; + sprintf( buf, "%s", inet_ntoa( addr.sin_addr ) ); + + return buf; +} + diff --git a/src/socket.h b/src/socket.h index 0ccee3b..9e36041 100644 --- a/src/socket.h +++ b/src/socket.h @@ -42,6 +42,8 @@ namespace Bu virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); + Bu::FString getAddress() const; + private: int nSocket; bool bActive; -- cgit v1.2.3 From 60bac0c9f558ab34c70f099db923204a84d51ffc Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 29 Jun 2007 01:59:26 +0000 Subject: The plugger was dying on a HashException it should have caught, and the Logger now allows you to include extra printf formatting in your fields just like the docs say you can. --- src/logger.cpp | 32 ++++++++++++++++++++------------ src/plugger.h | 8 +++++--- src/tests/logger.cpp | 2 +- 3 files changed, 26 insertions(+), 16 deletions(-) (limited to 'src/plugger.h') diff --git a/src/logger.cpp b/src/logger.cpp index 848dfb1..1fc2262 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -71,22 +71,30 @@ void Bu::Logger::setFormat( const Bu::FString &str ) if( *s == '%' ) { sLogFormat += '%'; - s++; - for( int l = 0;; l++ ) + Bu::FString sBuf; + for(;;) { - if( fmts[l][0] == '\0' ) + s++; + int l; + for( l = 0;; l++ ) { - sLogFormat += *s; - break; + if( fmts[l][0] == '\0' ) + { + sBuf += *s; + break; + } + else if( *s == fmts[l][0] ) + { + sLogFormat += fmts[l][2]; + sLogFormat += fmts[l][3]; + sLogFormat += '$'; + sLogFormat += sBuf; + sLogFormat += fmts[l][1]; + break; + } } - else if( *s == fmts[l][0] ) - { - sLogFormat += fmts[l][2]; - sLogFormat += fmts[l][3]; - sLogFormat += '$'; - sLogFormat += fmts[l][1]; + if( fmts[l][0] != '\0' ) break; - } } } else diff --git a/src/plugger.h b/src/plugger.h index 615a662..2124b7a 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -116,13 +116,15 @@ namespace Bu void registerExternalPlugin( const char *sFName, const char *sPluginName ) { - PluginReg *pReg = (PluginReg *)hPlugin[sPluginName]; - if( pReg != NULL ) - { + PluginReg *pReg; + try { + pReg = (PluginReg *)hPlugin[sPluginName]; hPlugin.erase( sPluginName ); dlclose( pReg->dlHandle ); delete pReg; pReg = NULL; + } catch( Bu::HashException &e ) + { } pReg = new PluginReg; diff --git a/src/tests/logger.cpp b/src/tests/logger.cpp index a271443..290f479 100644 --- a/src/tests/logger.cpp +++ b/src/tests/logger.cpp @@ -19,7 +19,7 @@ class Thing int main() { setLogLevel( 4 ); - setLogFormat("%L: %y-%m-%d %h:%M:%s %f:%l:%F: %t"); + setLogFormat("%L: %y-%02m-%02d %h:%02M:%02s %f:%l:%F: %t"); lineLog( 5, "Hey, error: %s", strerror( errno ) ); Thing gh; -- cgit v1.2.3