From e0c425939d361e6fc66b60381fffc52b182bd4e6 Mon Sep 17 00:00:00 2001 From: Franklin_Zhang Date: Mon, 8 Jan 2018 18:43:48 +0800 Subject: [PATCH 1/4] Architecture update Interface Name Change Signed-off-by: Franklin_Zhang --- include/{INxService.h => INxModelService.h} | 2 +- ...ceInstance.h => INxModelServiceInstance.h} | 2 +- ...erviceRecord.h => INxModelServiceRecord.h} | 2 +- include/INxServiceAccess.h | 4 ++-- src/NxServiceAccess.cpp | 16 +++++++++++++ src/NxServiceAccess.h | 23 +++++++++++++++++++ src/NxServiceBase.cpp | 0 src/NxServiceBase.h | 0 8 files changed, 44 insertions(+), 5 deletions(-) rename include/{INxService.h => INxModelService.h} (97%) rename include/{INxServiceInstance.h => INxModelServiceInstance.h} (84%) rename include/{INxServiceRecord.h => INxModelServiceRecord.h} (94%) create mode 100644 src/NxServiceAccess.cpp create mode 100644 src/NxServiceAccess.h create mode 100644 src/NxServiceBase.cpp create mode 100644 src/NxServiceBase.h diff --git a/include/INxService.h b/include/INxModelService.h similarity index 97% rename from include/INxService.h rename to include/INxModelService.h index 72a1a05..92d47e1 100644 --- a/include/INxService.h +++ b/include/INxModelService.h @@ -38,7 +38,7 @@ namespace NJGIS } NjServicePermission; //! model service - class INjService: public virtual INxUnknown + class INjModelService: public virtual INxUnknown { public: //! get ID diff --git a/include/INxServiceInstance.h b/include/INxModelServiceInstance.h similarity index 84% rename from include/INxServiceInstance.h rename to include/INxModelServiceInstance.h index e9571b2..a6b68d6 100644 --- a/include/INxServiceInstance.h +++ b/include/INxModelServiceInstance.h @@ -10,7 +10,7 @@ namespace NJGIS { namespace SERVICE { - class INjServiceInstance : public virtual INxUnknown + class INjServiceServiceInstance : public virtual INxUnknown { public: virtual int getCurrentState(std::string& state) = 0; diff --git a/include/INxServiceRecord.h b/include/INxModelServiceRecord.h similarity index 94% rename from include/INxServiceRecord.h rename to include/INxModelServiceRecord.h index 9664694..070bc52 100644 --- a/include/INxServiceRecord.h +++ b/include/INxModelServiceRecord.h @@ -20,7 +20,7 @@ namespace NJGIS } NjRecordStatus; - class INjServiceRecord : public virtual INxUnknown + class INjModelServiceRecord : public virtual INxUnknown { public: virtual int getID(std::string& id) = 0; diff --git a/include/INxServiceAccess.h b/include/INxServiceAccess.h index aa8249e..646fd93 100644 --- a/include/INxServiceAccess.h +++ b/include/INxServiceAccess.h @@ -13,10 +13,10 @@ namespace NJGIS { public: //! get model service list - virtual int getServicesList(std::vector &list) = 0; + virtual int getServicesList(std::vector &list) = 0; //! get model service by OID - virtual NJGIS::SERVICE::INjService* getServiceByOID(const char* oid) = 0; + virtual NJGIS::SERVICE::INjModelService* getServiceByOID(const char* oid) = 0; //! get model servcie by name virtual int getServicesByName(const char* name, std::vector &list) = 0; diff --git a/src/NxServiceAccess.cpp b/src/NxServiceAccess.cpp new file mode 100644 index 0000000..cab4ba1 --- /dev/null +++ b/src/NxServiceAccess.cpp @@ -0,0 +1,16 @@ + +int NJGIS::SERVICE::NjServiceAccess::getServicesList( std::vector &list ) +{ + throw std::exception("The method or operation is not implemented."); +} + +NJGIS::SERVICE::INjService* NJGIS::SERVICE::NjServiceAccess::getServiceByOID( const char* oid ) +{ + throw std::exception("The method or operation is not implemented."); +} + +int NJGIS::SERVICE::NjServiceAccess::getServicesByName( const char* name, std::vector &list ) +{ + throw std::exception("The method or operation is not implemented."); +} + diff --git a/src/NxServiceAccess.h b/src/NxServiceAccess.h new file mode 100644 index 0000000..7e21e37 --- /dev/null +++ b/src/NxServiceAccess.h @@ -0,0 +1,23 @@ +#ifndef __NJGIS_NXSERVICEACCESS_H__ +#define __NJGIS_NXSERVICEACCESS_H__ + +#include "../include/INxServiceAccess.h" + +namespace NJGIS +{ + namespace SERVICE + { + class NjServiceAccess : public virtual INjServiceAccess + { + public: + virtual int getServicesList( std::vector &list ); + + virtual NJGIS::SERVICE::INjService* getServiceByOID( const char* oid ); + + virtual int getServicesByName( const char* name, std::vector &list ); + + }; + } +} + +#endif \ No newline at end of file diff --git a/src/NxServiceBase.cpp b/src/NxServiceBase.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/NxServiceBase.h b/src/NxServiceBase.h new file mode 100644 index 0000000..e69de29 -- Gitee From 22776ce7acec4d61547de34f73b78174a8b7a3dd Mon Sep 17 00:00:00 2001 From: Franklin_Zhang Date: Mon, 8 Jan 2018 23:26:03 +0800 Subject: [PATCH 2/4] update service base Signed-off-by: Franklin_Zhang --- include/INxData.h | 8 ++++---- include/INxDataConfiguration.h | 4 ++-- include/INxModelService.h | 7 ++++--- include/INxModelServiceInstance.h | 8 ++++---- include/INxModelServiceRecord.h | 4 ++-- include/INxServer.h | 14 ++++---------- include/INxServerFactory.h | 4 ++-- include/INxService.h | 23 +++++++++++++++++++++++ include/INxServiceAccess.h | 9 ++++----- include/INxUnknown.h | 4 ++-- include/NxServiceAPI.h | 4 ++-- src/NxServer.cpp | 20 ++++++++++++-------- src/NxServer.h | 9 ++++++--- src/NxServerFactory.h | 4 ++-- src/NxService.cpp | 1 + src/NxService.h | 27 +++++++++++++++++++++++++++ src/NxServiceAccess.cpp | 6 +++--- src/NxServiceAccess.h | 8 ++++---- src/NxServiceBase.cpp | 0 src/NxServiceBase.h | 0 utils/NxHttp.h | 4 ++-- 21 files changed, 110 insertions(+), 58 deletions(-) create mode 100644 include/INxService.h create mode 100644 src/NxService.cpp create mode 100644 src/NxService.h delete mode 100644 src/NxServiceBase.cpp delete mode 100644 src/NxServiceBase.h diff --git a/include/INxData.h b/include/INxData.h index 25ad728..47b5005 100644 --- a/include/INxData.h +++ b/include/INxData.h @@ -1,8 +1,8 @@ -#ifndef __NJGIS_INXDATA_H__ -#define __NJGIS_INXDATA_H__ +#ifndef __NJGIS_INJDATA_H__ +#define __NJGIS_INJDATA_H__ #include -#include "INxUnknown.h" +#include "INxService.h" namespace NJGIS { @@ -16,7 +16,7 @@ namespace NJGIS ZIP = 3 } NjDataType; - class INjData : public virtual INxUnknown + class INjData : public virtual INjService { public: virtual int isExist(); diff --git a/include/INxDataConfiguration.h b/include/INxDataConfiguration.h index e4584fc..c4d7137 100644 --- a/include/INxDataConfiguration.h +++ b/include/INxDataConfiguration.h @@ -1,5 +1,5 @@ -#ifndef __NJGIS_IDATACONFIGURATION_H__ -#define __NJGIS_IDATACONFIGURATION_H__ +#ifndef __NJGIS_INJDATACONFIGURATION_H__ +#define __NJGIS_INJDATACONFIGURATION_H__ #include "INxData.h" diff --git a/include/INxModelService.h b/include/INxModelService.h index 92d47e1..85d80f9 100644 --- a/include/INxModelService.h +++ b/include/INxModelService.h @@ -1,7 +1,8 @@ -#ifndef __NJGIS_INXSERVICE_H__ -#define __NJGIS_INXSERVICE_H__ +#ifndef __NJGIS_INJMODELSERVICE_H__ +#define __NJGIS_INJMODELSERVICE_H__ #include "INxDataConfiguration.h" +#include "INxService.h" namespace NJGIS { @@ -38,7 +39,7 @@ namespace NJGIS } NjServicePermission; //! model service - class INjModelService: public virtual INxUnknown + class INjModelService: public virtual INjService { public: //! get ID diff --git a/include/INxModelServiceInstance.h b/include/INxModelServiceInstance.h index a6b68d6..4cdce01 100644 --- a/include/INxModelServiceInstance.h +++ b/include/INxModelServiceInstance.h @@ -1,16 +1,16 @@ -#ifndef __NJGIS_ISERVICEINSTANCE_H__ -#define __NJGIS_ISERVICEINSTANCE_H__ +#ifndef __NJGIS_INJMODELSERVICEINSTANCE_H__ +#define __NJGIS_INJMODELSERVICEINSTANCE_H__ #include #include -#include "INxUnknown.h" +#include "INxService.h" namespace NJGIS { namespace SERVICE { - class INjServiceServiceInstance : public virtual INxUnknown + class INjServiceServiceInstance : public virtual INjService { public: virtual int getCurrentState(std::string& state) = 0; diff --git a/include/INxModelServiceRecord.h b/include/INxModelServiceRecord.h index 070bc52..bfe9ba5 100644 --- a/include/INxModelServiceRecord.h +++ b/include/INxModelServiceRecord.h @@ -1,5 +1,5 @@ -#ifndef __NJGIS_INXSERVICERECORD_H__ -#define __NJGIS_INXSERVICERECORD_H__ +#ifndef __NJGIS_INJSERVICERECORD_H__ +#define __NJGIS_INJSERVICERECORD_H__ #include #include diff --git a/include/INxServer.h b/include/INxServer.h index b4bbe7e..69d10ff 100644 --- a/include/INxServer.h +++ b/include/INxServer.h @@ -1,23 +1,17 @@ -#ifndef __NJGIS_INXSERVER_H__ -#define __NJGIS_INXSERVER_H__ +#ifndef __NJGIS_INXJSERVER_H__ +#define __NJGIS_INXJSERVER_H__ #include -#include "INxUnknown.h" +#include "INxService.h" #include "INxServiceAccess.h" namespace NJGIS { namespace SERVICE { - class INjServer : public virtual INxUnknown + class INjServer : public virtual INjService { public: - //! get IP "xxxx.xxxx.xxxx.xxxx" - virtual int getIP(std::string &ip) = 0; - - //! get Port - virtual int getPort() = 0; - //! set IP and Port virtual int setIPAndPort(const char* ip, const int port = 8060) = 0; diff --git a/include/INxServerFactory.h b/include/INxServerFactory.h index 0f485ce..81f21ad 100644 --- a/include/INxServerFactory.h +++ b/include/INxServerFactory.h @@ -1,5 +1,5 @@ -#ifndef __NJGIS_INXSERVERFACTORY_H__ -#define __NJGIS_INXSERVERFACTORY_H__ +#ifndef __NJGIS_INJSERVERFACTORY_H__ +#define __NJGIS_INJSERVERFACTORY_H__ #include "INxServer.h" diff --git a/include/INxService.h b/include/INxService.h new file mode 100644 index 0000000..fb9c7cd --- /dev/null +++ b/include/INxService.h @@ -0,0 +1,23 @@ +#ifndef _NJGIS_INJSERVICE_H__ +#define _NJGIS_INJSERVICE_H__ + +#include "INxUnknown.h" +#include + +namespace NJGIS +{ + namespace SERVICE + { + class INjService : public virtual INxUnknown + { + public: + virtual const char* getIP() = 0; + + virtual int getPort() = 0; + + virtual int getPortStr( std::string &port ) = 0; + }; + } +} + +#endif \ No newline at end of file diff --git a/include/INxServiceAccess.h b/include/INxServiceAccess.h index 646fd93..38d1a44 100644 --- a/include/INxServiceAccess.h +++ b/include/INxServiceAccess.h @@ -1,15 +1,14 @@ -#ifndef __NJGIS_INXSERVICEACCESS_H__ -#define __NJGIS_INXSERVICEACCESS_H__ +#ifndef __NJGIS_INJSERVICEACCESS_H__ +#define __NJGIS_INJSERVICEACCESS_H__ -#include "INxUnknown.h" -#include "INxService.h" +#include "INxModelService.h" #include namespace NJGIS { namespace SERVICE { - class INjServiceAccess : public virtual INxUnknown + class INjServiceAccess : public virtual INjService { public: //! get model service list diff --git a/include/INxUnknown.h b/include/INxUnknown.h index 813cc4f..8dc2f3b 100644 --- a/include/INxUnknown.h +++ b/include/INxUnknown.h @@ -1,5 +1,5 @@ -#ifndef __NJ_GIS_INXKNOWN_H__ -#define __NJ_GIS_INXKNOWN_H__ +#ifndef __NJGIS_INJKNOWN_H__ +#define __NJGIS_INJKNOWN_H__ namespace NJGIS { diff --git a/include/NxServiceAPI.h b/include/NxServiceAPI.h index b9f9538..23ec80b 100644 --- a/include/NxServiceAPI.h +++ b/include/NxServiceAPI.h @@ -1,5 +1,5 @@ -#ifndef __NJGIS_INXSERVICEAPI_H__ -#define __NJGIS_INXSERVICEAPI_H__ +#ifndef __NJGIS_NJSERVICEAPI_H__ +#define __NJGIS_NJSERVICEAPI_H__ #include "INxServerFactory.h" diff --git a/src/NxServer.cpp b/src/NxServer.cpp index 8f4039f..ada8764 100644 --- a/src/NxServer.cpp +++ b/src/NxServer.cpp @@ -2,10 +2,9 @@ #include "../utils/NxHttp.h" #include -int NJGIS::SERVICE::NjServer::getIP( std::string &ip ) +const char* NJGIS::SERVICE::NjServer::getIP() { - ip = this->_ip; - return 1; + return this->_ip.c_str(); } int NJGIS::SERVICE::NjServer::getPort( ) @@ -13,6 +12,14 @@ 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 ) { this->_ip = ip; @@ -23,10 +30,8 @@ int NJGIS::SERVICE::NjServer::setIPAndPort( const char* ip, const int port ) int NJGIS::SERVICE::NjServer::connect() { - std::stringstream ss; - ss << this->_port; std::string strport; - ss >> strport; + this->getPortStr(strport); std::string url = "http://" + this->_ip + ":" + strport + "/ping"; std::string body = ""; @@ -48,6 +53,5 @@ int NJGIS::SERVICE::NjServer::connect( const char* ip, const int port ) NJGIS::SERVICE::INjServiceAccess* NJGIS::SERVICE::NjServer::getServiceAccess() { - throw std::exception("The method or operation is not implemented."); + return NULL; } - diff --git a/src/NxServer.h b/src/NxServer.h index 4dc961e..051ae8e 100644 --- a/src/NxServer.h +++ b/src/NxServer.h @@ -1,5 +1,5 @@ -#ifndef __NJGIS_NXSERVER_H__ -#define __NJGIS_NXSERVER_H__ +#ifndef __NJGIS_NJSERVER_H__ +#define __NJGIS_NJSERVER_H__ #include "../include/INxServer.h" @@ -14,10 +14,12 @@ namespace NJGIS NjServer(const char* ip, const int port):_ip(ip),_port(port){}; - virtual int getIP( std::string &ip ); + 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(); @@ -25,6 +27,7 @@ namespace NJGIS virtual int connect( const char* ip, const int port = 8060 ); virtual INjServiceAccess* getServiceAccess(); + private: std::string _ip; diff --git a/src/NxServerFactory.h b/src/NxServerFactory.h index bd2028c..a22a17a 100644 --- a/src/NxServerFactory.h +++ b/src/NxServerFactory.h @@ -1,5 +1,5 @@ -#ifndef __NJGSI_NXSERVERFACYORY_H__ -#define __NJGSI_NXSERVERFACYORY_H__ +#ifndef __NJGSI_NJSERVERFACYORY_H__ +#define __NJGSI_NJSERVERFACYORY_H__ #include "../include/INxServerFactory.h" diff --git a/src/NxService.cpp b/src/NxService.cpp new file mode 100644 index 0000000..8dcc2da --- /dev/null +++ b/src/NxService.cpp @@ -0,0 +1 @@ +#include "NxService.h" diff --git a/src/NxService.h b/src/NxService.h new file mode 100644 index 0000000..c0c1208 --- /dev/null +++ b/src/NxService.h @@ -0,0 +1,27 @@ +#ifndef _NJGIS_NJSERVICE_H__ +#define _NJGIS_NJSERVICE_H__ + +#include "../include/INxService.h" + +namespace NJGIS +{ + namespace SERVICE + { + class NjService : public virtual INjService + { + public: + NjService():_ip("127.0.0.1"),_port(8060){}; + + NjService(const char* ip, const int port):_ip(ip),_port(port){}; + + + private: + std::string _ip; + + int _port; + + }; + } +} + +#endif \ No newline at end of file diff --git a/src/NxServiceAccess.cpp b/src/NxServiceAccess.cpp index cab4ba1..0f91414 100644 --- a/src/NxServiceAccess.cpp +++ b/src/NxServiceAccess.cpp @@ -1,10 +1,11 @@ +#include "NxServiceAccess.h" -int NJGIS::SERVICE::NjServiceAccess::getServicesList( std::vector &list ) +int NJGIS::SERVICE::NjServiceAccess::getServicesList( std::vector &list ) { throw std::exception("The method or operation is not implemented."); } -NJGIS::SERVICE::INjService* NJGIS::SERVICE::NjServiceAccess::getServiceByOID( const char* oid ) +NJGIS::SERVICE::INjModelService* NJGIS::SERVICE::NjServiceAccess::getServiceByOID( const char* oid ) { throw std::exception("The method or operation is not implemented."); } @@ -13,4 +14,3 @@ int NJGIS::SERVICE::NjServiceAccess::getServicesByName( const char* name, std::v { throw std::exception("The method or operation is not implemented."); } - diff --git a/src/NxServiceAccess.h b/src/NxServiceAccess.h index 7e21e37..f7dcfb2 100644 --- a/src/NxServiceAccess.h +++ b/src/NxServiceAccess.h @@ -1,5 +1,5 @@ -#ifndef __NJGIS_NXSERVICEACCESS_H__ -#define __NJGIS_NXSERVICEACCESS_H__ +#ifndef __NJGIS_NJSERVICEACCESS_H__ +#define __NJGIS_NJSERVICEACCESS_H__ #include "../include/INxServiceAccess.h" @@ -10,9 +10,9 @@ namespace NJGIS class NjServiceAccess : public virtual INjServiceAccess { public: - virtual int getServicesList( std::vector &list ); + virtual int getServicesList( std::vector &list ); - virtual NJGIS::SERVICE::INjService* getServiceByOID( const char* oid ); + virtual NJGIS::SERVICE::INjModelService* getServiceByOID( const char* oid ); virtual int getServicesByName( const char* name, std::vector &list ); diff --git a/src/NxServiceBase.cpp b/src/NxServiceBase.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/NxServiceBase.h b/src/NxServiceBase.h deleted file mode 100644 index e69de29..0000000 diff --git a/utils/NxHttp.h b/utils/NxHttp.h index c414283..294c703 100644 --- a/utils/NxHttp.h +++ b/utils/NxHttp.h @@ -1,5 +1,5 @@ -#ifndef __NJGIS_NXHTTP_H__ -#define __NJGIS_NXHTTP_H__ +#ifndef __NJGIS_NJHTTP_H__ +#define __NJGIS_NJHTTP_H__ #include -- Gitee From 375ad87980ff3dc1280d21a7ce33babc5ddcbeb8 Mon Sep 17 00:00:00 2001 From: Franklin_Zhang Date: Tue, 9 Jan 2018 00:55:59 +0800 Subject: [PATCH 3/4] 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 4/4] 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