From 375ad87980ff3dc1280d21a7ce33babc5ddcbeb8 Mon Sep 17 00:00:00 2001 From: Franklin_Zhang Date: Tue, 9 Jan 2018 00:55:59 +0800 Subject: [PATCH 1/2] update some functions add model service class files Signed-off-by: Franklin_Zhang --- include/INxServer.h | 6 ------ include/INxService.h | 6 ++++++ include/INxServiceAccess.h | 9 ++++---- src/NxModelService.cpp | 0 src/NxModelService.h | 0 src/NxServer.cpp | 43 ++----------------------------------- src/NxServer.h | 13 ++--------- src/NxService.cpp | 44 ++++++++++++++++++++++++++++++++++++++ src/NxService.h | 11 ++++++++++ src/NxServiceAccess.cpp | 38 ++++++++++++++++++++++++++++---- src/NxServiceAccess.h | 14 ++++++++---- test/test.cpp | 3 +++ 12 files changed, 117 insertions(+), 70 deletions(-) create mode 100644 src/NxModelService.cpp create mode 100644 src/NxModelService.h diff --git a/include/INxServer.h b/include/INxServer.h index 69d10ff..d031a5f 100644 --- a/include/INxServer.h +++ b/include/INxServer.h @@ -15,12 +15,6 @@ namespace NJGIS //! set IP and Port virtual int setIPAndPort(const char* ip, const int port = 8060) = 0; - //! connect - virtual int connect() = 0; - - //! connect with params - virtual int connect(const char* ip, const int port = 8060) = 0; - //! get service access virtual INjServiceAccess* getServiceAccess() = 0; }; diff --git a/include/INxService.h b/include/INxService.h index fb9c7cd..36c07ba 100644 --- a/include/INxService.h +++ b/include/INxService.h @@ -11,11 +11,17 @@ namespace NJGIS class INjService : public virtual INxUnknown { public: + //! get ip or host of the target server virtual const char* getIP() = 0; + //! get port virtual int getPort() = 0; + //! get port string virtual int getPortStr( std::string &port ) = 0; + + //! connect the server to check if it available + virtual int connect() = 0; }; } } diff --git a/include/INxServiceAccess.h b/include/INxServiceAccess.h index 38d1a44..b59c894 100644 --- a/include/INxServiceAccess.h +++ b/include/INxServiceAccess.h @@ -12,15 +12,16 @@ namespace NJGIS { public: //! get model service list - virtual int getServicesList(std::vector &list) = 0; + virtual int getModelServicesList(std::vector &list) = 0; //! get model service by OID - virtual NJGIS::SERVICE::INjModelService* getServiceByOID(const char* oid) = 0; + virtual NJGIS::SERVICE::INjModelService* getModelServiceByOID(const char* oid) = 0; //! get model servcie by name - virtual int getServicesByName(const char* name, std::vector &list) = 0; + virtual int getModelServicesByName(const char* name, std::vector &list) = 0; }; - } + + } } #endif \ No newline at end of file diff --git a/src/NxModelService.cpp b/src/NxModelService.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/NxModelService.h b/src/NxModelService.h new file mode 100644 index 0000000..e69de29 diff --git a/src/NxServer.cpp b/src/NxServer.cpp index ada8764..51735f0 100644 --- a/src/NxServer.cpp +++ b/src/NxServer.cpp @@ -1,24 +1,8 @@ #include "NxServer.h" #include "../utils/NxHttp.h" +#include "NxServiceAccess.h" #include -const char* NJGIS::SERVICE::NjServer::getIP() -{ - return this->_ip.c_str(); -} - -int NJGIS::SERVICE::NjServer::getPort( ) -{ - return this->_port; -} - -int NJGIS::SERVICE::NjServer::getPortStr(std::string &port) -{ - std::stringstream ss; - ss << this->_port; - ss >> port; - return 1; -} int NJGIS::SERVICE::NjServer::setIPAndPort( const char* ip, const int port ) { @@ -28,30 +12,7 @@ int NJGIS::SERVICE::NjServer::setIPAndPort( const char* ip, const int port ) return 1; } -int NJGIS::SERVICE::NjServer::connect() -{ - std::string strport; - this->getPortStr(strport); - - std::string url = "http://" + this->_ip + ":" + strport + "/ping"; - std::string body = ""; - NjHttpHelper::request_get_sync(url.c_str(), body); - if (body == "OK") - { - return 1; - } - return 0; -} - -int NJGIS::SERVICE::NjServer::connect( const char* ip, const int port ) -{ - this->_ip = ip; - if(port > 65535 || port < 0) { return -1; } - this->_port = port; - return this->connect(); -} - NJGIS::SERVICE::INjServiceAccess* NJGIS::SERVICE::NjServer::getServiceAccess() { - return NULL; + return new NJGIS::SERVICE::NjServiceAccess(this->_ip.c_str(), this->_port); } diff --git a/src/NxServer.h b/src/NxServer.h index 051ae8e..56199d8 100644 --- a/src/NxServer.h +++ b/src/NxServer.h @@ -2,30 +2,21 @@ #define __NJGIS_NJSERVER_H__ #include "../include/INxServer.h" +#include "NxService.h" namespace NJGIS { namespace SERVICE { - class NjServer : public virtual INjServer + class NjServer : public virtual INjServer, public NjService { public: NjServer(){}; NjServer(const char* ip, const int port):_ip(ip),_port(port){}; - virtual const char* getIP(); - - virtual int getPort(); - - virtual int getPortStr(std::string &port); - virtual int setIPAndPort( const char* ip, const int port = 8060 ); - virtual int connect(); - - virtual int connect( const char* ip, const int port = 8060 ); - virtual INjServiceAccess* getServiceAccess(); private: diff --git a/src/NxService.cpp b/src/NxService.cpp index 8dcc2da..59b15c1 100644 --- a/src/NxService.cpp +++ b/src/NxService.cpp @@ -1 +1,45 @@ #include "NxService.h" +#include "../utils/NxHttp.h" +#include + +const char* NJGIS::SERVICE::NjService::getIP() +{ + return this->_ip.c_str(); +} + +int NJGIS::SERVICE::NjService::getPort() +{ + return this->_port; +} + +int NJGIS::SERVICE::NjService::getPortStr( std::string &port ) +{ + std::stringstream ss; + ss << this->_port; + ss >> port; + return 1; +} + + + +int NJGIS::SERVICE::NjService::getBaseUrl( std::string &url ) +{ + std::string strport; + this->getPortStr(strport); + url = "http://" + this->_ip + ":" + strport + "/"; + return 1; +} + +int NJGIS::SERVICE::NjService::connect() +{ + std::string url = ""; + this->getBaseUrl(url); + url = url + "ping"; + std::string body = ""; + NjHttpHelper::request_get_sync(url.c_str(), body); + if (body == "OK") + { + return 1; + } + return 0; +} \ No newline at end of file diff --git a/src/NxService.h b/src/NxService.h index c0c1208..d5ba70b 100644 --- a/src/NxService.h +++ b/src/NxService.h @@ -14,6 +14,17 @@ namespace NJGIS NjService(const char* ip, const int port):_ip(ip),_port(port){}; + virtual const char* getIP(); + + virtual int getPort(); + + virtual int getPortStr( std::string &port ); + + virtual int connect(); + + protected: + + virtual int getBaseUrl( std::string &url ); private: std::string _ip; diff --git a/src/NxServiceAccess.cpp b/src/NxServiceAccess.cpp index 0f91414..2728e15 100644 --- a/src/NxServiceAccess.cpp +++ b/src/NxServiceAccess.cpp @@ -1,16 +1,46 @@ #include "NxServiceAccess.h" +#include "NxModelService.h" +#include "../utils/NxHttp.h" -int NJGIS::SERVICE::NjServiceAccess::getServicesList( std::vector &list ) +int NJGIS::SERVICE::NjServiceAccess::getModelServicesList( std::vector &list ) { - throw std::exception("The method or operation is not implemented."); + std::string url; + this->getBaseUrl(url); + url = url + "modelser/json/all"; + Json::Value jResonese; + NJGIS::SERVICE::NjHttpHelper::request_get_json_sync(url.c_str(), jResonese); + + if(jResonese["result"].asString() == "suc") + { + Json::Value jMss = jResonese["data"]; + int count = jMss.size(); + for(int index = 0; index < count; index++) + { + list.push_back(this->createModelServiceByJSON(jMss[index])); + } + } + else + { + return -1; + } + + return 1; } -NJGIS::SERVICE::INjModelService* NJGIS::SERVICE::NjServiceAccess::getServiceByOID( const char* oid ) +NJGIS::SERVICE::INjModelService* NJGIS::SERVICE::NjServiceAccess::getModelServiceByOID( const char* oid ) { throw std::exception("The method or operation is not implemented."); } -int NJGIS::SERVICE::NjServiceAccess::getServicesByName( const char* name, std::vector &list ) +int NJGIS::SERVICE::NjServiceAccess::getModelServicesByName( const char* name, std::vector &list ) { throw std::exception("The method or operation is not implemented."); } + +NJGIS::SERVICE::INjModelService* NJGIS::SERVICE::NjServiceAccess::createModelServiceByJSON( Json::Value ms ) +{ + INjModelService* pMs = NULL; + + + return pMs; +} diff --git a/src/NxServiceAccess.h b/src/NxServiceAccess.h index f7dcfb2..fe0ca88 100644 --- a/src/NxServiceAccess.h +++ b/src/NxServiceAccess.h @@ -2,20 +2,26 @@ #define __NJGIS_NJSERVICEACCESS_H__ #include "../include/INxServiceAccess.h" +#include "json/json.h" +#include "NxService.h" namespace NJGIS { namespace SERVICE { - class NjServiceAccess : public virtual INjServiceAccess + class NjServiceAccess : public virtual INjServiceAccess, public NjService { public: - virtual int getServicesList( std::vector &list ); + NjServiceAccess(const char* ip, int port):NjService(ip, port){}; - virtual NJGIS::SERVICE::INjModelService* getServiceByOID( const char* oid ); + virtual int getModelServicesList( std::vector &list ); - virtual int getServicesByName( const char* name, std::vector &list ); + virtual NJGIS::SERVICE::INjModelService* getModelServiceByOID( const char* oid ); + virtual int getModelServicesByName( const char* name, std::vector &list ); + + private: + virtual INjModelService* createModelServiceByJSON(Json::Value ms); }; } } diff --git a/test/test.cpp b/test/test.cpp index f1a1fea..db7c6ed 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -10,6 +10,9 @@ int main() if(pServer->connect() == 1) { printf("Hello My SDK"); + NJGIS::SERVICE::INjServiceAccess* pServiceAccess = pServer->getServiceAccess(); + std::vector list_ms; + pServiceAccess->getModelServicesList(list_ms); } } -- Gitee From 80af2a312124ddfc894a87549f0068f0c2b0a063 Mon Sep 17 00:00:00 2001 From: Franklin_Zhang Date: Tue, 9 Jan 2018 08:30:23 +0800 Subject: [PATCH 2/2] update model service interface Signed-off-by: Franklin_Zhang --- include/INxModelService.h | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/include/INxModelService.h b/include/INxModelService.h index 85d80f9..726b490 100644 --- a/include/INxModelService.h +++ b/include/INxModelService.h @@ -6,8 +6,8 @@ namespace NJGIS { - namespace SERVICE - { + namespace SERVICE + { //! type of platform typedef enum { @@ -42,20 +42,20 @@ namespace NJGIS class INjModelService: public virtual INjService { public: - //! get ID - virtual int getServiceID(std::string& id) = 0; + //! get OID + virtual const char* getServiceOID() = 0; //! get name - virtual int getServiceName(std::string& name) = 0; + virtual const char* getServiceName() = 0; //! get type - virtual int getServiceType(std::string& type) = 0; + virtual const char* getServiceType(std::string& type) = 0; //! get etail URL - virtual int getServiceDetailURL(std::string& url) = 0; + virtual const char* getServiceDetailURL(std::string& url) = 0; //! get pid - virtual int getServicePid(std::string& pid) = 0; + virtual const char* getServicePid(std::string& pid) = 0; //! get mid virtual int getServiceMid(std::string& mid) = 0; @@ -64,31 +64,31 @@ namespace NJGIS virtual bool getServiceRegister() = 0; //! get description - virtual int getServiceDescription(std::string& description) = 0; + virtual const char* getServiceDescription(std::string& description) = 0; //! get version - virtual int getServiceVersion(std::string& version) = 0; + virtual const char* getServiceVersion(std::string& version) = 0; //! get platform - virtual int getServicePlatform(NJGIS::SERVICE::NjPlatform& platform) = 0; + virtual const NJGIS::SERVICE::NjPlatform getServicePlatform() = 0; //! get deployment time - virtual int getDeploymentTime(NJGIS::SERVICE::NjPlatform& datetime) = 0; + virtual const NJGIS::SERVICE::NjPlatform int getDeploymentTime() = 0; - //! get image - virtual int getImage(std::string& img) = 0; + //! get image url + virtual const char getImage() = 0; //! get deployor information virtual int getServiceDeployorInfo() = 0; - //! get status - virtual int getServiceStatus(NJGIS::SERVICE::NjServiceStatus& status) = 0; + //! get status (Dynamic) + virtual NJGIS::SERVICE::NjServiceStatus getServiceStatus() = 0; - //! get limitaion - virtual int getServiceLimitation(NJGIS::SERVICE::NjServiceLimitation& limitaion) = 0; + //! get limitaion (Dynamic) + virtual NJGIS::SERVICE::NjServiceLimitation getServiceLimitation() = 0; - //! get permission - virtual int getServicePermission(NJGIS::SERVICE::NjServicePermission& permission) = 0; + //! get permission + virtual const NJGIS::SERVICE::NjServicePermission getServicePermission() = 0; //! invoke service virtual int invoke(const INjDataConfiguration* config, std::string& recordid) = 0; -- Gitee