瀏覽代碼

Use config file params for hepu login

qiuyang 2 月之前
父節點
當前提交
25fce9e68b

+ 2 - 2
framework/request/include/HepuLogin.h

@@ -35,8 +35,8 @@ class HepuLogin
             writer.Key("param");
             writer.StartObject();
 
-            writer.Key("token");
-            writer.String(token.c_str());
+            //writer.Key("token");
+            //writer.String(token.c_str());
 
             writer.Key("username");
             writer.String(username.c_str());

二進制
lib/libgsd_modules.so


二進制
lib/libgsd_plugins.so


+ 15 - 3
modules/Hepu/include/Hepu.hpp

@@ -34,9 +34,11 @@ namespace gsd{
     {
         private:
 
-            string username;
-            string password;
-            string token;
+            string username_;
+            string password_;
+            string token_;
+            string url_;
+            int port_;
 
         public:
             Hepu(){}
@@ -52,6 +54,8 @@ namespace gsd{
 
             int32_t Init(string username, string url, int port);
 
+            int32_t Init2();
+
             static std::shared_ptr<Hepu> CreateNew();
 
             int32_t LoginHepu();
@@ -64,6 +68,14 @@ namespace gsd{
 
             int32_t sendHepuTarget(HepuTarget& HepuTargetMsg);
 
+            void setUsr(string usr);
+
+            void setPwd(string pwd);
+
+            void setUrl(string url);
+
+            void setPort(int port);
+
     };
 };
 

+ 42 - 8
modules/Hepu/src/Hepu.cpp

@@ -11,7 +11,7 @@ namespace gsd{
     }
 
     int32_t Hepu::Init(std::string username, std::string url, int port){
-        this->username = username;
+        this->username_ = username;
         m_hepu = std::make_shared<httplib::Client>(url, port);
         if(m_hepu == NULL){
             ErrorL << "Hepu http client initialization failed.";
@@ -24,14 +24,27 @@ namespace gsd{
         return OK;
     }
 
+    int32_t Hepu::Init2(){
+        m_hepu = std::make_shared<httplib::Client>(this->url_, this->port_);
+        if(m_hepu == NULL){
+            ErrorL << "Hepu http client initialization failed.";
+            return ERR;
+        }
+        if(this->LoginHepu() != OK){
+            ErrorL << "Failed to login to Hepu IPC.";
+            return ERR;
+        }
+        return OK;
+    }
+
     int32_t Hepu::LoginHepu(){
         if(m_hepu == nullptr) return ERR;
 
         HepuLogin hepuloginMsg;
         std::string msg;
         hepuloginMsg.token = "";
-        hepuloginMsg.username = this->username;
-        hepuloginMsg.password = this->password;
+        hepuloginMsg.username = this->username_;
+        hepuloginMsg.password = this->password_;
         hepuloginMsg.objectToJson(msg);
         msg += "\r\n";
 
@@ -47,7 +60,7 @@ namespace gsd{
                     return ERR;
                 }
                 if(hepuloginReMsg.token.size()){
-                    this->token = hepuloginReMsg.token;
+                    this->token_ = hepuloginReMsg.token;
                     return OK;
                 }
                 return ERR;
@@ -62,14 +75,14 @@ namespace gsd{
     }
 
     bool Hepu::alive(){
-        return this->token == "" ? false : true;
+        return this->token_ == "" ? false : true;
     }
 
     int32_t Hepu::sendHepuHB(HepuHB& hepuHBMsg){
         if(m_hepu == nullptr) return ERR;
 
         std::string msg;
-        hepuHBMsg.token = this->token;
+        hepuHBMsg.token = this->token_;
         hepuHBMsg.objectToJson(msg);
         msg+="\r\n";
         
@@ -100,7 +113,7 @@ namespace gsd{
 
         HepuHB hepuHBMsg;
         std::string msg;
-        hepuHBMsg.token = this->token;
+        hepuHBMsg.token = this->token_;
         hepuHBMsg.objectToJson(msg);
         msg+="\r\n";
         
@@ -130,7 +143,7 @@ namespace gsd{
         if(m_hepu == nullptr) return ERR;
 
         std::string msg;
-        HepuTargetMsg.token = this->token;
+        HepuTargetMsg.token = this->token_;
         HepuTargetMsg.channelid = 1;
         HepuTargetMsg.bTracking = true;
         HepuTargetMsg.trackingTime = 0;
@@ -158,4 +171,25 @@ namespace gsd{
         }
         return ERR;
     }
+
+    void Hepu::setUsr(string username)
+    {
+        this->username_ = username;
+    }
+
+    void Hepu::setPwd(string password)
+    {
+        this->password_ = password;
+    }
+
+    void Hepu::setUrl(string url)
+    {
+        this->url_ = url;
+    }
+
+    void Hepu::setPort(int port)
+    {
+        this->port_ = port;
+    }
+
 }

+ 6 - 6
plugins/HepuPlugin/src/HepuPlugin.cpp

@@ -9,15 +9,15 @@ namespace gsd
     }
 
     bool HepuPlugin::Init(){
-        if(config::getPtr()->Hepu == 0)
-            return false;
-
         if(this->m_hepuClient == nullptr){
             this->m_hepuClient = Hepu::CreateNew();
-        }
-
+        }   
         
-        if(this->m_hepuClient->Init(HEPU_USR,HEPU_IP,HEPU_PORT) == OK){
+        this->m_hepuClient->setPwd(config::getPtr()->HepuPwd);
+        this->m_hepuClient->setUrl(config::getPtr()->HepuURL);
+        this->m_hepuClient->setUsr(config::getPtr()->HepuUsr);
+        this->m_hepuClient->setPort(config::getPtr()->HepuPort);
+        if(this->m_hepuClient->Init(config::getPtr()->HepuUsr , config::getPtr()->HepuIP, config::getPtr()->HepuPort) == OK){
             InfoL << "Hepu IPC http login succeeds."<<endl;
         }else{
             WarnL << "Hepu IPC http login failed."<<endl;

+ 7 - 4
source/UserApp/src/UserApp.cpp

@@ -74,10 +74,13 @@ namespace gsd
         }
 
         // HepuPlugin
-        if(this->m_HepuPlugin == nullptr) m_HepuPlugin = HepuPlugin::getPtr();
-        if(!this->m_HepuPlugin->Init()){
-            ErrorL << "HepuPlugin init failed" << endl;
-            return false;
+        if(config::getPtr()->Hepu == 1)
+        {
+            if(this->m_HepuPlugin == nullptr) m_HepuPlugin = HepuPlugin::getPtr();
+            if(!this->m_HepuPlugin->Init()){
+                ErrorL << "HepuPlugin init failed" << endl;
+                return false;
+            }
         }
 
         // 释放资源