UniSet  2.6.0
PassiveLProcessor.h
00001 /*
00002  * Copyright (c) 2015 Pavel Vainerman.
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as
00006  * published by the Free Software Foundation, version 2.1.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00011  * Lesser General Lesser Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00015  */
00016 // --------------------------------------------------------------------------
00017 #ifndef PassiveLProcessor_H_
00018 #define PassiveLProcessor_H_
00019 // --------------------------------------------------------------------------
00020 #include <map>
00021 #include <memory>
00022 #include "UniSetTypes.h"
00023 #include "UniSetObject.h"
00024 #include "Extensions.h"
00025 #include "SharedMemory.h"
00026 #include "UInterface.h"
00027 #include "SMInterface.h"
00028 #include "LProcessor.h"
00029 // --------------------------------------------------------------------------
00030 namespace uniset
00031 {
00032 // -------------------------------------------------------------------------
00034 class PassiveLProcessor:
00035     public UniSetObject,
00036     protected LProcessor
00037 {
00038     public:
00039 
00040         PassiveLProcessor(uniset::ObjectId objId,
00041                           uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr, const std::string& prefix = "lproc" );
00042         virtual ~PassiveLProcessor();
00043 
00044         enum Timers
00045         {
00046             tidStep
00047         };
00048 
00049         static void help_print( int argc, const char* const* argv );
00050 
00051         static std::shared_ptr<PassiveLProcessor> init_plproc( int argc, const char* const* argv,
00052                 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
00053                 const std::string& prefix = "plproc" );
00054 
00055     protected:
00056         PassiveLProcessor(): shm(0), maxHeartBeat(0) {};
00057 
00058         virtual void step();
00059         virtual void getInputs();
00060         virtual void setOuts();
00061 
00062         void sysCommand( const uniset::SystemMessage* msg ) override;
00063         void sensorInfo( const uniset::SensorMessage* sm ) override;
00064         void timerInfo( const uniset::TimerMessage* tm ) override;
00065         void askSensors( const UniversalIO::UIOCommand cmd );
00066         //        void initOutput();
00067 
00068         // действия при завершении работы
00069         virtual void sigterm( int signo ) override;
00070         void initIterators();
00071         virtual bool activateObject() override;
00072 
00073         std::shared_ptr<SMInterface> shm;
00074 
00075     private:
00076         PassiveTimer ptHeartBeat;
00077         uniset::ObjectId sidHeartBeat = { uniset::DefaultObjectId };
00078         int maxHeartBeat = { 10 };
00079         IOController::IOStateList::iterator itHeartBeat;
00080         std::mutex mutex_start;
00081 };
00082 // --------------------------------------------------------------------------
00083 } // end of namespace uniset
00084 // ---------------------------------------------------------------------------
00085 #endif