Delete try catch from ReconClient.

This commit is contained in:
sunwen
2023-08-22 10:47:19 +08:00
parent 24399db391
commit e47b1c9602
6 changed files with 70 additions and 14 deletions

View File

@@ -17,4 +17,12 @@ struct TaskQueryResult
bool Start ;
};
struct PACSSetting
{
std::string AETitle;
std::string ServerAETitle;
std::string ServerIP;
int Port = 0;;
};
#endif // __SCAN_H__

View File

@@ -10,6 +10,7 @@ namespace {
const char* QUERY_VERSION_URL = "/Version/";
const char* QUERY_RECON_URL = "/Task/Query/";
const char* QUERY_TRANSFER_URL = "/Transfer/Query/";
const char* SET_PACS_URL = "/Transfer/Setting/";
}
namespace Recon {
@@ -46,11 +47,13 @@ namespace Recon {
content.append(str);
free(str);
auto resp = mRequest.post(mHost+CREATE_URL,content,mHeaders);
if (resp.httpCode() == 201){
if (resp->httpCode() == 201){
delete resp;
return RequestResult::Success();
}
else{
mErrorMessage = resp.getContent();
mErrorMessage = resp->getContent();
delete resp;
return RequestResult::Fail(mErrorMessage);
}
}
@@ -65,8 +68,9 @@ namespace Recon {
content.append(str);
free(str);
auto resp = mRequest.post(mHost+QUERY_SCAN_URL,content,mHeaders);
if (resp.httpCode() == 200){
cJSON * scans = cJSON_Parse(resp.getContent().data());
if (resp->httpCode() == 200){
cJSON * scans = cJSON_Parse(resp->getContent().data());
delete resp;
int size = cJSON_GetArraySize(scans);
if (size == 1){
cJSON * scaninf = cJSON_GetArrayItem(scans, 0);
@@ -81,7 +85,8 @@ namespace Recon {
return RequestResult::Fail(mErrorMessage);
}
else{
mErrorMessage = resp.getContent();
mErrorMessage = resp->getContent();
delete resp;
return RequestResult::Fail(mErrorMessage);
}
}
@@ -96,16 +101,18 @@ namespace Recon {
content.append(str);
free(str);
auto resp = mRequest.post(mHost+QUERY_RECON_URL,content,mHeaders);
if (resp.httpCode() == 204){
if (resp->httpCode() == 204){
delete resp;
return RequestResult::Success();
}
else if (resp.httpCode() == 200){
aReconID = resp.getContent();
else if (resp->httpCode() == 200){
aReconID = resp->getContent();
delete resp;
return RequestResult::Success(aReconID);
}
else{
mErrorMessage = resp.getContent();
mErrorMessage = resp->getContent();
delete resp;
return RequestResult::Fail(mErrorMessage);
}
@@ -121,8 +128,9 @@ namespace Recon {
content.append(str);
free(str);
auto resp = mRequest.post(mHost+QUERY_RECON_URL,content,mHeaders);
if (resp.httpCode() == 200){
cJSON * task = cJSON_Parse(resp.getContent().data());
if (resp->httpCode() == 200){
cJSON * task = cJSON_Parse(resp->getContent().data());
delete resp;
aTask.ReconID = cJSON_GetObjectItem(task, "ReconID")->valuestring;
aTask.ScanID= cJSON_GetObjectItem(task, "ScanID")->valuestring;
aTask.Start = cJSON_GetObjectItem(task, "Start")->valueint!=0;
@@ -131,7 +139,40 @@ namespace Recon {
return RequestResult::Success();
}
else{
mErrorMessage = resp.getContent();
mErrorMessage = resp->getContent();
delete resp;
return RequestResult::Fail(mErrorMessage);
}
}
RequestResult ReconClient::SetPACSSetting(const PACSSetting& aSetting)
{
cJSON * obj = cJSON_CreateObject();
if (!aSetting.AETitle.empty()){
cJSON_AddStringToObject(obj, "AETitle", aSetting.AETitle.c_str());
}
if (!aSetting.ServerIP.empty()){
cJSON_AddStringToObject(obj, "IP", aSetting.ServerIP.c_str());
}
if (!aSetting.ServerAETitle.empty()){
cJSON_AddStringToObject(obj, "ServerAETitle", aSetting.ServerAETitle.c_str());
}
if (aSetting.Port>0){
cJSON_AddNumberToObject(obj, "Port", aSetting.Port);
}
char* str = cJSON_Print(obj);
cJSON_Delete(obj);
std::string content;
content.append(str);
free(str);
auto resp = mRequest.post(mHost+SET_PACS_URL,content,mHeaders);
if (resp->httpCode() == 200){
delete resp;
return RequestResult::Success();
}
else{
mErrorMessage = resp->getContent();
delete resp;
return RequestResult::Fail(mErrorMessage);
}
}

View File

@@ -16,6 +16,7 @@ namespace Recon {
RequestResult QueryReconID(const std::string& aScanID, std::string& aReconID);
RequestResult QueryReconTask(const std::string& aReconID, TaskQueryResult& aTask);
RequestResult QueryVersion();
RequestResult SetPACSSetting(const PACSSetting& aSetting);
private:
std::string mVersionContent;