Go to the documentation of this file.00001
00002
00003
00004
00005
00008
00009 #ifndef lgrInterface_H_
00010 #define lgrInterface_H_
00011
00012 #include "lgrCore.h"
00013 #include "virtualConstructor.h"
00014 #include "lgrCommand.h"
00015 #include "lgrCommandDispatcher.h"
00016 #include "lgrCommandQueue.h"
00017 #include "lgrCommandFunctor.h"
00018
00019 #include "logger.h"
00020 #include "lgrDriver.h"
00021
00022 #include <map>
00023 #include <list>
00024
00025 namespace MAKLogger
00026 {
00027 class DtLogger;
00028 class DtLgrCommandHandler;
00029
00033 class DT_DLL_LGRCORE DtCommandInterface
00034 {
00035 public:
00037 DT_VIRTUAL_CTR(DtCommandInterface,(DtCommandDispatcherSP))
00038
00039
00040 virtual ~DtCommandInterface();
00041
00047 virtual bool update();
00048
00051 void disconnectFromDispatcher();
00052
00054 void reconnectToDispatcher();
00055
00056 void addResponseHandler(const DtCommand& command,DtResponseFunctorSP);
00057
00059 virtual void sendCommand(const DtCommand&) const;
00060
00063 bool executeResponse(DtResponse command);
00064
00065 private:
00067 DtCommandInterface( const DtCommandInterface& src );
00068 DtCommandInterface& operator=( const DtCommandInterface& src );
00069
00070 protected:
00071
00073 typedef std::map<DtCommand,DtResponseFunctorSP,std::less<DtCommand> > DtResponseMap;
00074 DtResponseMap myResponseMap;
00075
00077 DtResponseQueueSP myResponseQueue;
00078
00080 DtCommandDispatcherSP myDispatcher;
00081
00082 };
00083
00085 template <typename CommandHandlerType>
00086 static typename CommandHandlerType::Interface* createInterface(DtLogger& logger)
00087 {
00088 DtBoost::shared_ptr<DtLgrCommandHandler> commandHandler = \
00089 logger.getCommandHandler(CommandHandlerType::Factory::theCommandType);
00090
00091 if(commandHandler)
00092 {
00093 commandHandler->lock();
00094 DtBoost::shared_ptr<CommandHandlerType> subCommandHandler = \
00095 DtBoost::dynamic_pointer_cast<CommandHandlerType>(commandHandler);
00096 if(subCommandHandler)
00097 {
00098 typename CommandHandlerType::Interface* commandInterface = \
00099 CommandHandlerType::Interface::createNonThreadsafe(logger,
00100 *subCommandHandler);
00101
00102 commandHandler->unlock();
00103 return commandInterface;
00104 }
00105 commandHandler->unlock();
00106 }
00107 return 0;
00108 }
00109
00110 }
00111
00112 #endif //! DtCommandInterface_H_