diff --git a/include/INxRunningLog.h b/include/INxRunningLog.h index 4f6746b94471cee469935f212f291706c0b9276a..3e6c9db68a5303870f1b4bb13c4aabf942fb763d 100644 --- a/include/INxRunningLog.h +++ b/include/INxRunningLog.h @@ -2,6 +2,7 @@ #define __NJGIS_INJRUNNINGLOG_H__ #include "INxUnknown.h" +#include namespace NJGIS { @@ -21,7 +22,7 @@ namespace NJGIS virtual const char* getEvent() = 0; //! get flag - virtual const char* getFlag() = 0; + virtual int getFlag() = 0; //! get message virtual const char* getMessage() = 0; diff --git a/src/NxModelServiceRecord.cpp b/src/NxModelServiceRecord.cpp index 04874ecdaf703be70cf25d85fbadaa5d6511f1ad..68498b1ff74c085d0b4a8642a194cd8c19b667af 100644 --- a/src/NxModelServiceRecord.cpp +++ b/src/NxModelServiceRecord.cpp @@ -56,7 +56,7 @@ const char* NJGIS::SERVICE::NjModelServiceRecord::getRunningInfo_Invokeerr() std::vector* NJGIS::SERVICE::NjModelServiceRecord::getLogs() { - return NULL; + return this->_list_log; } int NJGIS::SERVICE::NjModelServiceRecord::refresh() @@ -95,6 +95,12 @@ int NJGIS::SERVICE::NjModelServiceRecord::refresh() this->_stdout = jMsr["msr_runninginfo"]["StdOut"].asString().c_str(); this->_stderr = jMsr["msr_runninginfo"]["StdErr"].asString().c_str(); + + //update log information + Json::Value jLogs = jMsr["msr_logs"]; + for(int i =0 ; i < jLogs.size(); i++){ + this->_list_log->push_back(NJRunningLogFactory::createRunningLogByJSON(jLogs[i],this->getIP(),this->getPort())); + } } else{ return -1; } diff --git a/src/NxModelServiceRecord.h b/src/NxModelServiceRecord.h index 478ce383d574aeb728ccef55383309dd30732061..670d36c2318827d77020926f08704621dd07f5b9 100644 --- a/src/NxModelServiceRecord.h +++ b/src/NxModelServiceRecord.h @@ -3,6 +3,8 @@ #include "../include/INxModelServiceRecord.h" #include "NxService.h" +#include "../include/INxRunningLog.h" +#include "NxRunningLogFactory.h" namespace NJGIS { @@ -11,7 +13,9 @@ namespace NJGIS class NjModelServiceRecord : public virtual INjModelServiceRecord, public virtual NjService { public: - NjModelServiceRecord(){}; + NjModelServiceRecord(){ + this->_list_log = new std::vector (); + }; NjModelServiceRecord( const char* oid, @@ -38,7 +42,13 @@ namespace NJGIS _stderr(cstderr), _invkerr(invkerr), NjService(ip, port) - {}; + { + this->_list_log = new std::vector (); + }; + ~NjModelServiceRecord() + { + delete this->_list_log; + } virtual const char* getID(); @@ -85,6 +95,8 @@ namespace NJGIS std::string _invkerr; + std::vector* _list_log; + }; } } diff --git a/src/NxRunningLog.cpp b/src/NxRunningLog.cpp index 82bdde2714c4e7c79596b317311b9ac24eaca23c..fa8da44debb1c0340150ebb737c350c676e13487 100644 --- a/src/NxRunningLog.cpp +++ b/src/NxRunningLog.cpp @@ -2,31 +2,31 @@ const char* NJGIS::SERVICE::NjRunningLog::getType() { - return ""; + return this->_type.c_str(); } const char* NJGIS::SERVICE::NjRunningLog::getState() { - return ""; + return this->_state.c_str(); } const char* NJGIS::SERVICE::NjRunningLog::getEvent() { - return ""; + return this->_event.c_str(); } -const char* NJGIS::SERVICE::NjRunningLog::getFlag() +int NJGIS::SERVICE::NjRunningLog::getFlag() { - return ""; + return this->_flag; } const char* NJGIS::SERVICE::NjRunningLog::getMessage() { - return ""; + return this->_message.c_str(); } const char* NJGIS::SERVICE::NjRunningLog::getDateTime() { - return ""; + return this->_datetime.c_str(); } diff --git a/src/NxRunningLog.h b/src/NxRunningLog.h index 941b4d677957a2e8876a0a8a49ad58431ebec156..b782e048f09fef125dadf8b2f1cc8a57f3fe2ea4 100644 --- a/src/NxRunningLog.h +++ b/src/NxRunningLog.h @@ -1,25 +1,54 @@ #ifndef __NJGIS_NJRUNNINGLOG_H__ #define __NJGIS_NJRUNNINGLOG_H__ #include "../include/INxRunningLog.h" +#include "NxService.h" namespace NJGIS { namespace SERVICE { - class NjRunningLog : public virtual INjRunningLog + class NjRunningLog : public virtual INjRunningLog, public virtual NjService { + public: + NjRunningLog(){}; + + NjRunningLog( + const char* type, + const char* state, + const char* event, + int flag, + const char* message, + const char* datetime, + const char* ip, + int port + ): + _type(type), + _state(state), + _event(event), + _flag(flag), + _message(message), + _datetime(datetime), + NjService(ip,port) + {}; virtual const char* getType(); virtual const char* getState(); virtual const char* getEvent(); - virtual const char* getFlag(); + virtual int getFlag(); virtual const char* getMessage(); virtual const char* getDateTime(); + private: + std::string _type; + std::string _state; + std::string _event; + int _flag; + std::string _message; + std::string _datetime; }; } } diff --git a/src/NxServiceAccess.cpp b/src/NxServiceAccess.cpp index bea2ab1b04e234baf1d0fb5e4708a9933b214b7b..fca9a8af6b480f5c5a240ab9a2789726bac7d71c 100644 --- a/src/NxServiceAccess.cpp +++ b/src/NxServiceAccess.cpp @@ -53,6 +53,8 @@ NJGIS::SERVICE::INjModelService* NJGIS::SERVICE::NjServiceAccess::getModelServic int NJGIS::SERVICE::NjServiceAccess::getModelServicesByName( const char* name, std::vector &list ) { //! TODO DX + + //waite for later return NULL; } diff --git a/test/test.cpp b/test/test.cpp index 51688249d099242ae779c3d764add56773190c94..726af6b477f73bf2691b31d17479c735f2f931e5 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,11 +1,13 @@ #include "NxServiceAPI.h" #include #include -#include +#include +#include int main() { - int njs_init = NJGIS::SERVICE::init(); + const char* version = NJGIS::SERVICE::getVersion(); + std::cout << version <createServer("127.0.0.1"); if(pServer != NULL) @@ -19,32 +21,46 @@ int main() std::vector list_ms; pServiceAccess->getModelServicesList(list_ms); + for(int i = 0; i < list_ms.size(); i++) { if(list_ms[i] == NULL) continue; std::cout << list_ms[i]->getServiceOID() << " - " << list_ms[i]->getServiceName() << " - " << list_ms[i]->getServiceType() << std::endl; } - NJGIS::SERVICE::INjData* pData = pServiceAccess->uploadDataByFile( - "E:\\DemoData\\GeoModeling\\SWAT\\SWATModel664\\testify\\default\\udx_zip_hrudata.zip", "udx_zip_hrudata.zip"); - if(pData != NULL) - { + //上传模型运行数据 + NJGIS::SERVICE::INjData* pData = pServiceAccess->uploadDataByFile("E:\\NativeTest\\TestData\\TouchAir\\input.xml","input.xml"); + if(pData != NULL){ std::cout << pData->getID() << " - " << pData->getSize() << " - " << pData->getGenarationDateTime() << " - " << pData->getTag() << std::endl; - NJGIS::SERVICE::INjDataConfiguration* pDataconfig = pServiceAccess->createDataConfig(); - pDataconfig->insertData("04579ee0-5983-4d75-bdc9-a1a460229aa0", "LoadHydroResponseUnit", pData->getID()); - NJGIS::SERVICE::INjModelService* pMService = pServiceAccess->getModelServiceByOID("5aaabce23f761b048081dd9f"); + NJGIS::SERVICE::INjDataConfiguration * pDataconfig = pServiceAccess->createDataConfig(); + pDataconfig->insertData("aa00cced-60e7-48a5-90d2-f91ac08b624d","InputData",pData->getID()); + NJGIS::SERVICE::INjModelService* pMservice = pServiceAccess->getModelServiceByOID("5aabaa522f89583c98ead293"); std::string recordid; - if( pMService->invoke(pDataconfig, recordid) == 1) - { + //调用模型 + if(pMservice->invoke(pDataconfig,recordid) == 1 ){ + std::cout << "Invoke successfully! Model Service Record ID is : [" << recordid << "]" << std::endl; NJGIS::SERVICE::INjModelServiceRecord* pRecord = pServiceAccess->getModelServiceRecordByID(recordid.c_str()); - while(true) - { - pRecord->refresh(); - Sleep(2000); - std::cout << pRecord->getStatus() << std::endl; + while(true){ + Sleep(2000); + //刷新纪录 + pRecord->refresh(); + std::cout << pRecord->getStatus() << std::endl; + + //测试得到logs信息功能 + std::vector* list_logs; + list_logs = pRecord->getLogs(); + for (int j = 0; j < list_logs->size(); j++) + { + if((*list_logs)[j] == NULL)continue; + + std::cout<< (*list_logs)[j]->getType() << " - " << (*list_logs)[j]->getState() << " - " << (*list_logs)[j]->getEvent() << " - " << (*list_logs)[j]->getMessage() <