فهرست منبع

- 优化各个组件自检

Your Name 2 سال پیش
والد
کامیت
392e651f7e
4فایلهای تغییر یافته به همراه35 افزوده شده و 11 حذف شده
  1. BIN
      lib/libgsd_plugins.so
  2. 1 3
      plugins/ExpelPlugin/include/ExpelPlugin.hpp
  3. 28 5
      plugins/ExpelPlugin/src/ExpelPlugin.cpp
  4. 6 3
      plugins/HttpPlugin/src/HttpPlugin.cpp

BIN
lib/libgsd_plugins.so


+ 1 - 3
plugins/ExpelPlugin/include/ExpelPlugin.hpp

@@ -100,9 +100,7 @@ namespace gsd
          * @description: RestPlugin
          * @description: RestPlugin
          * @return {*}
          * @return {*}
          */        
          */        
-        virtual bool RestPlugin(){
-            return true;
-        }
+        virtual bool RestPlugin();
         
         
     protected:  
     protected:  
         Socket::Ptr sockerUdp = nullptr;
         Socket::Ptr sockerUdp = nullptr;

+ 28 - 5
plugins/ExpelPlugin/src/ExpelPlugin.cpp

@@ -18,10 +18,6 @@ namespace gsd
      * @return {*}
      * @return {*}
      */    
      */    
     bool ExpelPlugin::StartTask(){
     bool ExpelPlugin::StartTask(){
-        // timer
-        // if(this->timer0 == nullptr) this->timer0 = std::make_shared<Timer>(10.0f, [&](){
-        //     return true;
-        // }, nullptr);
         return true;
         return true;
     }   
     }   
     
     
@@ -30,7 +26,8 @@ namespace gsd
      * @return {*}
      * @return {*}
      */    
      */    
     bool ExpelPlugin::Alive(){
     bool ExpelPlugin::Alive(){
-        return true;
+        if(this->sockerUdp == nullptr) this->PluginAlive = false;
+        return this->PluginAlive;
     }
     }
 
 
     /**
     /**
@@ -47,6 +44,7 @@ namespace gsd
     bool ExpelPlugin::Init(){
     bool ExpelPlugin::Init(){
         if(this->sockerUdp == nullptr) this->sockerUdp = Socket::createSocket();
         if(this->sockerUdp == nullptr) this->sockerUdp = Socket::createSocket();
         if(this->sockerUdp == nullptr) {
         if(this->sockerUdp == nullptr) {
+            this->PluginAlive = false;
             ErrorL << "Sockerudp cannot be created" << endl;
             ErrorL << "Sockerudp cannot be created" << endl;
             return false;
             return false;
         }
         }
@@ -55,6 +53,7 @@ namespace gsd
         this->sockerUdp->setOnRead([&](const Buffer::Ptr &buf, struct sockaddr *addr , int){
         this->sockerUdp->setOnRead([&](const Buffer::Ptr &buf, struct sockaddr *addr , int){
             this->UdpRecData(buf);
             this->UdpRecData(buf);
         });
         });
+        this->PluginAlive = true;
         return true;
         return true;
     }
     }
 
 
@@ -129,4 +128,28 @@ namespace gsd
     int32_t ExpelPlugin::getExpelSize(){
     int32_t ExpelPlugin::getExpelSize(){
         return Expel::getPtr()->getExpelSize();
         return Expel::getPtr()->getExpelSize();
     }
     }
+
+    /**
+     * @description: RestPlugin
+     * @return {*}
+     */    
+    bool ExpelPlugin::RestPlugin(){
+        auto task = [&](){
+            if(this->sockerUdp != nullptr){
+                this->sockerUdp->bindUdpSock(7777);
+                this->sockerUdp->setOnRead([&](const Buffer::Ptr &buf, struct sockaddr *addr , int){
+                    this->UdpRecData(buf);
+                });
+                this->PluginAlive = true;
+            }
+        };
+        if(this->sockerUdp == nullptr) this->sockerUdp = Socket::createSocket();
+        if(this->sockerUdp == nullptr) {
+            this->PluginAlive = false;
+            ErrorL << "Sockerudp cannot be created" << endl;
+            return false;
+        }
+        task();
+        return true;
+    }
 } // namespace gsd
 } // namespace gsd

+ 6 - 3
plugins/HttpPlugin/src/HttpPlugin.cpp

@@ -177,9 +177,9 @@ namespace gsd
      * @return {*}
      * @return {*}
      */    
      */    
     bool HttpPlugin::Alive(){
     bool HttpPlugin::Alive(){
-        bool result = true;
-        if(this->m_HttpServer == nullptr) result = false;
-        return result;
+        if(this->m_HttpServer == nullptr) this->PluginAlive = false;
+        else this->PluginAlive = true;
+        return this->PluginAlive;
     }
     }
 
 
     /**
     /**
@@ -187,6 +187,9 @@ namespace gsd
      * @return {*}
      * @return {*}
      */    
      */    
     bool HttpPlugin::RestPlugin(){
     bool HttpPlugin::RestPlugin(){
+        if(this->m_HttpServer == nullptr) this->m_HttpServer = HttpServer::CreateNew();
+        if(this->m_HttpServer != nullptr) this->m_HttpServer->Init();
+        this->PluginAlive = true;
         return true;
         return true;
     }
     }