User Manual, Developers Guide and API Documentation

Stamper.hpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * Glue                                                                       *
00003  * __________________________________________________________________________ *
00004  *                                                                            *
00005  * Copyright (C) 2005-2006                                                    *
00006  * Lehrstuhl fuer Kommunikationsnetze (ComNets)                               *
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany                                 *
00008  * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242                   *
00009  * email: wns@comnets.rwth-aachen.de                                          *
00010  * www: http://wns.comnets.rwth-aachen.de                                     *
00011  ******************************************************************************/
00012 
00013 #ifndef GLUE_STAMPER_HPP
00014 #define GLUE_STAMPER_HPP
00015 
00016 #include <WNS/ldk/fun/FUN.hpp>
00017 #include <WNS/ldk/HasReceptor.hpp>
00018 #include <WNS/ldk/HasConnector.hpp>
00019 #include <WNS/ldk/HasDeliverer.hpp>
00020 #include <WNS/ldk/Processor.hpp>
00021 #include <WNS/ldk/CommandTypeSpecifier.hpp>
00022 #include <WNS/pyconfig/View.hpp>
00023 #include <WNS/logger/Logger.hpp>
00024 #include <WNS/Cloneable.hpp>
00025 #include <WNS/Assure.hpp>
00026 
00027 #include <string>
00028 
00029 namespace glue {
00030 
00034     template <class COMMAND>
00035     class Stamper :
00036     public wns::ldk::Processor<Stamper<COMMAND> >,
00037     public wns::ldk::CommandTypeSpecifier<COMMAND>,
00038     public wns::ldk::HasReceptor<>,
00039     public wns::ldk::HasConnector<>,
00040     public wns::ldk::HasDeliverer<>,
00041     public wns::Cloneable<Stamper<COMMAND> >
00042     {
00043     public:
00044     typedef COMMAND Command;
00045 
00046     Stamper(wns::ldk::fun::FUN* fun, wns::pyconfig::View& config) :
00047         wns::ldk::Processor<Stamper<Command> >(),
00048         wns::ldk::CommandTypeSpecifier<COMMAND>(fun),
00049         wns::ldk::HasReceptor<>(),
00050         wns::ldk::HasConnector<>(),
00051         wns::ldk::HasDeliverer<>(),
00052         wns::Cloneable<Stamper<COMMAND> >(),
00053 
00054         stamp(NULL),
00055         logger(config.get<wns::pyconfig::View>("logger")),
00056         logMessage(config.get<std::string>("logMessage"))
00057     {
00058     }       
00059 
00060     virtual
00061     ~Stamper()
00062     {
00063         if (stamp != NULL) delete stamp;
00064     }
00065 
00066     // ProcessorInterface
00067     virtual void
00068     processIncoming(const wns::ldk::CompoundPtr& /* compound */)
00069     {
00070     }
00071     
00072     virtual void
00073     processOutgoing(const wns::ldk::CompoundPtr& compound)
00074     {
00075         assure(stamp != NULL, "I'm a stamper without a stamp. I'm damn useless.");
00076         if (logMessage != "") {
00077         MESSAGE_BEGIN(NORMAL, logger, m, this->getFUN()->getName());
00078         m << logMessage;
00079         MESSAGE_END();
00080         }
00081         Command* command = this->activateCommand(compound->getCommandPool());
00082         (*command) = (*stamp);
00083     }
00084 
00085     // Selectors
00093     void
00094     setStamp(const Command& stamp)
00095     {
00096         if (this->stamp != NULL) delete this->stamp;
00097         this->stamp = new Command(stamp);
00098     }
00099 
00103     const Command&
00104     getStamp() const
00105     {
00106         return *stamp;
00107     }
00108 
00109     private:
00110     Command* stamp;
00111     wns::logger::Logger logger;
00112     std::string logMessage;
00113     };
00114 
00115 }
00116 
00117 #endif // GLUE_STAMPER_HPP

Generated on Fri May 25 03:32:00 2012 for openWNS by  doxygen 1.5.5