<?xml version="1.0" encoding="utf-8"?> <!-- name -   msgcount -       sleep_msec -       type ==== in -  (  ) out -  () --> <Controller> <settings> <set name="class-name" val="Controller"/> <set name="msg-count" val="30"/> <set name="sleep-msec" val="150"/> </settings> <variables> <item name="HiLevel" type="long" const="1" default="95" max="100" comment="  "/> <item name="LowLevel" type="long" const="1" default="5" min=0" comment="  "/> </variables> <smap> <item name="OnControl_s" vartype="in" iotype="DI" comment="  "/> <item name="Level_s" vartype="in" iotype="AI" comment="   "/> <item name="cmdLoad_c" vartype="out" iotype="DO" comment="  ''"/> <item name="cmdUnload_c" vartype="out" iotype="DO" comment="  ''"/> </smap> <msgmap> </msgmap> </Controller>  <settings> ... <Controller name="Controller1" HiLevel="90"/> </settings>  --Controller1-HiLoad 93  uniset2-codegen -n Controller --ask --no-main controller.src.xml  bin_PROGRAMS = controller BUILT_SOURCES = Controller_SK.h Controller_SK.h controller_LDADD = $(top_builddir)/lib/libUniSetExample.la #controller_CPPFLAGS = controller_SOURCES = Controller_SK.cc Controller.cc controller-main.cc Controller_SK.h Controller_SK.cc: controller.src.xml @UNISET_CODEGEN@ -n Controller --topdir $(top_builddir)/ --ask --no-main controller.src.xml clean-local: rm -rf *_SK.cc *_SK.h *.log  <objects name="Objects" section="Objects"> ... <item id="20002" name="Controller1"/> </objects>  <settings> <Controller name="Controller1" HiLevel="90" OnControl_s="OnControl_S" Level_s="Level_AS" cmdLoad_c="CmdLoad_C" cmdUnload_c="CmdUnload_C"/> </settings>  void Controller::sensorInfo(const UniSetTypes::SensorMessage* sm) { if( sm->id == OnControl_s ) { if( sm->value ) { myinfo << myname << "(sensorInfo):   .." << endl; if( in_Level_s > LowLevel && in_Level_s < HiLevel ) { //   "" out_cmdLoad_c = true; out_cmdUnload_c = false; } else processing(); } else { myinfo << myname << "(sensorInfo):   .." << endl; //     out_cmdLoad_c = false; out_cmdUnload_c = false; } } else if( sm->id == Level_s ) { //   ,   if( in_OnControl_s ) processing(); } } // ----------------------------------------------------------------------------- void Controller::processing() { if( in_Level_s >= HiLevel ) { myinfo << myname << "(sensorInfo):   (" << HiLevel << ").  .." << endl; //  "" out_cmdLoad_c = false; out_cmdUnload_c = true; } else if( in_Level_s <= LowLevel ) { myinfo << myname << "(sensorInfo):   (" << LowLevel << ").  .." << endl; //  "" out_cmdLoad_c = true; out_cmdUnload_c = false; } }  #ifndef Controller_H_ #define Controller_H_ // ----------------------------------------------------------------------------- #include <string> #include "Controller_SK.h" // ----------------------------------------------------------------------------- /*! \page_Controller    - \ref sec_controller_Common \section sec_controller_Common         OnControl_s=1  ,    ,       HiLevel.    «»   ,     LowLevel.    .    OnControl_s=0,   . */ class Controller: public Controller_SK { public: Controller( UniSetTypes::ObjectId id, xmlNode* cnode, const std::string& prefix = "" ); virtual ~Controller(); protected: virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override; virtual std::string getMonitInfo() override; //  ( ) void processing(); private: }; // ----------------------------------------------------------------------------- #endif // Controller_H_  #include <UniSetActivator.h> #include "UniSetExampleConfiguration.h" #include "Controller.h" // ----------------------------------------------------------------------------- using namespace UniSetTypes; using namespace std; // ----------------------------------------------------------------------------- int main( int argc, const char** argv ) { try { auto conf = uniset_init(argc, argv); auto act = UniSetActivator::Instance(); auto cn = UniSetExample::make_object<Controller>("Controller1", "Controller"); act->add(cn); SystemMessage sm(SystemMessage::StartUp); act->broadcast( sm.transport_msg() ); act->run(false); return 0; } catch( const Exception& ex ) { cerr << "(controller): " << ex << endl; } catch( const std::exception& ex ) { cerr << "(controller): " << ex.what() << endl; } catch(...) { cerr << "(controller): catch(...)" << endl; } return 1; } // -----------------------------------------------------------------------------  [pv@pvbook Controller]$ ./start_fg.sh 04/03/2016 15:39:19( info): Controller1(waitSM): waiting SM ready 60000 msec testID=100 04/03/2016 15:39:19( info): Controller1(sensorInfo):   ..  [pv@pvbook Administrator]$ ./exist ||=======******** UNISET-EXAMPLE/Services ********=========|| !!!!!! ||=======******** UNISET-EXAMPLE/Controllers ********=========|| (22000 )SharedMemory1 <--- exist ok ||=======******** UNISET-EXAMPLE/Objects ********=========|| (20002 )Controller1 <--- exist ok Source: https://habr.com/ru/post/278565/
All Articles